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 ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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();
}
}
回答2:
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.