You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2011/05/27 10:56:31 UTC

svn commit: r1128202 - in /cxf/trunk/rt/frontend/jaxws/src: main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java main/java/org/apache/cxf/jaxws/support/Messages.properties test/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfoTest.java

Author: ningjiang
Date: Fri May 27 08:56:31 2011
New Revision: 1128202

URL: http://svn.apache.org/viewvc?rev=1128202&view=rev
Log:
CXF-3551 Log warning message when cxf find the @WebServices which is loaded by the other classloader

Modified:
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfoTest.java

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java?rev=1128202&r1=1128201&r2=1128202&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfo.java Fri May 27 08:56:31 2011
@@ -19,11 +19,13 @@
 
 package org.apache.cxf.jaxws.support;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.ResourceBundle;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.jws.WebService;
@@ -253,6 +255,18 @@ public class JaxWsImplementorInfo {
         }
         return null;
     }
+    
+    protected static boolean ifAnnotationLoadedByOtherClassLoader(Class<?> cls,
+        Class<? extends Annotation> annotationClass) {
+        for (Annotation an : cls.getAnnotations()) {
+            if (an.annotationType() != null 
+                && annotationClass.getName().equals(an.annotationType().getName())) {
+                return true;
+            }
+        }
+        return false;
+        
+    }
     private void initialize() {
         Class<?> cls = implementorClass;
         while (cls != null) {
@@ -262,6 +276,13 @@ public class JaxWsImplementorInfo {
                 if (cls.isInterface()) {
                     cls = null;
                 }
+            } else {
+                // check if there are annotations has the same name with WebServices
+                if (ifAnnotationLoadedByOtherClassLoader(cls, WebService.class)) {
+                    LOG.log(Level.WARNING,
+                            "WEBSERVICE_ANNOTATIONS_IS_LOADED_BY_OTHER_CLASSLOADER",
+                            WebService.class.getName());
+                }
             }
             if (cls != null) {
                 cls = cls.getSuperclass();                
@@ -312,10 +333,22 @@ public class JaxWsImplementorInfo {
         WebServiceProvider ann = cls.getAnnotation(WebServiceProvider.class);
         if (null != ann) {
             return ann;
+        } else {
+            if (ifAnnotationLoadedByOtherClassLoader(cls, WebServiceProvider.class)) {
+                LOG.log(Level.WARNING, 
+                    "WEBSERVICE_ANNOTATIONS_IS_LOADED_BY_OTHER_CLASSLOADER",
+                    WebServiceProvider.class.getName());
+            }
         }
         for (Class<?> inf : cls.getInterfaces()) {
             if (null != inf.getAnnotation(WebServiceProvider.class)) {
                 return inf.getAnnotation(WebServiceProvider.class);
+            } else {
+                if (ifAnnotationLoadedByOtherClassLoader(cls, WebServiceProvider.class)) {
+                    LOG.log(Level.WARNING, 
+                            "WEBSERVICE_ANNOTATIONS_IS_LOADED_BY_OTHER_CLASSLOADER",
+                            WebServiceProvider.class.getName());
+                }
             }
         }
         return getWebServiceProviderAnnotation(cls.getSuperclass());

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties?rev=1128202&r1=1128201&r2=1128202&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties Fri May 27 08:56:31 2011
@@ -32,3 +32,4 @@ INVALID_RESPONSE_WRAPPER = @ResponseWrap
 SERVICECLASS_MUST_BE_SET = serviceClass must be set to a valid service interface or class
 XMLSEEALSO_NULL_CLASS = A class listed in the XmlSeeAlso annotation of the service class %s cannot be found on the classpath. Index: %d of XmlSeeAlso class list.
 WEBMETHOD_EXCLUDE_NOT_ALLOWED = The @javax.jws.WebMethod(exclude=true) cannot be used on a service endpoint interface. Method: {0}
+WEBSERVICE_ANNOTATIONS_IS_LOADED_BY_OTHER_CLASSLOADER = The @{} is loaded by other classloader. Please check if there are multi version of jws jar in your class path.
\ No newline at end of file

Modified: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfoTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfoTest.java?rev=1128202&r1=1128201&r2=1128202&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfoTest.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfoTest.java Fri May 27 08:56:31 2011
@@ -19,7 +19,11 @@
 
 package org.apache.cxf.jaxws.support;
 
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceProvider;
+
 import org.apache.cxf.calculator.CalculatorImpl;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -30,4 +34,13 @@ public class JaxWsImplementorInfoTest ex
         JaxWsImplementorInfo info = new JaxWsImplementorInfo(CalculatorImpl.class);
         assertEquals("testutils/calculator.wsdl", info.getWsdlLocation());
     }
+    
+    @Test
+    public void testWebServiceAnnotation() throws Exception {
+        assertTrue(JaxWsImplementorInfo.
+                   ifAnnotationLoadedByOtherClassLoader(CalculatorImpl.class, WebService.class));
+        assertFalse(JaxWsImplementorInfo.
+                    ifAnnotationLoadedByOtherClassLoader(CalculatorImpl.class, WebServiceProvider.class));
+        
+    }
 }