You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2009/06/18 15:15:52 UTC

svn commit: r786049 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: ./ runtime/description/marshal/impl/

Author: scheu
Date: Thu Jun 18 13:15:51 2009
New Revision: 786049

URL: http://svn.apache.org/viewvc?rev=786049&view=rev
Log:
JIRA:AXIS2-4396
Contributor:Rich Scheuerle
Summary:
Corrected the code that examines the @XmlSeeAlso annotations on the endpoint interface.
Now the endpoint interace will be correctly loaded from the impl's @WebService endpointInterface parameter.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/WebServiceExceptionLogger.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionBuilder.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/WebServiceExceptionLogger.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/WebServiceExceptionLogger.java?rev=786049&r1=786048&r2=786049&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/WebServiceExceptionLogger.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/WebServiceExceptionLogger.java Thu Jun 18 13:15:51 2009
@@ -98,6 +98,16 @@
                 log.debug("The exception is an instance of checked exception: " + 
                           checkedException.getName());
             }
+            
+            // Extra trace if ElementNSImpl incompatibility problem.
+            // The incompatibility exception occurs if the JAXB Unmarshaller 
+            // unmarshals to a dom element instead of a generated object.  This can 
+            // result in class cast exceptions.  The solution is usually a missing
+            // @XmlSeeAlso annotation in the jaxws or jaxb classes. 
+            if (rootT.toString().contains("org.apache.xerces.dom.ElementNSImpl incompatible")) {
+            	log.debug("This exception may be due to a missing @XmlSeeAlso in the client's jaxws or" +
+            			" jaxb classes.");
+            }
             log.debug("Method = " + method.toGenericString());
             for (int i = 0; i < args.length; i++) {
                 String value =

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionBuilder.java?rev=786049&r1=786048&r2=786049&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionBuilder.java Thu Jun 18 13:15:51 2009
@@ -63,7 +63,14 @@
      */
     static private void init(MarshalServiceRuntimeDescriptionImpl marshalDesc,
                              ServiceDescription serviceDesc) {
+    	
+    	if (log.isDebugEnabled()) {
+    		log.debug("start init");
+    	}
 
+    	if (log.isDebugEnabled()) {
+    		log.debug("Discover the artifacts");
+    	}
         // Artifact class discovery/builder
         ArtifactProcessor artifactProcessor = new ArtifactProcessor(serviceDesc);
         try {
@@ -75,6 +82,9 @@
         marshalDesc.setResponseWrapperMap(artifactProcessor.getResponseWrapperMap());
         marshalDesc.setFaultBeanDescMap(artifactProcessor.getFaultBeanDescMap());
 
+        if (log.isDebugEnabled()) {
+    		log.debug("Build the annotations map");
+    	}
         // Build the annotation map
         Map<String, AnnotationDesc> map;
         try {
@@ -90,6 +100,10 @@
         }
         marshalDesc.setAnnotationMap(map);
 
+       
+        if (log.isDebugEnabled()) {
+    		log.debug("Build the property descriptor cache");
+    	}
         // Build the property descriptor map
         Map<Class, Map<String, PropertyDescriptorPlus>> cache;
         try {
@@ -118,12 +132,23 @@
         boolean doAnnotationWalk = true;
         packages = new TreeSet<String>();
         if (doSchemaWalk) {
+        	if (log.isDebugEnabled()) {
+        		log.debug("Get the packages using the schema");
+        	}
             packages.addAll(PackageSetBuilder.getPackagesFromSchema(serviceDesc));
         }
         if (doAnnotationWalk) {
             // Get the package names from the annotations.  Use the annotation map to reduce Annotation introspection
+        	if (log.isDebugEnabled()) {
+        		log.debug("Get the packages using the class annotations");
+        	}
             packages.addAll(PackageSetBuilder.getPackagesFromAnnotations(serviceDesc, marshalDesc));
         }
         marshalDesc.setPackages(packages);
+        
+        if (log.isDebugEnabled()) {
+        	log.debug("MarshalDesc = " + marshalDesc);
+    		log.debug("end init");
+    	}
     }
 }
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java?rev=786049&r1=786048&r2=786049&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/MarshalServiceRuntimeDescriptionImpl.java Thu Jun 18 13:15:51 2009
@@ -146,60 +146,67 @@
     }
 
     public String toString() {
-        final String newline = "\n";
-        final String sameline = " ";
-        StringBuffer string = new StringBuffer();
-
-        string.append(newline);
-        string.append("  MarshalServiceRuntime:" + getKey());
-        string.append(newline);
-        string.append("    Packages = " + getPackages().toString());
+        try {
+            final String newline = "\n";
+            final String sameline = " ";
+            StringBuffer string = new StringBuffer();
 
-        for (Entry<String, AnnotationDesc> entry : this.annotationMap.entrySet()) {
             string.append(newline);
-            string.append("    AnnotationDesc cached for:" + entry.getKey());
-            string.append(entry.getValue().toString());
-        }
-
-        for (Entry<Class, Map<String, PropertyDescriptorPlus>> entry : this.pdMapCache.entrySet()) {
+            string.append("  MarshalServiceRuntime:" + getKey());
             string.append(newline);
-            string.append("    PropertyDescriptorPlus Map cached for:" +
-                    entry.getKey().getCanonicalName());
-            for (PropertyDescriptorPlus pdp : entry.getValue().values()) {
+            String pkgs = (getPackages() == null) ? "none" : getPackages().toString();
+            string.append("    Packages = " + pkgs);
+
+            for (Entry<String, AnnotationDesc> entry : this.annotationMap.entrySet()) {
                 string.append(newline);
-                string.append("      propertyName   =" + pdp.getPropertyName());
+                string.append("    AnnotationDesc cached for:" + entry.getKey());
+                string.append(entry.getValue().toString());
+            }
+
+            for (Entry<Class, Map<String, PropertyDescriptorPlus>> entry : this.pdMapCache.entrySet()) {
                 string.append(newline);
-                string.append("        xmlName      =" + pdp.getXmlName());
+                string.append("    PropertyDescriptorPlus Map cached for:" +
+                        entry.getKey().getCanonicalName());
+                for (PropertyDescriptorPlus pdp : entry.getValue().values()) {
+                    string.append(newline);
+                    string.append("      propertyName   =" + pdp.getPropertyName());
+                    string.append(newline);
+                    string.append("        xmlName      =" + pdp.getXmlName());
+                    string.append(newline);
+                    string.append("        propertyType =" + pdp.getPropertyType().getCanonicalName());
+                    string.append(newline);
+                }
+            }
+
+            string.append("    RequestWrappers");
+            for (Entry<OperationDescription, String> entry : this.requestWrapperMap.entrySet()) {
                 string.append(newline);
-                string.append("        propertyType =" + pdp.getPropertyType().getCanonicalName());
+                string.append("    Operation:" + entry.getKey().getJavaMethodName() +
+                        " RequestWrapper:" + entry.getValue());
+            }
+
+            string.append("    ResponseWrappers");
+            for (Entry<OperationDescription, String> entry : this.responseWrapperMap.entrySet()) {
                 string.append(newline);
+                string.append("    Operation:" + entry.getKey().getJavaMethodName() +
+                        " ResponseWrapper:" + entry.getValue());
             }
-        }
 
-        string.append("    RequestWrappers");
-        for (Entry<OperationDescription, String> entry : this.requestWrapperMap.entrySet()) {
-            string.append(newline);
-            string.append("    Operation:" + entry.getKey().getJavaMethodName() +
-                    " RequestWrapper:" + entry.getValue());
-        }
+            string.append("    FaultBeanDesc");
+            for (Entry<FaultDescription, FaultBeanDesc> entry : this.faultBeanDescMap.entrySet()) {
+                string.append(newline);
+                string.append("    FaultException:" + entry.getKey().getExceptionClassName());
+                string.append(newline);
+                string.append(entry.getValue().toString());
+            }
 
-        string.append("    ResponseWrappers");
-        for (Entry<OperationDescription, String> entry : this.responseWrapperMap.entrySet()) {
-            string.append(newline);
-            string.append("    Operation:" + entry.getKey().getJavaMethodName() +
-                    " ResponseWrapper:" + entry.getValue());
-        }
 
-        string.append("    FaultBeanDesc");
-        for (Entry<FaultDescription, FaultBeanDesc> entry : this.faultBeanDescMap.entrySet()) {
-            string.append(newline);
-            string.append("    FaultException:" + entry.getKey().getExceptionClassName());
-            string.append(newline);
-            string.append(entry.getValue().toString());
+            return string.toString();
+        } catch (Throwable t) {
+            // A problem occurred while dumping the contents.
+            // This should not be re-thrown.
+            return "An error occured while dumping the debug contents of MarshalServiceRuntimeDescriptionImpl:" + t.toString();
         }
-
-
-        return string.toString();
     }
 
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java?rev=786049&r1=786048&r2=786049&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java Thu Jun 18 13:15:51 2009
@@ -44,14 +44,18 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.jws.WebService;
 import javax.wsdl.Definition;
 import javax.wsdl.WSDLException;
 import javax.xml.bind.JAXBElement;
 import java.io.File;
 import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.Collection;
@@ -94,6 +98,11 @@
      * @return Set of Packages
      */
     public static TreeSet<String> getPackagesFromSchema(ServiceDescription serviceDesc) {
+    	
+    	if (log.isDebugEnabled()) {
+    		log.debug("start getPackagesFromSchema");
+    		log.debug("ServiceDescription = " + serviceDesc.toString());
+    	}
 
         TreeSet<String> set = new TreeSet<String>();
         //If we are on client side we will get wsdl definition from ServiceDescription. If we are on server side we will have to
@@ -127,6 +136,9 @@
                 }
             }
         }
+        if (log.isDebugEnabled()) {
+        	log.debug("end getPackagesFromSchema");
+        }
         return set;
     }
 
