axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From barre...@apache.org
Subject svn commit: r818124 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/server/dispatcher/ test/org/apache/axis2/jaxws/server/dispatcher/
Date Wed, 23 Sep 2009 14:46:15 GMT
Author: barrettj
Date: Wed Sep 23 14:46:15 2009
New Revision: 818124

URL: http://svn.apache.org/viewvc?rev=818124&view=rev
Log:
Log the context classloader before and after invoking the JAXWS endpoint.  This helps identify
issues where the classloader may be changed during invocation.  That is important because
JAXB contexts are based on the classloader, and if the classloader is changed that could cause
problems related to not being able to find the correct JAXB Context to marshall responses.
 Add associated test for the log message.

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/dispatcher/
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcherLoggingTest.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java?rev=818124&r1=818123&r2=818124&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
Wed Sep 23 14:46:15 2009
@@ -38,6 +38,8 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.List;
 import java.util.concurrent.Callable;
 /**
@@ -74,7 +76,14 @@
     protected Object invokeTargetOperation(Method method, Object[] args) throws Throwable
{
         Object output = null;
         try {
+            if (log.isDebugEnabled()) {
+                log.debug(logContextClassLoader("Before invocation"));
+            }
             output = method.invoke(serviceInstance, args);
+            
+            if (log.isDebugEnabled()) {
+                log.debug(logContextClassLoader("After invocation"));
+            }
         } catch (Throwable t) {
             
             // Delegate logging the exception to the WebServiceExceptionLogger.
@@ -88,6 +97,9 @@
                                           serviceInstance,
                                           args);
                                                          
+            if (log.isDebugEnabled()) {
+                logContextClassLoader("After invocation caught exception " + t.toString());
+            }
             throw t;
         }
         
@@ -95,6 +107,57 @@
     }
     
     
+    /**
+     * Return a string with the current context class loader on the thread.  The string is
intended
+     * to be used in debug logging statements.
+     * @param logString appended to the string to be returned
+     * @return a string to be logged into debug logging trace.
+     */
+    String logContextClassLoader(String appendString) {
+        String logMessage = null;
+        try {
+            logMessage = "Current ThreadContextClassLoader";
+            if (appendString != null) {
+                logMessage += ": " + appendString;
+            }
+            logMessage += ": " + getCurrentContextClassLoader();
+        } catch (Throwable t) {
+            // We don't want any exceptions in logging to cause trouble for the application
+            logMessage = "Unable to log current thread context classloader due to Throwable:
" + t.toString();
+        }
+        return logMessage;
+    }
+    
+    /**
+     * @return ClassLoader
+     */
+    private static ClassLoader getCurrentContextClassLoader() {
+        // NOTE: This method must remain private because it uses AccessController
+        ClassLoader cl = null;
+        try {
+            cl = (ClassLoader) org.apache.axis2.java.security.AccessController.doPrivileged(new
PrivilegedExceptionAction() {
+                public Object run() throws ClassNotFoundException {
+                    return Thread.currentThread().getContextClassLoader();
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            // The privileged method will throw a PriviledgedActionException which
+            // contains the actual exception.
+            if (log.isDebugEnabled()) {
+                log.debug("Exception thrown from AccessController: " + e);
+            }
+            Exception wrappedE = e.getException();
+            if (wrappedE instanceof RuntimeException) {
+                throw (RuntimeException) wrappedE;
+            } else {
+                throw new RuntimeException(wrappedE);
+            }
+        }
+        
+        return cl;
+    }
+
+
     protected class AsyncInvocationWorker implements Callable {
         
         private Method method;

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcherLoggingTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcherLoggingTest.java?rev=818124&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcherLoggingTest.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcherLoggingTest.java
Wed Sep 23 14:46:15 2009
@@ -0,0 +1,74 @@
+/*
+ * 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.jaxws.server.dispatcher;
+
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.server.EndpointCallback;
+
+import junit.framework.TestCase;
+
+/**
+ * Verify logging in the JavaDispatcher.  This does not verify any of the 
+ * dispatching logic.
+ */
+public class JavaDispatcherLoggingTest extends TestCase {
+
+    /**
+     * Verify the logging of the context classloader before and after invocation
+     */
+    public void testLogContextClassloader() {
+        TestDispatcherLogging testDispatcher = new TestDispatcherLogging(null, null);
+        assertTrue(testDispatcher.logContextClassLoader("Before").startsWith("Current ThreadContextClassLoader:
Before: "));
+        assertTrue(testDispatcher.logContextClassLoader(null).startsWith("Current ThreadContextClassLoader:
"));
+    }
+
+}
+
+class TestDispatcherLogging extends JavaDispatcher {
+    TestDispatcherLogging(Class impl, Object serviceInstance) {
+        super(impl, serviceInstance);
+    }
+    @Override
+    protected MessageContext createFaultResponse(MessageContext request,
+            Throwable fault) {
+        return null;
+    }
+
+    @Override
+    protected MessageContext createResponse(MessageContext request,
+            Object[] input, Object output) {
+        return null;
+    }
+
+    @Override
+    public MessageContext invoke(MessageContext request) throws Exception {
+        return null;
+    }
+
+    @Override
+    public void invokeAsync(MessageContext request, EndpointCallback callback) {
+        
+    }
+
+    @Override
+    public void invokeOneWay(MessageContext request) {
+        
+    }
+    
+}



Mime
View raw message