javax.interceptor.Interceptor类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中javax.interceptor.Interceptor类的一些代码示例,展示了Interceptor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Interceptor类的具体详情如下:
包路径:javax.interceptor.Interceptor
类名称:Interceptor

Interceptor介绍

暂无

代码示例

代码示例来源:origin: jersey/jersey

  1. @Interceptor
  2. @Priority(Interceptor.Priority.PLATFORM_AFTER + 800)
  3. public class CdiInterceptorWrapper {
  4. @Inject
  5. private CdiInterceptorWrapperExtension extension;

代码示例来源:origin: jersey/jersey

  1. /**
  2. * Interceptor checking James as a user in query params.
  3. *
  4. * @author Petr Bouda
  5. */
  6. @Secured
  7. @Interceptor
  8. public class SecurityInterceptor {
  9. @Inject
  10. NameService nameService;
  11. @Inject
  12. JaxrsService jaxrsService;
  13. @AroundInvoke
  14. public Object logMethodEntry(InvocationContext ctx) throws Exception {
  15. MultivaluedMap<String, String> params = jaxrsService.getUriInfo().getQueryParameters();
  16. String user = params.getFirst("user");
  17. if (nameService.getName().equals(user)) {
  18. return ctx.proceed();
  19. } else {
  20. throw new ForbiddenException("Forbidden resource for the user: " + user);
  21. }
  22. }
  23. }

代码示例来源:origin: jersey/jersey

  1. @Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199)
  2. @Interceptor
  3. @Transactional
  4. @JerseyVetoed
  5. public final class WebAppExceptionInterceptor implements Serializable {
  6. @Inject
  7. @TransactionalExceptionInterceptorProvider.WaeQualifier
  8. private WebAppExceptionHolder store;

代码示例来源:origin: org.apache.tomee/openejb-core

  1. @Interceptor
  2. @Transactional(Transactional.TxType.SUPPORTS)
  3. @Priority(Interceptor.Priority.PLATFORM_BEFORE + 200)
  4. public class SupportsInterceptor extends InterceptorBase {
  5. @AroundInvoke
  6. public Object intercept(final InvocationContext ic) throws Exception {
  7. return super.intercept(ic);
  8. }
  9. @Override
  10. protected TransactionPolicy getPolicy() throws SystemException, ApplicationException {
  11. return new TxSupports(getTransactionManager());
  12. }
  13. }

代码示例来源:origin: weld/core

  1. /** Uses CDI API binding - @javax.enterprise.context.control.ActivateRequestContext.
  2. *
  3. * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
  4. */
  5. @Vetoed
  6. @Interceptor
  7. @ActivateRequestContext
  8. @SuppressWarnings("checkstyle:magicnumber")
  9. @Priority(Interceptor.Priority.PLATFORM_BEFORE + 100)
  10. public class CdiRequestContextActivatorInterceptor extends AbstractActivateRequestContextInterceptor {
  11. @Inject
  12. public CdiRequestContextActivatorInterceptor(@Unbound RequestContext requestContext, BeanManagerImpl beanManager) {
  13. super(requestContext, beanManager);
  14. }
  15. }

代码示例来源:origin: javaee-samples/javaee7-samples

  1. /**
  2. * Class used to enable (activate) the dynamic interceptor and sets its priority
  3. *
  4. * @author Arjan Tijms
  5. *
  6. */
  7. @Interceptor
  8. @Priority(200)
  9. public class HelloInterceptorEnabler {
  10. }

代码示例来源:origin: javamelody/javamelody

  1. /**
  2. * Intercepteur pour CDI & pour EJB 3.1 (Java EE 6+),
  3. * configuré automatiquement pour les beans et méthodes ayant l'annotation @{@link Asynchronous}.
  4. * @author Emeric Vernat
  5. */
  6. @Interceptor
  7. @Asynchronous
  8. public class MonitoringAsynchronousCdiInterceptor extends MonitoringInterceptor {
  9. private static final long serialVersionUID = 1L;
  10. // note: it would be cool to automatically monitor methods having @Schedule or @Schedules like @Asynchronous,
  11. // without having to add @Monitored on the method, but we can't
  12. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * {@link Interceptor} for handling the {@link CompleteTask}-Annotation
  3. *
  4. * @author Daniel Meyer
  5. */
  6. @Interceptor
  7. @CompleteTask
  8. public class CompleteTaskInterceptor implements Serializable {
  9. private static final long serialVersionUID = 1L;
  10. @Inject BusinessProcess businessProcess;
  11. @AroundInvoke
  12. public Object invoke(InvocationContext ctx) throws Exception {
  13. try {
  14. Object result = ctx.proceed();
  15. CompleteTask completeTaskAnnotation = ctx.getMethod().getAnnotation(CompleteTask.class);
  16. boolean endConversation = completeTaskAnnotation.endConversation();
  17. businessProcess.completeTask(endConversation);
  18. return result;
  19. } catch (InvocationTargetException e) {
  20. throw new ProcessEngineCdiException("Error while completing task: "+e.getCause().getMessage(), e.getCause());
  21. }
  22. }
  23. }

代码示例来源:origin: org.glassfish.jersey.containers.glassfish/jersey-gf-cdi

  1. /**
  2. * Transactional interceptor to help retain {@link WebApplicationException}
  3. * thrown by transactional beans.
  4. */
  5. @Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199)
  6. @Interceptor
  7. @Transactional
  8. public final class WebAppExceptionInterceptor implements Serializable {
  9. private static final long serialVersionUID = -1L;
  10. @Inject
  11. WebAppExceptionHolder store;
  12. @AroundInvoke
  13. public Object intercept(final InvocationContext ic) throws Exception {
  14. try {
  15. return ic.proceed();
  16. } catch (final WebApplicationException wae) {
  17. if (store != null) {
  18. store.exception = wae;
  19. }
  20. throw wae;
  21. }
  22. }
  23. }

代码示例来源:origin: org.apache.tomee/openejb-core

  1. @Interceptor
  2. @Transactional(Transactional.TxType.MANDATORY)
  3. @Priority(Interceptor.Priority.PLATFORM_BEFORE + 200)
  4. public class MandatoryInterceptor extends InterceptorBase {
  5. @AroundInvoke
  6. public Object intercept(final InvocationContext ic) throws Exception {
  7. return super.intercept(ic);
  8. }
  9. @Override
  10. protected TransactionPolicy getPolicy() throws SystemException, ApplicationException {
  11. return new TxMandatory(getTransactionManager());
  12. }
  13. }

代码示例来源:origin: weld/core

  1. /** Uses CDI API binding - @javax.enterprise.context.control.ActivateRequestContext.
  2. *
  3. * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
  4. */
  5. @Vetoed
  6. @Interceptor
  7. @ActivateRequestContext
  8. @SuppressWarnings("checkstyle:magicnumber")
  9. @Priority(Interceptor.Priority.PLATFORM_BEFORE + 100)
  10. public class CdiRequestContextActivatorInterceptor extends AbstractActivateRequestContextInterceptor {
  11. @Inject
  12. public CdiRequestContextActivatorInterceptor(@Unbound RequestContext requestContext, BeanManagerImpl beanManager) {
  13. super(requestContext, beanManager);
  14. }
  15. }

代码示例来源:origin: javaee-samples/javaee7-samples

  1. /**
  2. * @author Arun Gupta
  3. */
  4. @Priority(Interceptor.Priority.APPLICATION + 10)
  5. @Interceptor
  6. @MyAroundConstructInterceptorBinding
  7. public class MyAroundConstructInterceptor {
  8. @AroundConstruct
  9. public void validateConstructor(InvocationContext context) {
  10. System.out.println("MyAroundConstructInterceptor.validateConstructor");
  11. }
  12. }

代码示例来源:origin: javamelody/javamelody

  1. /**
  2. * Intercepteur pour CDI & pour EJB 3.1 (Java EE 6+).
  3. * Il est destiné à un compteur pour les statistiques d'exécutions de
  4. * méthodes @{@link javax.faces.bean.RequestScoped}, @{@link SessionScoped}, @{@link ApplicationScoped}
  5. * ( ainsi que @{@link Stateless}, @{@link Stateful} ou @{@link MessageDriven} ).
  6. * Il peut être paramétré par l'annotation @{@link Monitored} dans les sources java des classes d'implémentations de beans CDI ou d'ejb.
  7. * (ou alors par l'annotation @{@link javax.interceptor.Interceptors} dans les mêmes classes).
  8. * @author Emeric Vernat
  9. */
  10. @Interceptor
  11. @Monitored
  12. public class MonitoringCdiInterceptor extends MonitoringInterceptor {
  13. private static final long serialVersionUID = 1L;
  14. }

代码示例来源:origin: hibernate/hibernate-validator

  1. @Interceptor
  2. @Priority(Interceptor.Priority.PLATFORM_AFTER + 800)
  3. public class ValidationInterceptor implements Serializable {
  4. @Inject
  5. private Validator validator;

代码示例来源:origin: camunda/camunda-bpm-platform

  1. @Interceptor
  2. @StartProcess("")
  3. public class StartProcessInterceptor implements Serializable {
  4. @Inject BusinessProcess businessProcess;

代码示例来源:origin: org.glassfish.jersey.ext.cdi/jersey-cdi1x-transaction

  1. @Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199)
  2. @Interceptor
  3. @Transactional
  4. @JerseyVetoed
  5. public final class WebAppExceptionInterceptor implements Serializable {
  6. @Inject
  7. @TransactionalExceptionInterceptorProvider.WaeQualifier
  8. private WebAppExceptionHolder store;

代码示例来源:origin: org.apache.tomee/openejb-core

  1. @Interceptor
  2. @Transactional(Transactional.TxType.REQUIRES_NEW)
  3. @Priority(Interceptor.Priority.PLATFORM_BEFORE + 200)
  4. public class RequiredNewInterceptor extends InterceptorBase {
  5. @AroundInvoke
  6. public Object intercept(final InvocationContext ic) throws Exception {
  7. return super.intercept(ic);
  8. }
  9. @Override
  10. protected TransactionPolicy getPolicy() throws SystemException, ApplicationException {
  11. return new TxRequiresNew(getTransactionManager());
  12. }
  13. }

代码示例来源:origin: weld/core

  1. /** Uses CDI API binding - @javax.enterprise.context.control.ActivateRequestContext.
  2. *
  3. * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
  4. */
  5. @Vetoed
  6. @Interceptor
  7. @ActivateRequestContext
  8. @SuppressWarnings("checkstyle:magicnumber")
  9. @Priority(Interceptor.Priority.PLATFORM_BEFORE + 100)
  10. public class CdiRequestContextActivatorInterceptor extends AbstractActivateRequestContextInterceptor {
  11. @Inject
  12. public CdiRequestContextActivatorInterceptor(@Unbound RequestContext requestContext, BeanManagerImpl beanManager) {
  13. super(requestContext, beanManager);
  14. }
  15. }

代码示例来源:origin: javaee-samples/javaee7-samples

  1. /**
  2. * Interceptors with smaller priority values are called first.
  3. *
  4. * @author Radim Hanus
  5. */
  6. @Interceptor
  7. @MyInterceptorBinding
  8. @Priority(Interceptor.Priority.APPLICATION + 200)
  9. public class LowPriorityInterceptor {
  10. @AroundInvoke
  11. public Object log(InvocationContext context) throws Exception {
  12. Object[] parameters = context.getParameters();
  13. if (parameters.length > 0 && parameters[0] instanceof String) {
  14. String param = (String) parameters[0];
  15. parameters[0] = param + " Nice to meet you.";
  16. context.setParameters(parameters);
  17. }
  18. return context.proceed();
  19. }
  20. }

代码示例来源:origin: javaee-samples/javaee7-samples

  1. /**
  2. * @author Arun Gupta
  3. * @author Radim Hanus
  4. */
  5. @Interceptor
  6. @MyInterceptorBinding
  7. public class MyInterceptor {
  8. @AroundInvoke
  9. public Object log(InvocationContext context) throws Exception {
  10. Object[] parameters = context.getParameters();
  11. if (parameters.length > 0 && parameters[0] instanceof String) {
  12. String param = (String) parameters[0];
  13. parameters[0] = "Hi " + param + " !";
  14. context.setParameters(parameters);
  15. }
  16. return context.proceed();
  17. }
  18. }

相关文章

Interceptor类方法