You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2009/10/24 03:46:15 UTC

svn commit: r829296 [3/3] - in /webservices/axis2/trunk/java/modules: jaxws-integration/ jaxws-integration/test/org/apache/axis2/jaxws/sample/ jaxws-integration/test/org/apache/axis2/jaxws/sample/dlwminArrays/ jaxws/src/org/apache/axis2/datasource/jaxb...

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor.java?rev=829296&r1=829295&r2=829296&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor.java Sat Oct 24 01:46:13 2009
@@ -31,6 +31,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import java.lang.reflect.Method;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
@@ -50,6 +51,8 @@
             new HashMap<OperationDescription, String>();
     private Map<OperationDescription, String> responseWrapperMap =
             new HashMap<OperationDescription, String>();
+    private Map<OperationDescription, Method> methodMap =
+        new HashMap<OperationDescription, Method>();
     private Map<FaultDescription, FaultBeanDesc> faultBeanDescMap =
             new HashMap<FaultDescription, FaultBeanDesc>();
 
@@ -73,6 +76,10 @@
     Map<FaultDescription, FaultBeanDesc> getFaultBeanDescMap() {
         return faultBeanDescMap;
     }
+    
+    Map<OperationDescription, Method> getMethodMap() {
+        return methodMap;
+    }
 
     void build() {
         for (EndpointDescription ed : serviceDesc.getEndpointDescriptions()) {
@@ -84,6 +91,7 @@
                     String packageName = getPackageName(declaringClassName);
                     String simpleName = getSimpleClassName(declaringClassName);
                     String methodName = opDesc.getJavaMethodName();
+                    
 
                     // There is no default for @RequestWrapper/@ResponseWrapper classname  None is listed in Sec. 7.3 on p. 80 of
                     // the JAX-WS spec, BUT Conformance(Using javax.xml.ws.RequestWrapper) in Sec 2.3.1.2 on p. 13
@@ -137,10 +145,41 @@
                         FaultBeanDesc faultBeanDesc = create(ed, faultDesc, opDesc);
                         faultBeanDescMap.put(faultDesc, faultBeanDesc);
                     }
+                    
+                    // Get the Method
+                    Class cls = null;
+                    try {
+                        cls = loadClass(declaringClassName, getContextClassLoader());
+                    } catch(Exception e) {
+                        if (log.isDebugEnabled()) {
+                            log.debug("Class " + declaringClassName + " was not found by the Context ClassLoader.  " +
+                            		"Will use the ClassLoader associated with the service.  The exception is: " +e);
+                        }
+                    }
+                    
+                    if (cls == null) {
+                        try {
+                            cls = loadClass(declaringClassName, ed.getAxisService().getClassLoader());
+                        } catch(Exception e) {
+                            if (log.isDebugEnabled()) {
+                                log.debug("Class " + declaringClassName + " was not found by the AxisService ClassLoader.  " +
+                                        "Processing continues.  The exception is:" +e);
+                            }
+                            
+                        }
+                    }
+                    if (cls != null) {
+                        Method method = getMethod(opDesc.getJavaMethodName(), cls);
+                        if (method != null) {
+                            methodMap.put(opDesc, method);
+                        }
+                    }
+                    
                 }
             }
         }
     }
