[jboss-cvs] JBossAS SVN: r110487 - branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 28 07:44:31 EST 2011


Author: richard.opalka at jboss.com
Date: 2011-01-28 07:44:30 -0500 (Fri, 28 Jan 2011)
New Revision: 110487

Added:
   branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation/ThreadLocalAwareWebServiceContext.java
Modified:
   branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java
Log:
[JBPAPP-5052] backporting ThreadLocal aware WebServiceContext injection implementation

Modified: branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java
===================================================================
--- branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java	2011-01-28 10:55:48 UTC (rev 110486)
+++ branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java	2011-01-28 12:44:30 UTC (rev 110487)
@@ -53,12 +53,9 @@
 {
    private static final String POJO_JNDI_PREFIX = "java:comp/env/";
    private SPIProvider spiProvider;
-   private ResourceInjectorFactory resourceInjectorFactory;
 
    public InvocationHandlerJSE()
    {
-      spiProvider = SPIProviderResolver.getInstance().getProvider();
-      resourceInjectorFactory = spiProvider.getSPI(ResourceInjectorFactory.class);
    }
 
    public Invocation createInvocation()
@@ -87,6 +84,10 @@
             throw new IllegalStateException("Cannot get target bean instance", ex);
          }
 
+         SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+         ResourceInjectorFactory resourceInjectorFactory = spiProvider.getSPI(ResourceInjectorFactory.class);
+         ResourceInjector wsContextInjector = resourceInjectorFactory.newResourceInjector();
+         wsContextInjector.inject(targetBean, ThreadLocalAwareWebServiceContext.getInstance());
          InjectionsMetaData injectionsMD = ep.getAttachment(InjectionsMetaData.class);
          if (injectionsMD != null)
             InjectionHelper.injectResources(targetBean, injectionsMD, ep.getJNDIContext());
@@ -110,11 +111,7 @@
 
          InvocationContext invContext = epInv.getInvocationContext();
          WebServiceContext wsContext = invContext.getAttachment(WebServiceContext.class);
-         if (wsContext != null)
-         {
-            ResourceInjector injector = resourceInjectorFactory.newResourceInjector();
-            injector.inject(targetBean, wsContext);
-         }
+         ThreadLocalAwareWebServiceContext.getInstance().setMessageContext(wsContext);
 
          Method method = getImplMethod(targetBean.getClass(), epInv.getJavaMethod());
          Object retObj = method.invoke(targetBean, epInv.getArgs());
@@ -124,6 +121,10 @@
       {
          handleInvocationException(e);
       }
+      finally
+      {
+         ThreadLocalAwareWebServiceContext.getInstance().setMessageContext(null);
+      }
    }
 
    protected Method getImplMethod(Class<?> implClass, Method seiMethod) throws ClassNotFoundException, NoSuchMethodException

Added: branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation/ThreadLocalAwareWebServiceContext.java
===================================================================
--- branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation/ThreadLocalAwareWebServiceContext.java	                        (rev 0)
+++ branches/JBPAPP_5_1/webservices/src/main/org/jboss/wsf/container/jboss50/invocation/ThreadLocalAwareWebServiceContext.java	2011-01-28 12:44:30 UTC (rev 110487)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.wsf.container.jboss50.invocation;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+import javax.xml.ws.EndpointReference;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.w3c.dom.Element;
+
+/**
+ * Web service context implementation that is thread local aware as required by JAX-WS spec.
+ *
+ * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
+ */
+public final class ThreadLocalAwareWebServiceContext implements WebServiceContext, Serializable
+{
+
+   private static final long serialVersionUID = 126557512266764152L;
+
+   private static final transient ThreadLocalAwareWebServiceContext SINGLETON = new ThreadLocalAwareWebServiceContext();
+
+   private final transient ThreadLocal<WebServiceContext> contexts = new InheritableThreadLocal<WebServiceContext>();
+
+   public static ThreadLocalAwareWebServiceContext getInstance()
+   {
+      return SINGLETON;
+   }
+
+   public void setMessageContext(final WebServiceContext ctx)
+   {
+      this.contexts.set(ctx);
+   }
+
+   public EndpointReference getEndpointReference(final Element... referenceParameters)
+   {
+      final WebServiceContext delegee = this.contexts.get();
+
+      if (delegee == null)
+      {
+         throw new IllegalStateException();
+      }
+
+      return delegee.getEndpointReference(referenceParameters);
+   }
+
+   public <T extends EndpointReference> T getEndpointReference(final Class<T> clazz,
+         final Element... referenceParameters)
+   {
+      final WebServiceContext delegee = this.contexts.get();
+
+      if (delegee == null)
+      {
+         throw new IllegalStateException();
+      }
+
+      return delegee.getEndpointReference(clazz, referenceParameters);
+   }
+
+   public MessageContext getMessageContext()
+   {
+      final WebServiceContext delegee = this.contexts.get();
+
+      if (delegee == null)
+      {
+         throw new IllegalStateException();
+      }
+
+      return delegee.getMessageContext();
+   }
+
+   public Principal getUserPrincipal()
+   {
+      final WebServiceContext delegee = this.contexts.get();
+
+      if (delegee == null)
+      {
+         throw new IllegalStateException();
+      }
+
+      return delegee.getUserPrincipal();
+   }
+
+   public boolean isUserInRole(String role)
+   {
+      final WebServiceContext delegee = this.contexts.get();
+
+      if (delegee == null)
+      {
+         throw new IllegalStateException();
+      }
+
+      return delegee.isUserInRole(role);
+   }
+
+}



More information about the jboss-cvs-commits mailing list