public Object invoke(Invocation invocation) throws Throwable { try { AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsFlags.IN_EJB_TIMEOUT); return invocation.invokeNext(); } finally { AllowedOperationsAssociation.popInMethodFlag(); } }
private void assertAllowedIn(String timerMethod) { AllowedOperationsAssociation.assertAllowedIn(timerMethod, IN_BUSINESS_METHOD | IN_EJB_TIMEOUT); } }
/** * Throw an IllegalStateException if the current inMethodFlag * does not match the given flags */ public static void assertAllowedIn(String ctxMethod, int flags) { Stack inMethodStack = (Stack)threadLocal.get(); // Strict validation, the caller MUST set the in method flag if (inMethodStack.empty()) { throw new IllegalStateException("Cannot obtain inMethodFlag for: " + ctxMethod); } // The container should push a method flag into the context just before // a call to the instance method if (inMethodStack.empty() == false) { // Check if the given ctxMethod can be called from the ejb instance // this relies on the inMethodFlag being pushed prior to the call to the ejb method Integer inMethodFlag = ((Integer) inMethodStack.peek()); if ((inMethodFlag.intValue() & flags) == 0 && inMethodFlag.intValue() != IN_INTERCEPTOR_METHOD) { String message = ctxMethod + " should not be access from this bean method: " + methodMap.get(inMethodFlag); IllegalStateException ex = new IllegalStateException(message); log.error(message + ", allowed is " + getAllowedMethodList(flags), ex); throw ex; } } }
AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_CREATE); Method ejbCreate = instance.getClass().getMethod("ejbCreate", new Class[0]); ejbCreate.invoke(instance, new Object[0]);
/** * Return the current inMethodFlag in String form, * or null if there is none */ public static String peekInMethodFlagAsString() { int currentMethodFlag = peekInMethodFlag(); return (String)methodMap.get(new Integer(currentMethodFlag)); }
public void storeEntity(EntityEnterpriseContext ctx) throws RemoteException { AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_STORE); try { store.storeEntity(ctx); } finally { AllowedOperationsAssociation.popInMethodFlag(); } }
public MessageContext getMessageContext() throws IllegalStateException { AllowedOperationsAssociation.assertAllowedIn("getMessageContext", IN_SERVICE_ENDPOINT_METHOD); return soapMessageContext; } }
public Object findEntity(Method finderMethod, Object[] args, EntityEnterpriseContext ctx, GenericEntityObjectFactory factory) throws Exception { try { AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_FIND); return store.findEntity(finderMethod, args, ctx, factory); } finally { AllowedOperationsAssociation.popInMethodFlag(); } }
public Object getPrimaryKey() { AllowedOperationsAssociation.assertAllowedIn("getPrimaryKey", IN_EJB_POST_CREATE | IN_EJB_REMOVE | IN_EJB_ACTIVATE | IN_EJB_PASSIVATE | IN_EJB_LOAD | IN_EJB_STORE | IN_BUSINESS_METHOD | IN_EJB_TIMEOUT); return id; }
/** * find multiple entities */ public Collection findEntities(Method finderMethod, Object[] args, EntityEnterpriseContext ctx, GenericEntityObjectFactory factory) throws Exception { try { // return the finderResults so that the invoker layer can extend this back // giving the client an OO 'cursor' AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_FIND); return store.findEntities(finderMethod, args, ctx, factory); } finally { AllowedOperationsAssociation.popInMethodFlag(); } }
private void assertAllowedIn(String timerMethod) { // TODO: This isn't handled by the AS timer service itself AllowedOperationsAssociation.assertAllowedIn(timerMethod, IN_BUSINESS_METHOD | IN_EJB_TIMEOUT | IN_SERVICE_ENDPOINT_METHOD); }
public void afterBegin() { if (notifySession) { try { AllowedOperationsAssociation.pushInMethodFlag(IN_AFTER_BEGIN); afterBegin.invoke(ctx.getInstance(), new Object[0]); } catch (Exception e) { log.error("failed to invoke afterBegin", e); } finally{ AllowedOperationsAssociation.popInMethodFlag(); } } }
private void assertAllowedIn(String timerMethod) { AllowedOperationsAssociation.assertAllowedIn(timerMethod, IN_EJB_POST_CREATE | IN_EJB_REMOVE | IN_EJB_LOAD | IN_EJB_STORE | IN_BUSINESS_METHOD | IN_EJB_TIMEOUT); } }
public StatefulSessionEnterpriseContext(Object instance, Container con) throws RemoteException { super(instance, con); ctx = new StatefulSessionContextImpl(); try { AllowedOperationsAssociation.pushInMethodFlag(IN_SET_SESSION_CONTEXT); ((SessionBean)instance).setSessionContext(ctx); } finally { AllowedOperationsAssociation.popInMethodFlag(); } }
private void checkUserTransactionMethods() { AllowedOperationsAssociation.assertAllowedIn("UserTransaction methods", IN_BUSINESS_METHOD | IN_EJB_TIMEOUT | IN_SERVICE_ENDPOINT_METHOD); }
public EntityEnterpriseContext(Object instance, Container con) throws RemoteException { super(instance, con); ctx = new EntityContextImpl(); try { AllowedOperationsAssociation.pushInMethodFlag(IN_SET_ENTITY_CONTEXT); ((EntityBean)instance).setEntityContext(ctx); } finally { AllowedOperationsAssociation.popInMethodFlag(); } }
private void assertAllowedIn(String timerMethod) { AllowedOperationsAssociation.assertAllowedIn(timerMethod, IN_BUSINESS_METHOD | IN_EJB_TIMEOUT | IN_SERVICE_ENDPOINT_METHOD); } }
public void callTimeout(Timer timer) throws Exception { if (timeoutMethod == null) throw new EJBException("No method has been annotated with @Timeout"); Object[] args = { timer }; if(timeoutMethod.getParameterTypes().length == 0) args = null; AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsFlags.IN_EJB_TIMEOUT); try { localInvoke(timeoutMethod, args); } catch (Throwable throwable) { if (throwable instanceof Exception) throw (Exception) throwable; throw new RuntimeException(throwable); } finally { AllowedOperationsAssociation.popInMethodFlag(); } }
public MessageContext getMessageContext() throws IllegalStateException { AllowedOperationsAssociation.assertAllowedIn("getMessageContext", NOT_ALLOWED); return null; }
public void invokePostConstruct(BeanContext<?> beanContext) { // FIXME: This is a dirty hack to notify AS EJBTimerService about what's going on AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsAssociation.IN_EJB_CREATE); try { this.pushContext(beanContext); invokeCallback(beanContext, PostConstruct.class); } finally { this.popContext(); AllowedOperationsAssociation.popInMethodFlag(); } }