java - Access NameBinding value inside my filter -


i've filter rest service. normal authentication filter.

now need pass boolean in it. link got point:

@namebinding @target({elementtype.type, elementtype.method}) @retention(value = retentionpolicy.runtime) public @interface authenticationfilterbinding {      boolean checkaccountstatus() default true; } 

and in filter implementation i've:

@authenticationfilterbinding @provider @priority(filterpriority.authentication_priority) public class authenticationfilter extends authenticationabstractfilter implements containerrequestfilter {      private static final logger logger = loggerfactory.getlogger(authenticationfilter.class);      @override     public void filter(containerrequestcontext requestcontext) {      // here need check value of checkaccountstatus() defined in code above.      // how can access value?      // filter logic goes here     } } 

on endpoints i've like:

@post @path("/photo") @consumes(mediatype.multipart_form_data) @authenticationfilterbinding(checkaccountstatus = false) @managedasync public void setuserphoto(@suspended asyncresponse ar, @formdataparam("image") inputstream filestream, @headerparam(constant.header_user_id) long userid) {      // ... } 

my problem need check value of checkaccountstatus inside filter , problem here, how can access it?

i've found solution:

in filter use reflection access value. this:

public void filter(containerrequestcontext requestcontext) {          final extendeduriinfo extendenduriinfo = (extendeduriinfo) requestcontext.geturiinfo();          boolean checkaccountstatus = extendenduriinfo                                                     .getmatchedresourcemethod()                                                     .getinvocable()                                                     .gethandlingmethod()                                                     .getannotation(authenticationfilterbinding.class).checkaccountstatus(); } 

hope may someone.

note, using reflection , reflection slow. wouldn't use on big filter (like authentication, filter you'll use pretty everywhere)... slow down app/website.

i ended creating new filter specific case. it's trade off.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -