如何为mobilefirst 8.0 java适配器编写全局过滤器 [英] How to write global filter for mobilefirst 8.0 java adapter
问题描述
我需要在mobilefirst 8.0 java适配器上使用全局过滤器。要写ContainerRequestFilter过滤器。但我需要一些mobilefirst数据。 ConfigurationApi,AdaptersAPI。我怎样才能在这种情况下得到它?或者还有其他方法可以使用所有java适配器方法调用某些代码?
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 ?
推荐答案
您可以编写一个ContainerRequestFilter并将其与适配器。您需要做的就是添加到适配器应用程序类中的getClasses()方法(除非它与应用程序类在同一个包中,在这种情况下它将自动发生)。
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).
您可以在过滤器中使用@Context注释来注入您需要的任何MFP API,就像在您的资源类中一样。
You can use the @Context annotation in filters to inject any MFP API you need, just like in your resource classes.
这是一个工作示例:
public class MyRequestFilter implements ContainerRequestFilter {
@Context
ConfigurationAPI configApi;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
doStuff();
}
}
这篇关于如何为mobilefirst 8.0 java适配器编写全局过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!