List of usage examples for javax.interceptor InvocationContext proceed
public Object proceed() throws Exception;
From source file:com.zuehlke.sbdfx.transport.BaseResource.java
protected Object interceptMethodsDelegate(final InvocationContext ctx) throws Exception { return ctx.proceed(); }
From source file:br.com.blackhouse.internet.bindings.intercept.TransactionalInterceptor.java
@AroundInvoke public Object invoke(InvocationContext context) throws Exception { EntityTransaction transaction = entityManager.getTransaction(); try {// ww w .jav a2 s. c om if (!transaction.isActive()) { transaction.begin(); } return context.proceed(); } catch (Exception e) { logger.error("Exception in transactional method call", e); if (transaction != null) { transaction.rollback(); } throw e; } finally { if (transaction != null && transaction.isActive()) { transaction.commit(); } } }
From source file:EmployeeBean.java
@AroundInvoke public Object TimerLog(InvocationContext ctx) throws Exception { String beanClassName = ctx.getClass().getName(); String businessMethodName = ctx.getMethod().getName(); String target = beanClassName + "." + businessMethodName; long startTime = System.currentTimeMillis(); System.out.println("Invoking " + target); try {/*from w w w . j av a2 s . c om*/ return ctx.proceed(); } finally { System.out.println("Exiting " + target); long totalTime = System.currentTimeMillis() - startTime; System.out.println("Business method " + businessMethodName + "in " + beanClassName + "takes " + totalTime + "ms to execute"); } }
From source file:eu.europa.ec.fisheries.uvms.interceptors.TracingInterceptor.java
@AroundInvoke public Object logCall(InvocationContext context) throws Exception { final Stopwatch stopwatch = Stopwatch.createStarted(); try {//from w w w .j ava2 s. co m Object[] parameters = context.getParameters(); String params = ""; for (Object parameter : parameters) { params += " " + String.valueOf(parameter); } log.debug(String.format("invocation of method %s with parameters %s", context.getMethod(), params)); return context.proceed(); } finally { log.info(String.format("Elapsed time ==> " + stopwatch)); } }
From source file:com.flexive.rest.interceptors.FxRestCallInterceptor.java
@AroundInvoke public Object aroundInvoke(InvocationContext context) throws Exception { final Object target = context.getTarget(); if (target instanceof FxRestApiService) { final FxRestApiService service = (FxRestApiService) target; FxRestApiUtils.applyRequestParameters(service.getHttpHeaders(), service.getUriInfo()); if (LOG.isTraceEnabled()) { LOG.trace("REST-API call at " + service.getUriInfo().getBaseUri() + " with user " + FxContext.getUserTicket().getLoginName()); }//from w w w . j a va2 s .c o m final Object result = context.proceed(); if (result instanceof FxRestApiResponse) { // wrap response, set common parameters return FxRestApiUtils.buildResponse((FxRestApiResponse) result); } return result; } else { throw new IllegalStateException("@FxRestApi target does not implement FxRestApiService"); } }
From source file:com.fiveamsolutions.nci.commons.ejb.AuthorizationInterceptor.java
/** * Ensures that the current authenticated user is associated with the current session so that security filtering is * correct./*from w w w. j ava2 s . c om*/ * * @param invContext the method context * @return the method result * @throws Exception if invoking the method throws an exception. */ @AroundInvoke @SuppressWarnings("PMD.SignatureDeclareThrowsException") // method invocation wrapper requires throws Exception public Object prepareReturnValue(InvocationContext invContext) throws Exception { final String currentUser = UsernameHolder.getUser(); if (StringUtils.equalsIgnoreCase(UsernameHolder.ANONYMOUS_USERNAME, currentUser)) { String username; try { username = sessionContext.getCallerPrincipal().getName(); } catch (IllegalStateException e) { username = getUnknownUsername(); } UsernameHolder.setUser(username); } try { return invContext.proceed(); } finally { // See PO-6019. Username needs to be cleaned up after the thread is done. UsernameHolder.setUserCaseSensitive(currentUser); } }
From source file:gov.nih.nci.coppa.services.interceptor.RemoteAuthorizationInterceptor.java
/** * Ensures that the current authenticated user is associated with the current session so that security filtering is * correct./*from w w w . ja v a 2 s . c o m*/ * * @param invContext the method context * @return the method result * @throws Exception if invoking the method throws an exception. */ @Override @AroundInvoke @SuppressWarnings("PMD.SignatureDeclareThrowsException") public Object prepareReturnValue(InvocationContext invContext) throws Exception { final String currentUser = UsernameHolder.getUser(); if (StringUtils.equalsIgnoreCase(UsernameHolder.ANONYMOUS_USERNAME, currentUser)) { String username; try { username = sessionContext.getCallerPrincipal().getName(); } catch (IllegalStateException e) { username = getUnknownUsername(); } UsernameHolder.setUserCaseSensitive(username); } try { return invContext.proceed(); } finally { // See PO-6019. Username needs to be cleaned up after the thread is done. UsernameHolder.setUserCaseSensitive(currentUser); } }
From source file:br.gov.frameworkdemoiselle.internal.interceptor.AuditableInterceptor.java
@AroundInvoke public Object audit(InvocationContext ic) throws Exception { // TODO: Use the bundle to log information String operation = getOperation(ic); if (log.isDebugEnabled()) { log.debug("Starting auditing on operation : " + operation); }//from w w w . j a v a 2 s .co m // TODO: This has to be parameterized with some form if ("getDelegate".equals(operation)) { return ic.proceed(); } if (!auditorInstances.isUnsatisfied()) { try { throwExceptionIfHasOnlyDefaultAuditorInstances(); throwExceptionIfHasOnlyDefaultAuditInfoInstances(); for (Iterator<Auditor> it = auditorInstances.iterator(); it.hasNext();) { Auditor internalAuditor = it.next(); Class<?> internalAuditorClass = internalAuditor.getClass(); // Proxy classes are skiped. The correct implementation is // used. if (isAuditorAProxy(internalAuditorClass)) { internalAuditorClass = (Class<?>) internalAuditorClass.getSuperclass(); } if (isAuditorAllowed(internalAuditorClass)) { // Other Auditor instances exists or were already // processed. continue; } String auditorClass = internalAuditorClass.getName(); Class<?> auditorClassTypeParameter = getAuditorTargetResource(internalAuditorClass); if (log.isTraceEnabled()) { log.trace("--------------------------------------------"); log.trace("Current InternalAuditor instance: " + auditorClass); log.trace("Current AuditorClassTypeParameter: " + auditorClassTypeParameter); log.trace("--------------------------------------------"); } for (Iterator<AuditInfo> ita = auditInfoInstances.iterator(); ita.hasNext();) { AuditInfo auditInfo = ita.next(); Class<?> auditInfoClass = auditInfo.getClass(); if (DefaultAuditInfo.class.isAssignableFrom(auditInfoClass)) { continue; } Class<?> auditInfoClassTypeParameter = getAuditorTargetResource(auditInfoClass); if (log.isTraceEnabled()) { log.trace("--------------------------------------------"); log.trace("Current AuditInfoClass: " + auditInfoClass); log.trace("Current AuditInfoClassTypeParameter: " + auditInfoClassTypeParameter); log.trace("--------------------------------------------"); } // We only process audit info instance whose type // parameter matches the // type parameter for the auditor. if (auditorClassTypeParameter == auditInfoClassTypeParameter) { log.debug("auditorClassTypeParameter == auditInfoClassTypeParameter: " + auditorClassTypeParameter + " : " + auditInfoClassTypeParameter); log.debug("TypeParameters Match. Processing auditInfo instance:" + auditInfo + " ..."); processAuditInfo(ic, operation, internalAuditor, auditorClass, auditInfo); } else { // Do not process this audit info for the current // auditor. log.debug("TypeParameters doen't match. Skiping this auditInfo (" + auditInfoClass + ") for this auditor (" + auditorClass + ")"); continue; } } log.debug("All AuditInfo processed for auditor: " + auditorClass); } } catch (DemoiselleException ex) { // TODO: Move message to bundle log.error("Instance of : " + getType(ic) + " is annotated with Auditable but without correct configuration!"); log.error(ex.toString(), ex); throw ex; } catch (Exception ex) { log.error(ex.toString(), ex); throw ex; } } else { log.warn("No instances of br.gov.frameworkdemoiselle.security.Auditor found on classpath!"); } return ic.proceed(); }
From source file:be.fedict.trust.service.snmp.SNMPInterceptor.java
private Object process(InvocationContext invocationContext) throws Exception { this.values = new HashMap<String, Long>(); Object target = invocationContext.getTarget(); LOG.debug("process SNMP on " + target.getClass().getCanonicalName()); /*//from w w w. ja v a 2 s. c o m * Process the possible SNMP annotation on the method */ SNMP methodSnmp = invocationContext.getMethod().getAnnotation(SNMP.class); if (null != methodSnmp) { increment(methodSnmp.oid(), methodSnmp.service(), 1L); } /* * Process the possible SNMP annotation on the fields */ injectSnmpFields(target); /* * Invoke */ Object result = invocationContext.proceed(); /* * Post-process the possible SNMP annotation on the fields */ updateSnmpFields(target); /* * Check for SNMPCounter methods */ SNMPCounter snmpCounter = invocationContext.getMethod().getAnnotation(SNMPCounter.class); if (null == snmpCounter) { // check if other methods are annotated this way, if so execute them for (Method method : target.getClass().getMethods()) { if (null != method.getAnnotation(SNMPCounter.class)) { method.invoke(target); } } } /* * Update the SNMP derived fields */ updateSnmpDerivedFields(target); /* * Return the invocation result */ return result; }
From source file:Employee.java
@PostConstruct public void jndiInject(InvocationContext invocation) { Object target = invocation.getTarget(); Field[] fields = target.getClass().getDeclaredFields(); Method[] methods = target.getClass().getDeclaredMethods(); // find all @JndiInjected fields methods and set them try {//from w w w .jav a2 s . c o m InitialContext ctx = new InitialContext(); for (Method method : methods) { JndiInjected inject = method.getAnnotation(JndiInjected.class); if (inject != null) { Object obj = ctx.lookup(inject.value()); method.setAccessible(true); method.invoke(target, obj); } } for (Field field : fields) { JndiInjected inject = field.getAnnotation(JndiInjected.class); if (inject != null) { Object obj = ctx.lookup(inject.value()); field.setAccessible(true); field.set(target, obj); } } invocation.proceed(); } catch (Exception ex) { throw new EJBException("Failed to execute @JndiInjected", ex); } }