axis-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sag...@apache.org
Subject svn commit: r1377228 - in /axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2: classloader/ThreadContextDescriptor.java engine/DependencyManager.java receivers/AbstractMessageReceiver.java
Date Sat, 25 Aug 2012 07:24:04 GMT
Author: sagara
Date: Sat Aug 25 07:24:03 2012
New Revision: 1377228

URL: http://svn.apache.org/viewvc?rev=1377228&view=rev
Log:
Fixed AXIS2-5399. 

Added:
    axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/ThreadContextDescriptor.java
  (with props)
Modified:
    axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java
    axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java

Added: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/ThreadContextDescriptor.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/ThreadContextDescriptor.java?rev=1377228&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/ThreadContextDescriptor.java
(added)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/ThreadContextDescriptor.java
Sat Aug 25 07:24:03 2012
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.classloader;
+
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+
+public class ThreadContextDescriptor {
+
+    private ClassLoader oldClassLoader;
+    private MessageContext oldMessageContext;
+
+    public ClassLoader getOldClassLoader() {
+        return oldClassLoader;
+    }
+
+    public void setOldClassLoader(ClassLoader oldClassLoader) {
+        this.oldClassLoader = oldClassLoader;
+    }
+
+    public MessageContext getOldMessageContext() {
+        return oldMessageContext;
+    }
+
+    public void setOldMessageContext(MessageContext oldMessageContext) {
+        this.oldMessageContext = oldMessageContext;
+    }
+
+    public static ThreadContextDescriptor setThreadContext(final AxisService service) {
+        ThreadContextDescriptor tc = new ThreadContextDescriptor();
+        tc.oldMessageContext = (MessageContext) MessageContext.currentMessageContext.get();
+        final ClassLoader contextClassLoader = getContextClassLoader_doPriv();
+        tc.oldClassLoader = contextClassLoader;
+        String serviceTCCL = (String) service.getParameterValue(Constants.SERVICE_TCCL);
+        if (serviceTCCL != null) {
+            serviceTCCL = serviceTCCL.trim().toLowerCase();
+
+            if (serviceTCCL.equals(Constants.TCCL_COMPOSITE)) {
+                final ClassLoader loader = (ClassLoader) AccessController
+                        .doPrivileged(new PrivilegedAction() {
+                            public Object run() {
+                                return new MultiParentClassLoader(new URL[] {}, new ClassLoader[]
{
+                                        service.getClassLoader(), contextClassLoader });
+                            }
+                        });
+                org.apache.axis2.java.security.AccessController
+                        .doPrivileged(new PrivilegedAction() {
+                            public Object run() {
+                                Thread.currentThread().setContextClassLoader(loader);
+                                return null;
+                            }
+                        });
+            } else if (serviceTCCL.equals(Constants.TCCL_SERVICE)) {
+                org.apache.axis2.java.security.AccessController
+                        .doPrivileged(new PrivilegedAction() {
+                            public Object run() {
+                                Thread.currentThread().setContextClassLoader(
+                                        service.getClassLoader());
+                                return null;
+                            }
+                        });
+            }
+        }
+        return tc;
+    }
+
+    /**
+     * Several pieces of information need to be available to the service
+     * implementation class. For one, the ThreadContextClassLoader needs to be
+     * correct, and for another we need to give the service code access to the
+     * MessageContext (getCurrentContext()). So we toss these things in TLS.
+     * 
+     * @param msgContext
+     *            the current MessageContext
+     * @return a ThreadContextDescriptor containing the old values
+     */
+    public static ThreadContextDescriptor setThreadContext(final MessageContext msgContext)
{
+        AxisService service = msgContext.getAxisService();
+        ThreadContextDescriptor tc = setThreadContext(service);
+        MessageContext.setCurrentMessageContext(msgContext);
+        return tc;
+    }
+
+    private static ClassLoader getContextClassLoader_doPriv() {
+        return (ClassLoader) org.apache.axis2.java.security.AccessController
+                .doPrivileged(new PrivilegedAction() {
+                    public Object run() {
+                        return Thread.currentThread().getContextClassLoader();
+                    }
+                });
+    }
+
+}

