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 2007/07/11 22:26:36 UTC

svn commit: r555386 - in /webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl: DescriptionUtils.java OperationDescriptionImpl.java ParameterDescriptionImpl.java

Author: scheu
Date: Wed Jul 11 13:26:32 2007
New Revision: 555386

URL: http://svn.apache.org/viewvc?view=rev&rev=555386
Log:
JIRA AXIS2-2943
Contributor: Dustin Amrhein
This patch improves the AttachmentDescription capabilities of the metadata module.
Subsequent patches will use this information in the JAX-WS RPC/LIT attachment marshalling.

Modified:
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ParameterDescriptionImpl.java

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java?view=diff&rev=555386&r1=555385&r2=555386
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java Wed Jul 11 13:26:32 2007
@@ -21,6 +21,8 @@
 import static org.apache.axis2.jaxws.description.builder.MDQConstants.CONSTRUCTOR_METHOD;
 
 import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.description.AttachmentDescription;
+import org.apache.axis2.jaxws.description.AttachmentType;
 import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
 import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
 import org.apache.axis2.jaxws.description.builder.WebMethodAnnot;
@@ -29,6 +31,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Operation;
+import javax.wsdl.extensions.mime.MIMEContent;
+import javax.wsdl.extensions.mime.MIMEMultipartRelated;
+import javax.wsdl.extensions.mime.MIMEPart;
 import javax.wsdl.extensions.soap.SOAPBody;
 import javax.wsdl.extensions.soap.SOAPHeader;
 import javax.wsdl.extensions.soap12.SOAP12Body;
@@ -405,5 +413,86 @@
         }
         return null;
     }