+    
 
     private FaultBeanDesc create(EndpointDescription ed, FaultDescription faultDesc, OperationDescription opDesc) {
         /* FaultBeanClass algorithm
@@ -396,6 +435,39 @@
 
         return cl;
     }
+    
+    /**
+     * Return the Method matching the method name or null
+     * @param methodName String containing method name
+     * @param cls Class of the class that declares the method
+     *
+     * @return Method or null
+     */
+    private static Method getMethod(final String methodName, final Class cls) {
+        // NOTE: This method must remain protected because it uses AccessController
+        Method method = null;
+        try {
+            method = (Method)AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                        public Object run()  {
+                            Method[] methods = cls.getMethods();
+                            if (methods != null) {
+                                for (int i=0; i<methods.length; i++) {
+                                    if (methods[i].getName().equals(methodName)) {
+                                        return methods[i];
+                                    }
+                                }
+                            }
+                            return null;
+                        }
+                    }
+            );
+        } catch (PrivilegedActionException e) {
+            
+        }
+
+        return method;
+    }
 
     /** @return ClassLoader */
     private static ClassLoader getContextClassLoader() {

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=829296&r1=829295&r2=829296&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 Sat Oct 24 01:46:13 2009
@@ -81,6 +81,7 @@
         marshalDesc.setRequestWrapperMap(artifactProcessor.getRequestWrapperMap());
         marshalDesc.setResponseWrapperMap(artifactProcessor.getResponseWrapperMap());
         marshalDesc.setFaultBeanDescMap(artifactProcessor.getFaultBeanDescMap());
+        marshalDesc.setMethodMap(artifactProcessor.getMethodMap());
 
         if (log.isDebugEnabled()) {
     		log.debug("Build the annotations map");

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=829296&r1=829295&r2=829296&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 Sat Oct 24 01:46:13 2009
@@ -31,11 +31,20 @@
 import org.apache.axis2.jaxws.utility.PropertyDescriptorPlus;
 import org.apache.axis2.jaxws.utility.XMLRootElementUtil;
 
+import java.lang.reflect.Method;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.TreeSet;
 
 
+/**
+ * @author scheu
+ *
+ */
+/**
+ * @author scheu
+ *
+ */
 public class MarshalServiceRuntimeDescriptionImpl implements
         MarshalServiceRuntimeDescription {
 
@@ -48,6 +57,7 @@
     private Map<OperationDescription, String> requestWrapperMap = null;
     private Map<OperationDescription, String> responseWrapperMap = null;
     private Map<FaultDescription, FaultBeanDesc> faultBeanDescMap = null;
+    private Map<OperationDescription, Method> methodMap = null;
     private MessageFactory messageFactory =
             (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
 
@@ -144,6 +154,21 @@
     void setFaultBeanDescMap(Map<FaultDescription, FaultBeanDesc> map) {
         faultBeanDescMap = map;
     }
+    
+    
+    /**
+     * Get the Method for the specified OperationDescription
+     */
+    public Method getMethod(OperationDescription operationDesc) {
+        return methodMap.get(operationDesc);
+    }
+    
+    /**
+     * Set the Map containing the OperationDescription->Method mapping
+     */
+    void setMethodMap(Map<OperationDescription, Method> map) {
+        methodMap = map;
+    }
 
     public String toString() {
         try {
@@ -199,6 +224,13 @@
                 string.append(newline);
                 string.append(entry.getValue().toString());
             }
+            
+            string.append("    Methods");
+            for (Entry<OperationDescription, Method> entry : this.methodMap.entrySet()) {
+                string.append(newline);
+                string.append("    Method Name:" + entry.getKey().getJavaMethodName() +
+                        " Method:" + entry.getValue().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=829296&r1=829295&r2=829296&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 Sat Oct 24 01:46:13 2009
@@ -295,34 +295,76 @@
         }
 
         // Also consider the request and response wrappers
-        String pkg = getPackageFromClassName(msrd.getRequestWrapperClassName(opDesc));
+        String requestWrapperPkg = getPackageFromClassName(msrd.getRequestWrapperClassName(opDesc));
         if (log.isDebugEnabled()) {
-            log.debug("Package from Request Wrapper annotation = " + pkg);
+            log.debug("Package from Request Wrapper annotation = " + requestWrapperPkg);
         }
-        if (pkg != null) {
-            set.add(pkg);
+        if (requestWrapperPkg != null) {
+            set.add(requestWrapperPkg);
         }
-        pkg = getPackageFromClassName(msrd.getResponseWrapperClassName(opDesc));
+        String responseWrapperPkg = getPackageFromClassName(msrd.getResponseWrapperClassName(opDesc));
         if (log.isDebugEnabled()) {
-            log.debug("Package from Response Wrapper annotation = " + pkg);
+            log.debug("Package from Response Wrapper annotation = " + responseWrapperPkg);
         }
-        if (pkg != null) {
-            set.add(pkg);
+        if (responseWrapperPkg != null) {
+            set.add(responseWrapperPkg);
+        }
+        
+        // In most doc/literal cases, the @RequestWrapper or @ResponseWrapper classes are successfully found.
+        // The wrapper classes contain the representation of the parameters, thus the parameters don't need
+        // to be separately processed.
+        // However if the @RequestWrapper or @ResponseWrappers are not found, then the parameters must be examined.
+        if (requestWrapperPkg == null || responseWrapperPkg == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Collect the packages of the parameters");
+            }
+            addPackagesFromParameters(set, opDesc) ;          
         }
 
         // Finally consider the result type
         Class cls = opDesc.getResultActualType();
         if (cls != null && cls != void.class && cls != Void.class) {
-            Package returnTypePkg = cls.getPackage();
+            String pkg = getPackageFromClass(cls);
             if (log.isDebugEnabled()) {
                 log.debug("Package from Return Type = " + pkg);
             }
-            if (returnTypePkg != null) {
-                pkg = returnTypePkg.getName();
+            if (pkg != null) {
                 set.add(pkg);
             }
         }
     }
+    
+    
+    /**
+     * addPackagesFromParameters
+     * @param set  Set of packages
+     * @param opDesc OperationDesc containing ParameterDescs
+     */
+    private static void addPackagesFromParameters(TreeSet<String> set, OperationDescription opDesc) {
+        ParameterDescription[] pDescs = opDesc.getParameterDescriptions();
+        if (pDescs != null) {
+            for (int i=0; i<pDescs.length; i++) {
+                ParameterDescription pDesc = pDescs[i];
+                if (pDesc != null) {
+                    // Get the actual type of the parameter.
+                    // For example if the parameter is Holder<A>, the A.class is
+                    // returned.
+                    // TODO Unfortunately the ParameterDescriptor only provides
+                    // the class, not the full generic.  So if the parameter
+                    // is List<A>, only List is returned.  The ParameterDescriptor
+                    // and this logic will need to be improved to handle that case.
+                    Class paramClass = pDesc.getParameterActualType();
+                    String pkg = getPackageFromClass(paramClass);
+                    if (log.isDebugEnabled()) {
+                        log.debug("Package from Parameter (" + paramClass + ") = " + pkg);
+                    }
+                    if (pkg != null) {
+                        set.add(pkg);
+                    }
+                }
+            }
+        }    
+    }
 
     /**
      * Update the package set with the packages referenced by this ParameterDescription
@@ -488,17 +530,39 @@
 
     /**
      * Return the package associated with the class name.  The className may not be specified (in
-     * which case a null Package is returned). if class has unnamed package return ""
+     * which case a null Package is returned). 
+     * If class has anunnamed package return ""
      *
      * @param className String (may be null or empty)
-     * @return Package or null if problems occur
+     * @return String or null if problems occur
      */
-    private static String getPackageFromClassName(String className) {
+    public static String getPackageFromClassName(String className) {
         Class clz = loadClass(className);
-        String pkg =
-                (clz == null) ? null : (clz.getPackage() == null) ? "" : clz.getPackage().getName();
+        String pkg = getPackageFromClass(clz);
         return pkg;
     }
+    
+    /**
+     * Return the package associated with the class name.  The className may not be specified (in
+     * which case a null Package is returned). if class has unnamed package return ""
+     *
+     * @param cls Class
+     * @return String or null 
+     */
+    public static String getPackageFromClass(Class cls) {
+        String pkgName = null;
+        if (cls == null) {
+            pkgName = null;
+        } else if (cls.isArray()) {
+            pkgName = getPackageFromClass(cls.getComponentType());
+        } else if (cls.isPrimitive()) {
+            pkgName = null;
+        } else {
+            pkgName =
+                (cls.getPackage() == null) ? "" : cls.getPackage().getName(); 
+        }
+        return pkgName;
+    }
 
     private static void addXmlSeeAlsoPackages(Class clz, 
                                               MarshalServiceRuntimeDescription msrd, 

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java?rev=829296&r1=829295&r2=829296&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java Sat Oct 24 01:46:13 2009
@@ -134,5 +134,64 @@
         assertTrue(baos.toString().indexOf("</root>") > 0);
     }
     
+    /**
+     * Create a Block representing an JAXB and simulate a 
+     * normal Dispatch<JAXB> flow
+     * @throws Exception
+     */
+    public void testMarshalArray() throws Exception {
+        
+        // Create a JAXBDSContext for the package containing Data
+        TreeSet<String> packages = new TreeSet<String>();
+        packages.add(Data.class.getPackage().getName());
+        JAXBDSContext context = new JAXBDSContext(packages);
+        
+        System.out.println(context.getJAXBContext().toString());
+        
+        // Force marshal by type
+        context.setProcessType(Data[].class);
+        
+        // Create an Data value
+        ObjectFactory factory = new ObjectFactory();
+        Data value[] = new Data[3];
+        value[0] = factory.createData(); 
+        value[0].setInput("Hello");
+        value[1] = factory.createData(); 
+        value[1].setInput("Beautiful");
+        value[2] = factory.createData(); 
+        value[2].setInput("World");
+        
+        // Create a JAXBElement.
+        // To indicate "occurrence elements", the value is wrapped in
+        // an OccurrenceArray
+        QName qName = new QName("urn://sample", "data");
+        OccurrenceArray occurrenceArray = new OccurrenceArray(value);
+        JAXBElement jaxbElement = new JAXBElement(qName, Data[].class, occurrenceArray);
+
+        // Create a writer
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OMOutputFormat format = new OMOutputFormat();
+        format.setDoOptimize(true);
+        MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(baos, format);
+        
+        // Marshal the value
+        writer.writeStartElement("root");
+        context.marshal(jaxbElement, writer);
+        writer.writeEndElement();
+
+        writer.flush();
+        
+        String outputText = baos.toString();
+        String subText = outputText;
+        int count = 0;
+        while (subText.indexOf("data") > 0) {
+            count++;
+            subText = subText.substring(subText.indexOf("data") + 1);
+        }
+        // 3 data refs for start tag name
+        // 3 data refs for end tag name
+        // 3 xsi type refs
+        assertTrue("Expected 9 data tags but found "+count+"  Text is:"+outputText, count == 9);
+    }
    
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java?rev=829296&r1=829295&r2=829296&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java Sat Oct 24 01:46:13 2009
@@ -582,4 +582,25 @@
         text = replace(text, "at ", "DEBUG_FRAME = ");
         return text;
     }
+    
+    /**
+     * Mimics the default Object.toString() produces a string of the form:
+     * 
+     *      obj.getClass().getName() + "@" + object's hashCode.
+     * 
+     * This method can be used to print the debug message when you want
+     * just the short name or if using the toString will cause full expansion
+     * of underlying data structures.
+     * 
+     * The returned value can also be used as an identity key.
+     * 
+     * @return obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj));
+     */
+    public static String getObjectIdentity(Object obj) {
+        if (obj == null) {
+            return "null";
+        }
+        return obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj));
+    }
+
 }