[jboss-cvs] JBossAS SVN: r73059 - in projects/ejb3/trunk/core/src/main/java/org/jboss: injection and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 5 07:27:09 EDT 2008


Author: heiko.braun at jboss.com
Date: 2008-05-05 07:27:08 -0400 (Mon, 05 May 2008)
New Revision: 73059

Added:
   projects/ejb3/trunk/core/src/main/java/org/jboss/injection/WebServiceContextProxy.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
Log:
EJBTHREE-1337: WebServiceContext proxy

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2008-05-05 10:43:29 UTC (rev 73058)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2008-05-05 11:27:08 UTC (rev 73059)
@@ -22,17 +22,6 @@
 package org.jboss.ejb3.stateless;
 
 
-import java.lang.reflect.Method;
-import java.util.Hashtable;
-import java.util.Map;
-
-import javax.ejb.EJBContext;
-import javax.ejb.EJBException;
-import javax.ejb.Handle;
-import javax.ejb.Timer;
-import javax.ejb.TimerService;
-import javax.naming.NamingException;
-
 import org.jboss.aop.Domain;
 import org.jboss.aop.MethodInfo;
 import org.jboss.aop.joinpoint.Invocation;
@@ -51,29 +40,32 @@
 import org.jboss.ejb3.proxy.ProxyUtils;
 import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
 import org.jboss.ejb3.proxy.factory.SessionProxyFactory;
-import org.jboss.ejb3.proxy.factory.stateful.StatefulProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateless.BaseStatelessRemoteProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateless.StatelessClusterProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateless.StatelessLocalProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateless.StatelessRemoteProxyFactory;
 import org.jboss.ejb3.session.SessionSpecContainer;
-import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.TimerServiceFactory;
-import org.jboss.injection.lang.reflect.BeanProperty;
+import org.jboss.injection.WebServiceContextProxy;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
 import org.jboss.proxy.ejb.handle.HomeHandleImpl;
-import org.jboss.wsf.spi.SPIProvider;
-import org.jboss.wsf.spi.SPIProviderResolver;
-import org.jboss.wsf.spi.invocation.ExtensibleWebServiceContext;
-import org.jboss.wsf.spi.invocation.InvocationType;
-import org.jboss.wsf.spi.invocation.WebServiceContextFactory;
 import org.jboss.wsf.spi.invocation.integration.InvocationContextCallback;
 import org.jboss.wsf.spi.invocation.integration.ServiceEndpointContainer;
 
+import javax.ejb.EJBException;
+import javax.ejb.Handle;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.naming.NamingException;
+import javax.xml.ws.WebServiceContext;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.Map;
 
+
 /**
  * Comment
  *
@@ -562,45 +554,17 @@
     */
    public Object invokeEndpoint(Method method, Object[] args, InvocationContextCallback invocationContextCallback) throws Throwable
    {
-      WSCallbackImpl callback = new WSCallbackImpl(invocationContextCallback);
-      return this.localInvoke(method, args, null, callback);
+      //  WebServiceContext association
+      WebServiceContextProxy.associateMessageContext(
+        invocationContextCallback.get( WebServiceContext.class )
+      );
+      
+      return this.localInvoke(method, args, null, null);
    }
 
-   static class WSCallbackImpl implements BeanContextLifecycleCallback
+   public String getContainerName()
    {
-      private javax.xml.ws.handler.MessageContext jaxwsMessageContext;
-      private javax.xml.rpc.handler.MessageContext jaxrpcMessageContext;
-
-      public WSCallbackImpl(InvocationContextCallback epInv)
-      {
-         jaxrpcMessageContext = epInv.get( javax.xml.rpc.handler.MessageContext.class );
-         jaxwsMessageContext = epInv.get( javax.xml.ws.handler.MessageContext.class );
-      }
-
-      public void attached(BeanContext beanCtx)
-      {
-         StatelessBeanContext sbc = (StatelessBeanContext)beanCtx;
-         sbc.setMessageContextJAXRPC(jaxrpcMessageContext);
-
-         BeanProperty beanProp = sbc.getWebServiceContextProperty();
-         if (beanProp != null)
-         {
-            EJBContext ejbCtx = beanCtx.getEJBContext();
-            SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
-            ExtensibleWebServiceContext wsContext = spiProvider.getSPI(WebServiceContextFactory.class).newWebServiceContext(InvocationType.JAXWS_EJB3, jaxwsMessageContext);
-            wsContext.addAttachment(EJBContext.class, ejbCtx);
-            beanProp.set(beanCtx.getInstance(), wsContext);
-         }
-      }
-
-      public void released(BeanContext beanCtx)
-      {
-         StatelessBeanContext sbc = (StatelessBeanContext)beanCtx;
-         sbc.setMessageContextJAXRPC(null);
-
-         BeanProperty beanProp = sbc.getWebServiceContextProperty();
-         if (beanProp != null)
-            beanProp.set(beanCtx.getInstance(), null);
-      }
+      String name = this.getObjectName() != null ? this.getObjectName().getCanonicalName() : null;
+      return name;
    }
 }

Added: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/WebServiceContextProxy.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/WebServiceContextProxy.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/WebServiceContextProxy.java	2008-05-05 11:27:08 UTC (rev 73059)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection;
+
+import org.w3c.dom.Element;
+
+import javax.xml.ws.EndpointReference;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.MessageContext;
+import java.security.Principal;
+
+/**
+ * WebServiceContext proxy that delegates to a ThreadLocal.
+ *
+ * @see org.jboss.ejb3.stateless.StatelessContainer
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class WebServiceContextProxy implements WebServiceContext
+{     
+   private static ThreadLocal<WebServiceContext> msgContextAssoc = new ThreadLocal<WebServiceContext>();
+
+   private static final WebServiceContext NOOP = new DefaultDelagate();
+
+   public static void associateMessageContext(WebServiceContext messageContext)
+   {
+      msgContextAssoc.set(messageContext);
+   }
+
+   public MessageContext getMessageContext()
+   {
+      return delegate().getMessageContext();
+   }
+
+   public Principal getUserPrincipal()
+   {
+      return delegate().getUserPrincipal();
+   }
+
+   public boolean isUserInRole(String string)
+   {
+      return delegate().isUserInRole(string);
+   }
+
+   public EndpointReference getEndpointReference(Element... elements)
+   {
+      return delegate().getEndpointReference(elements);
+   }
+
+   public <T extends EndpointReference> T getEndpointReference(Class<T> aClass, Element... elements)
+   {
+      return delegate().getEndpointReference(aClass, elements);
+   }
+
+   private WebServiceContext delegate()
+   {
+      return (msgContextAssoc.get() != null) ? msgContextAssoc.get() : NOOP;
+   }
+
+   private static final class DefaultDelagate implements WebServiceContext
+   {
+      private final RuntimeException EX = new WebServiceException("WebServiceContext not available");
+
+      public MessageContext getMessageContext()
+      {
+         throw EX;
+      }
+
+      public Principal getUserPrincipal()
+      {
+         throw EX;
+      }
+
+      public boolean isUserInRole(String string)
+      {
+         throw EX;
+      }
+
+      public EndpointReference getEndpointReference(Element... elements)
+      {
+         throw EX;
+      }
+
+      public <T extends EndpointReference> T getEndpointReference(Class<T> aClass, Element... elements)
+      {
+         throw EX;
+      }
+   }
+}


Property changes on: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/WebServiceContextProxy.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-cvs-commits mailing list