@@ -136,6 +148,11 @@
      */
     public static TreeSet<String> getPackagesFromAnnotations(ServiceDescription serviceDesc,
                                                              MarshalServiceRuntimeDescription msrd) {
+    	if (log.isDebugEnabled()) {
+    		log.debug("start getPackagesFromAnnotations");
+    		log.debug("ServiceDescription = " + serviceDesc.toString());
+    		log.debug("MarshalServiceRuntimeDescription = " + msrd.toString());
+    	}
         TreeSet<String> set = new TreeSet<String>();
         Collection<EndpointDescription> endpointDescs = serviceDesc.getEndpointDescriptions_AsCollection();
         
@@ -145,6 +162,9 @@
                 set.addAll(getPackagesFromAnnotations(endpointDesc, msrd));
             }
         }
+        if (log.isDebugEnabled()) {
+        	log.debug("end getPackagesFromAnnotations");
+        }
         return set;
     }
 
@@ -154,10 +174,15 @@
      */
     private static TreeSet<String> getPackagesFromAnnotations(EndpointDescription endpointDesc,
                                                               MarshalServiceRuntimeDescription msrd) {
-        
+    	if (log.isDebugEnabled()) {
+    		log.debug("start getPackagesFromAnnotations for EndpointDescription " + endpointDesc.getName());
+    	}
         TreeSet<String> set = new TreeSet<String>();
         String implClassName = getServiceImplClassName(endpointDesc);
         if (implClassName != null) {
+        	if (log.isDebugEnabled()) {
+        		log.debug("EndpointDescription implClassName = " + implClassName);
+        	}
             Class clz = loadClass(implClassName);
             if(clz == null){
                 clz = loadClass(implClassName, endpointDesc.getAxisService().getClassLoader());
@@ -171,6 +196,9 @@
         if (endpointInterfaceDesc != null) {
             getPackagesFromAnnotations(endpointDesc, endpointInterfaceDesc, set, msrd);
         }
+        if (log.isDebugEnabled()) {
+    		log.debug("end getPackagesFromAnnotations for EndpointDescription " + endpointDesc.getName());
+    	}
         return set;
     }
 
@@ -185,10 +213,47 @@
             TreeSet<String> set,
             MarshalServiceRuntimeDescription msrd) {
         
+    	if (log.isDebugEnabled()) {
+    		log.debug("start getPackagesFromAnnotations for EndpointInterfaceDescription " + 
+    					endpointInterfaceDesc.getPortType());
+    	}
         OperationDescription[] opDescs = endpointInterfaceDesc.getDispatchableOperations();
 
-        // Inspect the @XmlSeeAlso classes on the interface
-        addXmlSeeAlsoPackages(endpointInterfaceDesc.getSEIClass(), msrd, set);
+        // Inspect the @XmlSeeAlso classes on the interface.
+        // A) The SEI class is accessible via the getSEIClass method -OR-
+        // B) The endpoint directly implements the sei class
+        //    (The @XmlSeeAlso annotations were picked up when the endpoint is examined) -OR-
+        // C) Find the SEI class using the @WebService annotation
+        Class seicls = endpointInterfaceDesc.getSEIClass();
+        if (log.isDebugEnabled()) {
+        	log.debug("SEI Class is " + seicls);
+        }
+        if (seicls == null) {
+        	String implClassName = getServiceImplClassName(ed);
+            if (implClassName != null) {
+            	if (log.isDebugEnabled()) {
+            		log.debug("EndpointDescription implClassName = " + implClassName);
+            	}
+                Class clz = loadClass(implClassName);
+                if(clz == null){
+                    clz = loadClass(implClassName, ed.getAxisService().getClassLoader());
+                }
+                if (clz != null) {
+                	WebService ws = (WebService) getAnnotation(clz, WebService.class);
+                	if (ws != null) {
+                		String intClassName = ws.endpointInterface();
+                		if (log.isDebugEnabled()) {
+                    		log.debug("WebService endpointinterface = " + intClassName);
+                    	}
+                        seicls = loadClass(intClassName);
+                        if (seicls== null){
+                            seicls = loadClass(intClassName, ed.getAxisService().getClassLoader());
+                        }
+                	}
+                }
+            }
+        }
+        addXmlSeeAlsoPackages(seicls, msrd, set);
         
         
         // Build a set of packages from all of the operations
@@ -197,6 +262,10 @@
                 getPackagesFromAnnotations(ed, opDescs[i], set, msrd);
             }
         }