Propchange: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/ThreadContextDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java?rev=1377228&r1=1377227&r2=1377228&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java
(original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java
Sat Aug 25 07:24:03 2012
@@ -22,6 +22,8 @@ package org.apache.axis2.engine;
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.classloader.ThreadContextDescriptor;
+import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.ServiceContext;
 import org.apache.axis2.context.ServiceGroupContext;
 import org.apache.axis2.description.AxisService;
@@ -34,6 +36,7 @@ import org.apache.commons.logging.LogFac
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
 import java.util.Iterator;
 
 /**
@@ -64,7 +67,7 @@ public class DependencyManager {
         // ...however, we also still support the old way for now.  Note that introspecting
for
         // a method like this is something like 10 times slower than the above instanceof
check.
 
-        Class classToLoad = obj.getClass();
+        Class<?> classToLoad = obj.getClass();
         // We can not call classToLoad.getDeclaredMethed() , since there
         //  can be insatnce where mutiple services extends using one class
         // just for init and other reflection methods
@@ -109,12 +112,14 @@ public class DependencyManager {
             Parameter implInfoParam = service.getParameter(Constants.SERVICE_CLASS);
             if (implInfoParam != null) {
                 try {
-                    Class implClass = Loader.loadClass(
+                    ThreadContextDescriptor tc = ThreadContextDescriptor.setThreadContext(axisService);
+                    Class<?> implClass = Loader.loadClass(
                             classLoader,
                             ((String) implInfoParam.getValue()).trim());
                     Object serviceImpl = implClass.newInstance();
                     serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, serviceImpl);
                     initServiceObject(serviceImpl, serviceContext);
+                    restoreThreadContext(tc);
                 } catch (Exception e) {
                     throw AxisFault.makeFault(e);
                 }
@@ -137,7 +142,7 @@ public class DependencyManager {
 
             // For now, we also use "raw" introspection to try and find the destroy method.
 
-            Class classToLoad = obj.getClass();
+            Class<?> classToLoad = obj.getClass();
             Method method =
                     null;
             try {
@@ -160,4 +165,14 @@ public class DependencyManager {
 
         }
     }
+
+    protected static void restoreThreadContext(final ThreadContextDescriptor tc) {
+        org.apache.axis2.java.security.AccessController.doPrivileged(new PrivilegedAction()
{
+            public Object run() {
+                Thread.currentThread().setContextClassLoader(tc.getOldClassLoader());
+                return null;
+            }
+        });
+        MessageContext.currentMessageContext.set(tc.getOldMessageContext());
+    }
 }

Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java?rev=1377228&r1=1377227&r2=1377228&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java
(original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java
Sat Aug 25 07:24:03 2012
@@ -27,12 +27,11 @@ import org.apache.axiom.soap.SOAPFactory
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.classloader.MultiParentClassLoader;
+import org.apache.axis2.classloader.ThreadContextDescriptor;
 import org.apache.axis2.clustering.ClusteringFault;
 import org.apache.axis2.clustering.state.Replicator;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.ServiceContext;
-import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.InOnlyAxisOperation;
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.engine.AxisEngine;
@@ -46,8 +45,6 @@ import org.apache.axis2.wsdl.WSDLUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.net.URL;
-import java.security.AccessController;
 import java.security.PrivilegedAction;
 
 public abstract class AbstractMessageReceiver implements MessageReceiver {
@@ -58,12 +55,7 @@ public abstract class AbstractMessageRec
     public static final String SAVED_TCCL = "_SAVED_TCCL_";
     public static final String SAVED_MC = "_SAVED_MC_";
     public static final String DO_ASYNC = "messageReceiver.invokeOnSeparateThread";
-
-    // Place to store previous values
-    public static class ThreadContextDescriptor {
-        public ClassLoader oldClassLoader;
-        public MessageContext oldMessageContext;
-    }
+    
 
     protected void replicateState(MessageContext messageContext) throws ClusteringFault {
         Replicator.replicate(messageContext);
@@ -109,7 +101,7 @@ public abstract class AbstractMessageRec
 
         }
 
-        ThreadContextDescriptor tc = setThreadContext(messageCtx);
+        ThreadContextDescriptor tc = ThreadContextDescriptor.setThreadContext(messageCtx);
         try {
             invokeBusinessLogic(messageCtx);
         } catch (AxisFault fault) {
@@ -154,83 +146,19 @@ public abstract class AbstractMessageRec
                 worker);
     }
 
-    /**
-     * Several pieces of information need to be available to the service
-     * implementation class.  For one, the ThreadContextClassLoader needs
-     * to be correct, and for another we need to give the service code
-     * access to the MessageContext (getCurrentContext()).  So we toss these
-     * things in TLS.
-     *
-     * @param msgContext the current MessageContext
-     * @return a ThreadContextDescriptor containing the old values
-     */
-    protected ThreadContextDescriptor setThreadContext(final MessageContext msgContext) {
-        ThreadContextDescriptor tc = new ThreadContextDescriptor();
-        tc.oldMessageContext = (MessageContext) MessageContext.currentMessageContext.get();
-        final ClassLoader contextClassLoader = getContextClassLoader_doPriv();
-        tc.oldClassLoader = contextClassLoader;
-
-        AxisService service = msgContext.getAxisService();
-        String serviceTCCL = (String) service.getParameterValue(Constants.SERVICE_TCCL);
-        if (serviceTCCL != null) {
-            serviceTCCL = serviceTCCL.trim().toLowerCase();
-
-            if (serviceTCCL.equals(Constants.TCCL_COMPOSITE)) {
-                final ClassLoader loader = (ClassLoader) AccessController.doPrivileged(new
PrivilegedAction() {
-                    public Object run() {
-                        return new MultiParentClassLoader(new URL[]{},
-                                new ClassLoader[]{
-                                        msgContext.getAxisService().getClassLoader(),
-                                        contextClassLoader
-                                });
-                    }
-                });
-                org.apache.axis2.java.security.AccessController.doPrivileged(
-                        new PrivilegedAction() {
-                            public Object run() {
-                                Thread.currentThread().setContextClassLoader(
-                                        loader);
-                                return null;
-                            }
-                        }
-                );
-            } else if (serviceTCCL.equals(Constants.TCCL_SERVICE)) {
-                org.apache.axis2.java.security.AccessController.doPrivileged(
-                        new PrivilegedAction() {
-                            public Object run() {
-                                Thread.currentThread().setContextClassLoader(
-                                        msgContext.getAxisService().getClassLoader()
-                                );
-                                return null;
-                            }
-                        }
-                );
-            }
-        }
-        MessageContext.setCurrentMessageContext(msgContext);
-        return tc;
-    }
-
-    private ClassLoader getContextClassLoader_doPriv() {
-        return (ClassLoader) org.apache.axis2.java.security.AccessController.doPrivileged(
-                new PrivilegedAction() {
-                    public Object run() {
-                        return Thread.currentThread().getContextClassLoader();
-                    }
-                }
-        );
-    }
+    
 
+   
     protected void restoreThreadContext(final ThreadContextDescriptor tc) {
         org.apache.axis2.java.security.AccessController.doPrivileged(
                 new PrivilegedAction() {
                     public Object run() {
-                        Thread.currentThread().setContextClassLoader(tc.oldClassLoader);
+                        Thread.currentThread().setContextClassLoader(tc.getOldClassLoader());
                         return null;
                     }
                 }
         );
-        MessageContext.currentMessageContext.set(tc.oldMessageContext);
+        MessageContext.currentMessageContext.set(tc.getOldMessageContext());
     }
 
     /**
@@ -296,7 +224,7 @@ public abstract class AbstractMessageRec
 
         public void run() {
             try {
-                ThreadContextDescriptor tc = setThreadContext(messageCtx);
+                ThreadContextDescriptor tc = ThreadContextDescriptor.setThreadContext(messageCtx);
                 try {
                     invokeBusinessLogic(messageCtx);
                 } finally {



Mime
View raw message