0
votes

I need a global filter on mobilefirst 8.0 java adapter. Am tring to write ContainerRequestFilter filter. But i need some mobilefirst data in there. ConfigurationApi,AdaptersAPI. How can i get it in this context ? Or there have other way to call some code with all java adapter methods ?

2
Can you better define what's a "global filter"? How is this Java adapter any different than any other Java adapter example that already exists for v8.0?Idan Adar
now im writing annotation inherited from ContainerRequestFilter. but it will use on all java adapters and all methods across mobilefirst 8.0 server. may be its some global annotation. but i face dry context and have only ContainerRequestContext container.Igor Demyanenko

2 Answers

2
votes

You can write a ContainerRequestFilter and use it with an adapter. All you need to do is add to the getClasses() method in the adapter application class (unless it's in the same package as the application class, in this case it will happen automatically).

You can use the @Context annotation in filters to inject any MFP API you need, just like in your resource classes.

Here is a working example:

public class MyRequestFilter implements ContainerRequestFilter {

    @Context
    ConfigurationAPI configApi;

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        doStuff();
    }
}
0
votes

Thanks all! Question was solved. Helped this page https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/index.html about @NameBinding annotation. and additional @Produce annotation on Filter class.