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

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

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

Interceptor介绍

暂无

代码示例

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

@Interceptor
@Priority(Interceptor.Priority.PLATFORM_AFTER + 800)
public class CdiInterceptorWrapper {
  @Inject
  private CdiInterceptorWrapperExtension extension;

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

/**
 * Interceptor checking James as a user in query params.
 *
 * @author Petr Bouda
 */
@Secured
@Interceptor
public class SecurityInterceptor {

  @Inject
  NameService nameService;

  @Inject
  JaxrsService jaxrsService;

  @AroundInvoke
  public Object logMethodEntry(InvocationContext ctx) throws Exception {
    MultivaluedMap<String, String> params = jaxrsService.getUriInfo().getQueryParameters();
    String user = params.getFirst("user");

    if (nameService.getName().equals(user)) {
      return ctx.proceed();
    } else {
      throw new ForbiddenException("Forbidden resource for the user: " + user);
    }
  }
}

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

@Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199)
@Interceptor
@Transactional
@JerseyVetoed
public final class WebAppExceptionInterceptor implements Serializable {
  @Inject
  @TransactionalExceptionInterceptorProvider.WaeQualifier
  private WebAppExceptionHolder store;

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

@Interceptor
@Transactional(Transactional.TxType.SUPPORTS)
@Priority(Interceptor.Priority.PLATFORM_BEFORE + 200)
public class SupportsInterceptor extends InterceptorBase {
  @AroundInvoke
  public Object intercept(final InvocationContext ic) throws Exception {
    return super.intercept(ic);
  }

  @Override
  protected TransactionPolicy getPolicy() throws SystemException, ApplicationException {
    return new TxSupports(getTransactionManager());
  }
}

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

/** 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);
  }
}

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

/**
 * Class used to enable (activate) the dynamic interceptor and sets its priority
 * 
 * @author Arjan Tijms
 *
 */
@Interceptor
@Priority(200)
public class HelloInterceptorEnabler {

}

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

/**
 * Intercepteur pour CDI & pour EJB 3.1 (Java EE 6+),
 * configuré automatiquement pour les beans et méthodes ayant l'annotation @{@link Asynchronous}.
 * @author Emeric Vernat
 */
@Interceptor
@Asynchronous
public class MonitoringAsynchronousCdiInterceptor extends MonitoringInterceptor {
  private static final long serialVersionUID = 1L;

  // note: it would be cool to automatically monitor methods having @Schedule or @Schedules like @Asynchronous,
  // without having to add @Monitored on the method, but we can't
}

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

/**
 * {@link Interceptor} for handling the {@link CompleteTask}-Annotation
 * 
 * @author Daniel Meyer
 */
@Interceptor
@CompleteTask
public class CompleteTaskInterceptor implements Serializable {

 private static final long serialVersionUID = 1L;

 @Inject BusinessProcess businessProcess;

 @AroundInvoke
 public Object invoke(InvocationContext ctx) throws Exception {
  try {
   Object result = ctx.proceed();

   CompleteTask completeTaskAnnotation = ctx.getMethod().getAnnotation(CompleteTask.class);
   boolean endConversation = completeTaskAnnotation.endConversation();    
   businessProcess.completeTask(endConversation);     

   return result;
  } catch (InvocationTargetException e) {
   throw new ProcessEngineCdiException("Error while completing task: "+e.getCause().getMessage(), e.getCause());
  }
 }

}

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

/**
 * 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;
    }
  }
}

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

@Interceptor
@Transactional(Transactional.TxType.MANDATORY)
@Priority(Interceptor.Priority.PLATFORM_BEFORE + 200)
public class MandatoryInterceptor extends InterceptorBase {
  @AroundInvoke
  public Object intercept(final InvocationContext ic) throws Exception {
    return super.intercept(ic);
  }

  @Override
  protected TransactionPolicy getPolicy() throws SystemException, ApplicationException {
    return new TxMandatory(getTransactionManager());
  }
}

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

/** 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);
  }
}

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

/**
 * @author Arun Gupta
 */
@Priority(Interceptor.Priority.APPLICATION + 10)
@Interceptor
@MyAroundConstructInterceptorBinding
public class MyAroundConstructInterceptor {

  @AroundConstruct
  public void validateConstructor(InvocationContext context) {
    System.out.println("MyAroundConstructInterceptor.validateConstructor");
  }
}

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

/**
 * Intercepteur pour CDI & pour EJB 3.1 (Java EE 6+).
 * Il est destiné à un compteur pour les statistiques d'exécutions de
 * méthodes @{@link javax.faces.bean.RequestScoped}, @{@link SessionScoped}, @{@link ApplicationScoped}
 * ( ainsi que @{@link Stateless}, @{@link Stateful} ou @{@link MessageDriven} ).
 * 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.
 * (ou alors par l'annotation @{@link javax.interceptor.Interceptors} dans les mêmes classes).
 * @author Emeric Vernat
 */
@Interceptor
@Monitored
public class MonitoringCdiInterceptor extends MonitoringInterceptor {
  private static final long serialVersionUID = 1L;
}

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

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

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

@Interceptor
@StartProcess("")
public class StartProcessInterceptor implements Serializable {
 @Inject BusinessProcess businessProcess;

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

@Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199)
@Interceptor
@Transactional
@JerseyVetoed
public final class WebAppExceptionInterceptor implements Serializable {
  @Inject
  @TransactionalExceptionInterceptorProvider.WaeQualifier
  private WebAppExceptionHolder store;

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

@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());
  }
}

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

/** 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);
  }
}

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

/**
 * Interceptors with smaller priority values are called first.
 *
 * @author Radim Hanus
 */
@Interceptor
@MyInterceptorBinding
@Priority(Interceptor.Priority.APPLICATION + 200)
public class LowPriorityInterceptor {
  @AroundInvoke
  public Object log(InvocationContext context) throws Exception {
    Object[] parameters = context.getParameters();
    if (parameters.length > 0 && parameters[0] instanceof String) {
      String param = (String) parameters[0];
      parameters[0] = param + " Nice to meet you.";
      context.setParameters(parameters);
    }
    return context.proceed();
  }
}

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

/**
 * @author Arun Gupta
 * @author Radim Hanus
 */
@Interceptor
@MyInterceptorBinding
public class MyInterceptor {
  @AroundInvoke
  public Object log(InvocationContext context) throws Exception {
    Object[] parameters = context.getParameters();
    if (parameters.length > 0 && parameters[0] instanceof String) {
      String param = (String) parameters[0];
      parameters[0] = "Hi " + param + " !";
      context.setParameters(parameters);
    }
    return context.proceed();
  }
}

相关文章

Interceptor类方法