@Interceptor @Priority(Interceptor.Priority.PLATFORM_AFTER + 800) public class CdiInterceptorWrapper { @Inject private CdiInterceptorWrapperExtension extension;
private static <T> int priority(Class<? extends T> pluginClass) { Priority priority = pluginClass.getAnnotation(Priority.class); return priority == null ? 0 : priority.value(); }
@PreMatching @Priority(Integer.MIN_VALUE) @ApplicationScoped public class MpTracingContextFilter implements ContainerRequestFilter, ContainerResponseFilter { @Context private Provider<ServerRequest> request; @Inject private Config config;
@Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199) @Interceptor @Transactional @JerseyVetoed public final class WebAppExceptionInterceptor implements Serializable { @Inject @TransactionalExceptionInterceptorProvider.WaeQualifier private WebAppExceptionHolder store;
@ApplicationScoped @Alternative @Priority(value=Interceptor.Priority.LIBRARY_BEFORE) public class JspDefaultProducer { @Inject private BeanManagerImpl beanManagerImpl; @Produces @ApplicationScoped public JspResolver create(){ return new JspResolver("src/main/webapp",beanManagerImpl); } }
@ApplicationScoped @Alternative @Priority(Interceptor.Priority.LIBRARY_BEFORE) public class ServletContextFactory{ private ServletContext context; public void observesContext(@Observes @Initialized(ApplicationScoped.class) ServletContext context){ this.context = context; } @Produces @ApplicationScoped public ServletContext getInstance(){ return this.context; } }
/** * This class ensures that any HTTP response that includes a Content-Type * response header, will also include the UTF-8 character set. */ @Provider @Priority(Priorities.HEADER_DECORATOR) public class CharsetUtf8Filter implements ContainerResponseFilter { private static final String UTF_8 = StandardCharsets.UTF_8.displayName(Locale.ENGLISH); @Override public void filter(final ContainerRequestContext request, final ContainerResponseContext response) throws IOException { final MediaType type = response.getMediaType(); if (type != null && !type.getParameters().containsKey(MediaType.CHARSET_PARAMETER)) { final MediaType typeWithCharset = type.withCharset(UTF_8); response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, typeWithCharset); } } }
@Interceptor @Transactional(Transactional.TxType.REQUIRES_NEW) @Priority(Interceptor.Priority.PLATFORM_BEFORE + 200) public class RequiredNewInterceptor extends InterceptorBase { @AroundInvoke public Object intercept(final InvocationContext ic) throws Exception { return super.intercept(ic); } @Override protected TransactionPolicy getPolicy() throws SystemException, ApplicationException { return new TxRequiresNew(getTransactionManager()); } }
@PreMatching @Provider @Priority(1) public class HeaderAdder implements ContainerRequestFilter { public static final Logger LOGGER = LoggerFactory.getLogger(HeaderAdder.class);
/** Uses CDI API binding - @javax.enterprise.context.control.ActivateRequestContext. * * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a> */ @Vetoed @Interceptor @ActivateRequestContext @SuppressWarnings("checkstyle:magicnumber") @Priority(Interceptor.Priority.PLATFORM_BEFORE + 100) public class CdiRequestContextActivatorInterceptor extends AbstractActivateRequestContextInterceptor { @Inject public CdiRequestContextActivatorInterceptor(@Unbound RequestContext requestContext, BeanManagerImpl beanManager) { super(requestContext, beanManager); } }
/** * @author Radim Hanus */ @Priority(2000) @Alternative public class PriorityGreeting implements Greeting { @Override public String greet(String name) { return "Hey " + name + " I should be selected since I've got the highest priority !"; } }
/** * Class used to enable (activate) the dynamic interceptor and sets its priority * * @author Arjan Tijms * */ @Interceptor @Priority(200) public class HelloInterceptorEnabler { }
@PreMatching @Priority(Priorities.HEADER_DECORATOR) public class TypeGPXFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext rc) { String maybeType = rc.getUriInfo().getQueryParameters().getFirst("type"); if (maybeType != null && maybeType.equals("gpx")) { rc.getHeaders().putSingle(HttpHeaders.ACCEPT, "application/gpx+xml"); } } }
/** * <p>Title: FastJsonAutoDiscoverable</p> * <p>Description: FastJsonAutoDiscoverable</p> * * @author Victor.Zxy * @see AutoDiscoverable * @since 1.2.37 */ @Priority(AutoDiscoverable.DEFAULT_PRIORITY - 1) public class FastJsonAutoDiscoverable implements AutoDiscoverable { public volatile static boolean autoDiscover = true; @Override public void configure(final FeatureContext context) { final Configuration config = context.getConfiguration(); // Register FastJson. if (!config.isRegistered(FastJsonFeature.class) && autoDiscover) { context.register(FastJsonFeature.class); } } }
/** * Transactional interceptor to help retain {@link WebApplicationException} * thrown by transactional beans. */ @Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199) @Interceptor @Transactional public final class WebAppExceptionInterceptor implements Serializable { private static final long serialVersionUID = -1L; @Inject WebAppExceptionHolder store; @AroundInvoke public Object intercept(final InvocationContext ic) throws Exception { try { return ic.proceed(); } catch (final WebApplicationException wae) { if (store != null) { store.exception = wae; } throw wae; } } }
/** * for DI purposes */ @ApplicationScoped @Alternative @Priority(Interceptor.Priority.LIBRARY_BEFORE) public class NullConverter implements SingleValueConverter { @Override public String toString(Object o) {return null;} @Override public Object fromString(String s) {return null;} @Override public boolean canConvert(Class aClass) {return false;} }
@Provider @Priority(Integer.MIN_VALUE) public class TimedMetricsFilter extends AbstractMetricsFilter { private final Timer timer; public TimedMetricsFilter(MetricRegistry metricRegistry, ResourceInfo resourceInfo) { final Timed annotation = resourceInfo.getResourceMethod().getAnnotation(Timed.class); timer = metricRegistry.timer(chooseName(annotation.name(), annotation.absolute(), resourceInfo.getResourceMethod())); } @Override public void filter(ContainerRequestContext requestContext) throws IOException { requestContext.setProperty("metricsTimerContext", timer.time()); } @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { final Timer.Context context = (Timer.Context) requestContext.getProperty("metricsTimerContext"); if (context == null) return; final long elapsedNanos = context.stop(); responseContext.getHeaders().add("X-Runtime-Microseconds", TimeUnit.NANOSECONDS.toMicros(elapsedNanos)); } }
@Interceptor @Transactional(Transactional.TxType.REQUIRED) @Priority(Interceptor.Priority.PLATFORM_BEFORE + 200) public class RequiredInterceptor extends InterceptorBase { @AroundInvoke public Object intercept(final InvocationContext ic) throws Exception { return super.intercept(ic); } @Override protected TransactionPolicy getPolicy() throws SystemException { return new TxRequired(getTransactionManager()); } }