@Override protected void initScope() { for (WeldClass<?> clazz = getWeldAnnotated(); clazz != null; clazz = clazz.getWeldSuperclass()) { Set<Annotation> scopes = new HashSet<Annotation>(); scopes.addAll(clazz.getDeclaredMetaAnnotations(Scope.class)); scopes.addAll(clazz.getDeclaredMetaAnnotations(NormalScope.class)); if (scopes.size() == 1) { if (getWeldAnnotated().isAnnotationPresent(scopes.iterator().next().annotationType())) { this.scope = scopes.iterator().next().annotationType(); log.trace(USING_SCOPE, scope, this); } break; } else if (scopes.size() > 1) { throw new DefinitionException(ONLY_ONE_SCOPE_ALLOWED, getWeldAnnotated()); } } if (this.scope == null) { initScopeFromStereotype(); } if (this.scope == null) { this.scope = Dependent.class; log.trace(USING_DEFAULT_SCOPE, this); } }
@Override protected void setAttribute(String key, Object instance) { HttpSession session = getSession(true); if (session != null) { session.setAttribute(key, instance); log.trace("Added " + key + " to session " + this.getSession(false).getId()); } else { log.trace("Unable to add " + key + " to session as no session could be obtained"); } }
@Override protected void removeAttribute(String key) { HttpSession session = getSession(false); if (session != null) { session.removeAttribute(key); log.trace("Removed " + key + " from session " + this.getSession(false).getId()); } else { log.trace("Unable to remove " + key + " from non-existent session"); } }
/** * Invokes the method on the correct version of the instance as obtained by a context lookup * * @param self the proxy instance. * @param proxiedMethod the overridden method declared in the super class or interface. * @param proceed the forwarder method for invoking the overridden method. It is null if the * overridden mehtod is abstract or declared in the interface. * @param args an array of objects containing the values of the arguments passed in the method * invocation on the proxy instance. If a parameter type is a primitive type, the type of the * array element is a wrapper class. * @return the resulting value of the method invocation. * @throws Throwable if the method invocation fails. */ public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[] args) throws Throwable { if (bean == null) { bean = Container.instance() .services() .get(ContextualStore.class) .<Bean<Object>, Object>getContextual(id); } Object proxiedInstance = getProxiedInstance(bean); if (proxiedInstance == null) { // TODO not sure if this right PLM return null; } if (proxiedMethod.getName().equals("equals") && proxiedMethod.getParameterTypes().length == 1 && proxiedMethod.getParameterTypes()[0] == Object.class && args[0] == self) { return true; } try { Method method = SecureReflections.lookupMethod(proxiedInstance, proxiedMethod); Object returnValue = SecureReflections.invoke(proxiedInstance, method, args); log.trace( CALL_PROXIED_METHOD, proxiedMethod, proxiedInstance, args, returnValue == null ? null : returnValue); return returnValue; } catch (InvocationTargetException e) { throw e.getCause(); } }
protected void deactivateConversationContext(HttpServletRequest request) { ConversationContext conversationContext = httpConversationContext(); if (conversationContext.isActive()) { // Only deactivate the context if one is already active, otherwise we get Exceptions boolean isTransient = conversationContext.getCurrentConversation().isTransient(); if (log.isTraceEnabled()) { if (isTransient) { log.trace(CLEANING_UP_TRANSIENT_CONVERSATION); } else { log.trace(CLEANING_UP_CONVERSATION, conversationContext.getCurrentConversation().getId()); } } conversationContext.invalidate(); conversationContext.deactivate(); if (isTransient) { beanManager .getAccessibleLenientObserverNotifier() .fireEvent(request, DestroyedLiteral.CONVERSATION); } } }
/** * Gets the propagated conversation id parameter from the request * * @return The conversation id (or null if not found) */ private static String getConversationId( HttpServletRequest request, ConversationContext conversationContext) { if (request.getParameter(NO_CID) != null) { return null; // ignore cid; WELD-919 } if (CONVERSATION_PROPAGATION_NONE.equals(request.getParameter(CONVERSATION_PROPAGATION))) { return null; // conversationPropagation=none (CDI-135) } String cidName = conversationContext.getParameterName(); String cid = request.getParameter(cidName); log.trace(FOUND_CONVERSATION_FROM_REQUEST, cid); return cid; }
/** * Constructor * * @param bean The bean to proxy * @param beanIndex The index to the bean in the manager bean list */ public ClientProxyMethodHandler(Bean<?> bean, String id) { this.bean = bean; this.id = id; log.trace("Created method handler for bean " + bean + " identified as " + id); }