+        if (log.isDebugEnabled()) {
+    		log.debug("end getPackagesFromAnnotations for EndpointInterfaceDescription " + 
+    					endpointInterfaceDesc.getPortType());
+    	}
         return;
     }
 
@@ -434,6 +503,9 @@
     private static void addXmlSeeAlsoPackages(Class clz, 
                                               MarshalServiceRuntimeDescription msrd, 
                                               TreeSet<String> set) {
+    	if (log.isDebugEnabled()) {
+    		log.debug("start addXmlSeeAlsoPackages for " + clz);
+    	}
         if (clz != null) {
             AnnotationDesc aDesc = msrd.getAnnotationDesc(clz);
             if (aDesc != null) {
@@ -445,6 +517,9 @@
                                 (seeAlso[i].getPackage() == null) ? "" : 
                                     seeAlso[i].getPackage().getName();
                         if (pkg != null) {
+                        	if (log.isDebugEnabled()) {
+                        		log.debug(" adding package = " + pkg);
+                        	}
                             set.add(pkg);
                         }
                     }
@@ -458,6 +533,9 @@
                 }
             }
         }
+        if (log.isDebugEnabled()) {
+    		log.debug("end addXmlSeeAlsoPackages for " + clz);
+    	}
     }
     /**
      * Loads the class
@@ -504,7 +582,7 @@
             // Class.forName does not support primitives
             Class cls = ClassUtils.getPrimitiveClass(className);
             if (cls == null) {
-                cls = Class.forName(className, true, loader);
+                cls = forName(className, true, loader);
             }
             return cls;
             //Catch Throwable as ClassLoader can throw an NoClassDefFoundError that
@@ -568,7 +646,7 @@
                             // Class.forName does not support primitives
                             Class cls = ClassUtils.getPrimitiveClass(className);
                             if (cls == null) {
-                                cls = Class.forName(className, initialize, classloader);
+                                cls = forName(className, initialize, classloader);
                             }
                             return cls;
                         }
@@ -625,4 +703,18 @@
         }
         return result;
     }
+    
+    /**
+     * Get an annotation.  This is wrappered to avoid a Java2Security violation.
+     * @param cls Class that contains annotation 
+     * @param annotation Class of requrested Annotation
+     * @return annotation or null
+     */
+    private static Annotation getAnnotation(final AnnotatedElement element, final Class annotation) {
+        return (Annotation) AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                return element.getAnnotation(annotation);
+            }
+        });
+    }
 }