JAX-RS - DynamicFeature Examples

Code Snippets JAX-RS JAVA EE 

import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.container.ResourceInfo;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.Provider;
import java.lang.reflect.Method;

@Provider
public class FilterRegistrationFeature implements DynamicFeature {
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
if (MyResource.class.isAssignableFrom(resourceInfo.getResourceClass())) {
Method method = resourceInfo.getResourceMethod();
if (method.getName().toLowerCase().contains("order")) {
System.out.println("registering LogFilter");
context.register(new LogFilter());
}
}
}
}
Original Post




See Also