-    
+    /**
+     * This method will process a WSDL Binding and build AttachmentDescription objects if the
+     * WSDL dicatates attachments.
+     */
+    public static void getAttachmentFromBinding(OperationDescriptionImpl opDesc, Binding binding) {
+        if (binding != null) {
+            Iterator bindingOpIter = binding.getBindingOperations().iterator();
+            while (bindingOpIter.hasNext()) {
+                BindingOperation bindingOp = (BindingOperation) bindingOpIter.next();
+                // found the BindingOperation that matches the current OperationDescription
+                if (bindingOp.getName().equals(opDesc.getOperationName())) {
+                    if (bindingOp.getBindingInput() != null) {
+                        if (log.isDebugEnabled()) {
+                            log.debug("Processing binding input");
+                        }
+                        processBindingForMIME(bindingOp.getBindingInput()
+                                                       .getExtensibilityElements(),
+                                              opDesc,
+                                              bindingOp.getOperation());
+                    }
+                    if (bindingOp.getBindingOutput() != null) {
+                        if (log.isDebugEnabled()) {
+                            log.debug("Processing binding output");
+                        }
+                        processBindingForMIME(bindingOp.getBindingOutput()
+                                                       .getExtensibilityElements(),
+                                              opDesc,
+                                              bindingOp.getOperation());
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * This method will loop through the extensibility elements for a given BindingInput or
+     * BindingOutput element and determine if it has any MIMEMultipartRelated content. If it 
+     * does it will build up the appropriate AttachmentDescription objects.
+     */
+    private static void processBindingForMIME(List extensibilityElements,
+                                              OperationDescriptionImpl opDesc, Operation operation) {
+        Iterator extensibilityIter = extensibilityElements.iterator();
+        while (extensibilityIter.hasNext()) {
+            Object obj = extensibilityIter.next();
+            if (obj instanceof MIMEMultipartRelated) {
+                // Found mime information now process it and determine if we need to
+                // create an AttachmentDescription
+                MIMEMultipartRelated mime = (MIMEMultipartRelated) obj;
+                Iterator partIter = mime.getMIMEParts().iterator();
+                while (partIter.hasNext()) {
+                    MIMEPart mimePart = (MIMEPart) partIter.next();
+                    Iterator mExtIter = mimePart.getExtensibilityElements().iterator();
+                    // Process each mime part to determine if there is mime content
+                    while (mExtIter.hasNext()) {
+                        Object obj2 = mExtIter.next();
+                        // For mime content we need to potentially create an AttachmentDescription
+                        if (obj2 instanceof MIMEContent) {
+                            MIMEContent mimeContent = (MIMEContent) obj2;
+                            String part = mimeContent.getPart();
+                            String type = mimeContent.getType();
+                            // if we have not already processed this part for the operation
+                            if (opDesc.getPartAttachmentDescription(part) == null) {
+                                if (log.isDebugEnabled()) {
+                                    log.debug("Adding new AttachmentDescription for part: " + part
+                                            + " on operation: " + opDesc.getOperationName());
+                                }
+                                AttachmentDescription attachmentDesc =
+                                        new AttachmentDescriptionImpl(AttachmentType.SWA,
+                                                                      new String[] { type });
+                                opDesc.addPartAttachmentDescription(part, attachmentDesc);
+                            } else {
+                                if (log.isDebugEnabled()) {
+                                    log.debug("Already created AttachmentDescription for part: "
+                                            + part + " of type: " + type);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
 }

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java?view=diff&rev=555386&r1=555385&r2=555386
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java Wed Jul 11 13:26:32 2007
@@ -179,10 +179,12 @@
     // RUNTIME INFORMATION
     Map<String, OperationRuntimeDescription> runtimeDescMap =
             Collections.synchronizedMap(new HashMap<String, OperationRuntimeDescription>());
-
+    private Map<String, AttachmentDescription> partAttachmentMap;
+    
     OperationDescriptionImpl(Method method, EndpointInterfaceDescription parent) {
         // TODO: Look for WebMethod anno; get name and action off of it
         parentEndpointInterfaceDescription = parent;
+        partAttachmentMap = new HashMap<String, AttachmentDescription>();
         setSEIMethod(method);
 		checkForXmlListAnnotation(method.getAnnotations());
         // The operationQName is intentionally unqualified to be consistent with the remaining parts of the system. 
@@ -198,6 +200,7 @@
 
     OperationDescriptionImpl(AxisOperation operation, EndpointInterfaceDescription parent) {
         parentEndpointInterfaceDescription = parent;
+        partAttachmentMap = new HashMap<String, AttachmentDescription>();
         axisOperation = operation;
         this.operationQName = axisOperation.getName();
     }
@@ -207,6 +210,7 @@
                              AxisOperation axisOperation) {
 
         parentEndpointInterfaceDescription = parent;
+        partAttachmentMap = new HashMap<String, AttachmentDescription>();
         methodComposite = mdc;
         // The operationQName is intentionally unqualified to be consistent with the remaining parts of the system. 
         // Using a qualified name will cause breakage.
@@ -218,6 +222,7 @@
         parameterDescriptions = createParameterDescriptions();
         faultDescriptions = createFaultDescriptions();
 		isListType = mdc.isListType();
+        buildAttachmentInformation();
 
         //If an AxisOperation was already created for us by populateService then just use that one
         //Otherwise, create it
@@ -1762,35 +1767,47 @@
     }
     
     public AttachmentDescription getResultAttachmentDescription() {
-        if (_setAttachmentDesc) {
-            return attachmentDesc;
-        }
-        _setAttachmentDesc = true;
-
-        // TODO
-        // The annotation description should be constructed using the
-        // wsdl information.  
-        // In order to test the marshalling processing, I am 
-        // creating a dummy attachment triggered solely by the part name and
-        // part type.
-
         String partName = this.getResultPartName();
-        if (partName != null && 
-                partName.startsWith("dummyAttachment")) {
-            Class paramType = getResultActualType();
-            if (paramType == String.class) {
-                // TODO For the purposes of testing, assume this is text/plain
-                attachmentDesc = new AttachmentDescriptionImpl(AttachmentType.SWAREF,
-                                                               new String[] {"text/plain"});
-
-            } else if (paramType == byte[].class) {
-                // TODO For the purposes of testing, assume this is image/gif
-                attachmentDesc = new AttachmentDescriptionImpl(AttachmentType.SWAREF,
-                                                               new String[] {"text/plain"});
+        if (partName != null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Returning result AttachmentDescription for partName: " + partName);
             }
+            return partAttachmentMap.get(partName);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("Did not find result AttachmentDescription for partName: " + partName);
+        }
+        return null;
+    }
+    
+    /**
+     * This method will drive the building of AttachmentDescription objects for the
+     * operation input/output messages in the WSDL.
+     *
+     */
+    private void buildAttachmentInformation() {
+
+        // Only building attachment info if we find a full WSDL
+        if (this.getEndpointInterfaceDescriptionImpl()
+                .getEndpointDescriptionImpl()
+                .isWSDLFullySpecified()) {
+            DescriptionUtils.getAttachmentFromBinding(this,
+                                                      this.getEndpointInterfaceDescriptionImpl()
+                                                          .getEndpointDescriptionImpl()
+                                                          .getWSDLBinding());
         }
 
-        return attachmentDesc;
+    }
+
+    /**
+     * This will return an AttachmentDescription based on a part name.
+     */
+    public AttachmentDescription getPartAttachmentDescription(String partName) {
+        return partAttachmentMap.get(partName);
+    }
+
+    public void addPartAttachmentDescription(String partName, AttachmentDescription attachmentDesc) {
+        partAttachmentMap.put(partName, attachmentDesc);
     }
             
     public String toString() {
@@ -1877,6 +1894,21 @@
                 string.append("No Fault Descriptions");
             }
 
+            if(!partAttachmentMap.isEmpty()) {
+                string.append(newline);
+                string.append("Number of Attachment Descriptions: "  + partAttachmentMap.size());
+                string.append(newline);
+                Iterator<AttachmentDescription> adIter = partAttachmentMap.values().iterator();
+                while(adIter.hasNext()) {
+                        string.append(adIter.next().toString());
+                        string.append(newline);
+                }
+            } else {
+                string.append(newline);
+                string.append("No Attachment Descriptions");
+                string.append(newline);
+            }
+            
             string.append("RuntimeDescriptions:" + this.runtimeDescMap.size());
             string.append(newline);
             for (OperationRuntimeDescription runtimeDesc : runtimeDescMap.values()) {

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ParameterDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ParameterDescriptionImpl.java?view=diff&rev=555386&r1=555385&r2=555386
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ParameterDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ParameterDescriptionImpl.java Wed Jul 11 13:26:32 2007
@@ -28,6 +28,8 @@
 import org.apache.axis2.jaxws.description.ParameterDescriptionJava;
 import org.apache.axis2.jaxws.description.ParameterDescriptionWSDL;
 import org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.jws.WebParam;
 import javax.jws.soap.SOAPBinding;
@@ -42,6 +44,7 @@
 /** @see ../ParameterDescription */
 class ParameterDescriptionImpl
         implements ParameterDescription, ParameterDescriptionJava, ParameterDescriptionWSDL {
+    private static final Log log = LogFactory.getLog(ParameterDescriptionImpl.class);
     private OperationDescription parentOperationDescription;
     // The Class representing the parameter.  Note that for a Generic, including the JAX-WS Holder<T> Generic, 
     // this represents the raw type of the Generic (e.g. List for List<T> or Holder for Holder<T>).
@@ -399,36 +402,32 @@
     	return isListType;
     }
     
-    public AttachmentDescription getAttachmentDescription() {
-        if (_setAttachmentDesc) {
-            return attachmentDesc;
+    /**
+     * Helper method to get to parent impl object.
+     */
+    private OperationDescriptionImpl getOperationDescriptionImpl() {
+        if(this.getOperationDescription() instanceof OperationDescriptionImpl) {
+                return (OperationDescriptionImpl) this.getOperationDescription();
         }
-        _setAttachmentDesc = true;
-        
-        // TODO
-        // The annotation description should be constructed using the
-        // wsdl information.  
-        // In order to test the marshalling processing, I am 
-        // creating a dummy attachment triggered solely by the part name and
-        // part type.
-        
+        return null;
+    }
+    
+    /**
+     * This method will return an AttachmentDescription based on the part name of the parameter.
+     */
+    public AttachmentDescription getAttachmentDescription() {
         String partName = this.getPartName();
-        if (partName != null && 
-            partName.startsWith("dummyAttachment")) {
-            Class paramType = getParameterActualType();
-            if (paramType == String.class) {
-                // TODO For the purposes of testing, assume this is text/plain
-                attachmentDesc = new AttachmentDescriptionImpl(AttachmentType.SWAREF,
-                        new String[] {"text/plain"});
-                
-            } else if (paramType == byte[].class) {
-                // TODO For the purposes of testing, assume this is image/gif
-                attachmentDesc = new AttachmentDescriptionImpl(AttachmentType.SWAREF,
-                        new String[] {"text/plain"});
+        if(partName != null && getOperationDescriptionImpl() != null) {
+            if(log.isDebugEnabled()) {
+                log.debug("Returning parameter AttachmentDescription for partName: " + 
+                          partName);
             }
+            return getOperationDescriptionImpl().getPartAttachmentDescription(partName);
             
         }
-       
-        return attachmentDesc;
+        if(log.isDebugEnabled()) {
+            log.debug("Did not find parameter AttachmentDescription for partName: " + partName);
+        }
+        return null;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org