@Override public Object processInvocation(final InterceptorContext context) throws Exception { if ((context.getMethod().getName().equals("equals")) || context.getMethod().getName().equals("isIdentical")) { final Object other = context.getParameters()[0]; if (other == null) { return false; } final Class<?> proxyType = componentView.getProxyClass(); return proxyType.isAssignableFrom(other.getClass()); } else if (context.getMethod().getName().equals("hashCode")) { //use the identity of the component view as a hash code return componentView.hashCode(); } else { return context.proceed(); } } }
@Override public Object invoke(InterceptorContext interceptorContext) throws Exception { if(component instanceof BasicComponent) { ((BasicComponent) component).waitForComponentStart(); } final Method method = interceptorContext.getMethod(); final Interceptor interceptor = viewInterceptors.get(method); return interceptor.processInvocation(interceptorContext); }
Method invokedMethod = currentInvocationContext.getMethod(); if (invokedMethod == null) {
/** * Checks if the passed exception is an application exception. If yes, then throws back the * exception as-is. Else, wraps the exception in a {@link javax.ejb.EJBException} and throws the EJBException * * @param ex The exception to handle * @throws Exception Either the passed exception or an EJBException */ protected Exception handleException(final InterceptorContext invocation, Throwable ex) throws Exception { ApplicationExceptionDetails ae = component.getApplicationException(ex.getClass(), invocation.getMethod()); // it's an application exception, so just throw it back as-is if (ae != null) { throw (Exception)ex; } if (ex instanceof EJBException) { throw (EJBException) ex; } else if(ex instanceof Exception){ throw new EJBException((Exception)ex); } else { throw new EJBException(new RuntimeException(ex)); } }
@Override public Object processInvocation(final InterceptorContext context) throws Exception { if (context.getMethod().getName().equals("equals") || context.getMethod().getName().equals("isIdentical")) { final Object other = context.getParameters()[0]; final ComponentView componentView = context.getPrivateData(ComponentView.class); final Class<?> proxyType = componentView.getProxyClass(); final SessionID sessionId = context.getPrivateData(SessionID.class); if( proxyType.isAssignableFrom(other.getClass())) { //now we know that this is an ejb for the correct component view //as digging out the session id from the proxy object is not really //a viable option, we invoke equals() for the other instance with a //SessionIdHolder as the other side return other.equals(new SessionIdHolder(sessionId)); } else if(other instanceof SessionIdHolder) { return sessionId.equals( ((SessionIdHolder)other).sessionId); } else { return false; } } else if (context.getMethod().getName().equals("hashCode")) { final SessionID sessionId = context.getPrivateData(SessionID.class); //use the identity of the component view as a hash code return sessionId.hashCode(); } else { return context.proceed(); } }
protected TransactionAttributeType getCurrentTransactionAttribute() { final InterceptorContext invocation = CurrentInvocationContext.get(); final MethodIntf methodIntf = MethodIntfHelper.of(invocation); return getTransactionAttributeType(methodIntf, invocation.getMethod()); }
protected Object invokeInNoTx(InterceptorContext invocation, final EJBComponent component) throws Exception { try { return invocation.proceed(); } catch (Error e) { throw EjbLogger.ROOT_LOGGER.unexpectedError(e); } catch (EJBException e) { throw e; } catch (RuntimeException e) { ApplicationExceptionDetails ae = component.getApplicationException(e.getClass(), invocation.getMethod()); throw ae != null ? e : new EJBException(e); } catch (Exception e) { throw e; } catch (Throwable t) { throw new EJBException(new UndeclaredThrowableException(t)); } }
public boolean getRollbackOnly() throws IllegalStateException { // to allow override per invocation final InterceptorContext context = CurrentInvocationContext.get(); if (context.getMethod() == null) { throw EjbLogger.ROOT_LOGGER.lifecycleMethodNotAllowed("getRollbackOnly"); } return instance.getComponent().getRollbackOnly(); }
public void setRollbackOnly() throws IllegalStateException { // to allow override per invocation final InterceptorContext context = CurrentInvocationContext.get(); if (context.getMethod() == null) { throw EjbLogger.ROOT_LOGGER.lifecycleMethodNotAllowed("getRollbackOnly"); } instance.getComponent().setRollbackOnly(); } }
public Object processInvocation(final InterceptorContext context) throws Exception { final Component component = context.getPrivateData(Component.class); if (! (component instanceof EJBComponent)) { throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, EJBComponent.class); } final Iterator<String> iterator = rolesAllowed.iterator(); if (iterator.hasNext()) { final SecurityDomain securityDomain = context.getPrivateData(SecurityDomain.class); final SecurityIdentity identity = securityDomain.getCurrentSecurityIdentity(); final Roles ejbRoles = identity.getRoles("ejb", true); do { final String role = iterator.next(); if (ejbRoles.contains(role) || (role.equals("**") && !identity.isAnonymous())) { return context.proceed(); } } while (iterator.hasNext()); } throw EjbLogger.ROOT_LOGGER.invocationOfMethodNotAllowed(context.getMethod(), ((EJBComponent) component).getComponentName()); } }
@Override public Object processInvocation(final InterceptorContext context) throws Exception { final EJBComponent component = getComponent(context, EJBComponent.class); if (!component.isStatisticsEnabled()) return context.proceed(); final Long startWaitTime = (Long) context.getPrivateData(WaitTimeInterceptor.START_WAIT_TIME); final long waitTime = startWaitTime != null && startWaitTime != 0L ? System.currentTimeMillis() - startWaitTime : 0L; component.getInvocationMetrics().startInvocation(); final long start = System.currentTimeMillis(); try { return context.proceed(); } finally { final long executionTime = System.currentTimeMillis() - start; component.getInvocationMetrics().finishInvocation(context.getMethod(), waitTime, executionTime); } } }
private void assertInvocationAllowed() { AllowedMethodsInformation.checkAllowed(MethodType.TIMER_SERVICE_METHOD); final InterceptorContext currentInvocationContext = CurrentInvocationContext.get(); if (currentInvocationContext == null) { return; } // If the method in current invocation context is null, // then it represents a lifecycle callback invocation Method invokedMethod = currentInvocationContext.getMethod(); if (invokedMethod == null) { // it's a lifecycle callback Component component = currentInvocationContext.getPrivateData(Component.class); if (!(component instanceof SingletonComponent)) { throw EjbLogger.EJB3_TIMER_LOGGER.failToInvokeTimerServiceDoLifecycle(); } } }
Method invokedMethod = context.getMethod(); ComponentView componentView = context.getPrivateData(ComponentView.class); String viewClassOfInvokedMethod = componentView.getViewClass().getName();
protected Object invokeInCallerTx(InterceptorContext invocation, Transaction tx, final EJBComponent component) throws Exception { try { return invocation.proceed(); } catch (Error e) { final EJBTransactionRolledbackException e2 = EjbLogger.ROOT_LOGGER.unexpectedErrorRolledBack(e); setRollbackOnly(tx, e2); throw e2; } catch (Exception e) { ApplicationExceptionDetails ae = component.getApplicationException(e.getClass(), invocation.getMethod()); if (ae != null) { if (ae.isRollback()) setRollbackOnly(tx, e); throw e; } try { throw e; } catch (EJBTransactionRolledbackException | NoSuchEJBException | NoSuchEntityException e2) { setRollbackOnly(tx, e2); throw e2; } catch (RuntimeException e2) { final EJBTransactionRolledbackException e3 = new EJBTransactionRolledbackException(e2.getMessage(), e2); setRollbackOnly(tx, e3); throw e3; } } catch (Throwable t) { final EJBException e = new EJBException(new UndeclaredThrowableException(t)); setRollbackOnly(tx, e); throw e; } }
throw ex; } catch (Throwable t) { final Method invokedMethod = interceptorContext.getMethod();
result = invocation.proceed(); } catch (Throwable t) { ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod()); try { try {
public Object processInvocation(final InterceptorContext context) throws Exception { ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class); if (componentInstance == null) { throw EeLogger.ROOT_LOGGER.noComponentInstance(); } Method oldMethod = context.getMethod(); try { context.setMethod(componentMethod); context.setTarget(componentInstance.getInstance()); return componentInstance.getInterceptor(componentMethod).processInvocation(context); } finally { context.setMethod(oldMethod); context.setTarget(null); } } }
@Override public Object processInvocation(final InterceptorContext invocation) throws Exception { // Do we have a foreign transaction context? Transaction tx = TxServerInterceptor.getCurrentTransaction(); if (tx instanceof ForeignTransaction) { final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class); //for timer invocations there is no view, so the methodInf is attached directly //to the context. Otherwise we retrieve it from the invoked view MethodIntf methodIntf = invocation.getPrivateData(MethodIntf.class); if (methodIntf == null) { final ComponentView componentView = invocation.getPrivateData(ComponentView.class); if (componentView != null) { methodIntf = componentView.getPrivateData(MethodIntf.class); } else { methodIntf = MethodIntf.BEAN; } } final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod()); if (attr != TransactionAttributeType.NOT_SUPPORTED && attr != TransactionAttributeType.REQUIRES_NEW) { throw EjbLogger.ROOT_LOGGER.transactionPropagationNotSupported(); } } return invocation.proceed(); } }
public Object processInvocation(InterceptorContext invocation) throws Exception { final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class); final ContextTransactionManager tm = ContextTransactionManager.getInstance(); final int oldTimeout = tm.getTransactionTimeout(); try { final MethodIntf methodIntf = MethodIntfHelper.of(invocation); final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod()); final int timeoutInSeconds = component.getTransactionTimeout(methodIntf, invocation.getMethod()); switch (attr) { case MANDATORY: return mandatory(invocation, component); case NEVER: return never(invocation, component); case NOT_SUPPORTED: return notSupported(invocation, component); case REQUIRED: return required(invocation, component, timeoutInSeconds); case REQUIRES_NEW: return requiresNew(invocation, component, timeoutInSeconds); case SUPPORTS: return supports(invocation, component); default: throw EjbLogger.ROOT_LOGGER.unknownTxAttributeOnInvocation(attr, invocation); } } finally { // See also https://issues.jboss.org/browse/WFTC-44 tm.setTransactionTimeout(oldTimeout == ContextTransactionManager.getGlobalDefaultTransactionTimeout() ? 0 : oldTimeout); } }
return context.proceed(); } catch (Exception ex) { if(component.shouldDiscard(ex, context.getMethod())) { ROOT_LOGGER.tracef(ex, "Removing bean %s because of exception", sessionId); instance.discard();