cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r542042 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ systests/src/test/java/org/apache/cxf/systest/swa/ testutils/src/main/java/org/apache/cxf/testutil/common/ testutils/src/main/resources/ws...
Date Sun, 27 May 2007 21:58:00 GMT
Author: dandiep
Date: Sun May 27 14:57:58 2007
New Revision: 542042

URL: http://svn.apache.org/viewvc?view=rev&rev=542042
Log:
- Delete MIMEProcessor and integrate logic into ServiceProcessor so we can
  properly process SOAPHeaders.
- Fix build breakage which was a result of me not cleaning testutils
- Process attachment indexes a little better  (more refactoring coming)


Removed:
    incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/MIMEProcessor.java
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAInInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/SwAServiceImpl.java
    incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java
    incubator/cxf/trunk/testutils/src/main/resources/wsdl/swa-mime.wsdl
    incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ServiceProcessor.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAInInterceptor.java?view=diff&rev=542042&r1=542041&r2=542042
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAInInterceptor.java
Sun May 27 14:57:58 2007
@@ -75,6 +75,12 @@
             
             String start = partName + "=";
             boolean found = false;
+            
+            int idx = mpi.getIndex();
+            if (idx > inObjects.size()) {
+                idx = inObjects.size();
+            }
+            
             for (Attachment a : message.getAttachments()) {
                 if (a.getId().startsWith(start)) {
                     String ct = (String) mpi.getProperty(Message.CONTENT_TYPE);
@@ -97,14 +103,16 @@
                         o = dh;
                     }
                     
-                    inObjects.add(o);
+                    inObjects.add(idx, o);
                     found = true;
                     break;
                 }
             }
             
             if (!found) {
-                inObjects.add(null);
+
+                
+                inObjects.add(idx, null);
             }
         }
     }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java?view=diff&rev=542042&r1=542041&r2=542042
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
Sun May 27 14:57:58 2007
@@ -111,8 +111,8 @@
         Collection<Attachment> atts = setupAttachmentOutput(message);
 
         List<Object> outObjects = CastUtils.cast(message.getContent(List.class));
-
-        int bodyParts = sbi.getParts().size();
+        
+        int removed = 0;
         for (MessagePartInfo mpi : sbi.getAttachments()) {
             String partName = mpi.getConcreteName().getLocalPart();
             String ct = (String) mpi.getProperty(Message.CONTENT_TYPE);
@@ -122,11 +122,13 @@
                 .append(UUID.randomUUID())
                 .append("@apache.org").toString();
             
-            Object o = outObjects.remove(bodyParts);
+            // this assumes things are in order...
+            Object o = outObjects.remove(mpi.getIndex() - removed);
             if (o == null) {
                 continue;
             }
             
+            removed++;
             DataHandler dh = null;
             
             // This code could probably be refactored out somewhere...

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java?view=diff&rev=542042&r1=542041&r2=542042
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java
Sun May 27 14:57:58 2007
@@ -74,6 +74,37 @@
     }
     
     @Test
+    public void testSwaWithHeaders() throws Exception {
+        SwAService service = new SwAService();
+        
+        SwAServiceInterface port = service.getSwAServiceHttpPort();
+//        ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,

+//                                                        "http://localhost:9037/swa");
+        
+        Holder<String> textHolder = new Holder<String>();
+        Holder<String> headerHolder = new Holder<String>();
+        Holder<DataHandler> data = new Holder<DataHandler>();
+        
+        ByteArrayDataSource source = new ByteArrayDataSource("foobar".getBytes(), "application/octet-stream");
+        DataHandler handler = new DataHandler(source);
+        
+        data.value = handler;
+        
+        textHolder.value = "Hi";
+        headerHolder.value = "Header";
+
+        port.echoDataWithHeader(textHolder, data, headerHolder);
+        InputStream bis = null;
+        bis = data.value.getDataSource().getInputStream();
+        byte b[] = new byte[10];
+        bis.read(b, 0, 10);
+        String string = new String(b);
+        assertEquals("testfoobar", string);
+        assertEquals("Hi", textHolder.value);
+        assertEquals("Header", headerHolder.value);
+    }
+    
+    @Test
     public void testSwaDataStruct() throws Exception {
         SwAService service = new SwAService();
         

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/SwAServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/SwAServiceImpl.java?view=diff&rev=542042&r1=542041&r2=542042
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/SwAServiceImpl.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/swa/SwAServiceImpl.java
Sun May 27 14:57:58 2007
@@ -74,6 +74,24 @@
         }
     }
     
+    public void echoDataWithHeader(Holder<String> text, 
+                                   Holder<DataHandler> data,
+                                   Holder<String> headerText) {
+        try {
+            InputStream bis = null;
+            bis = data.value.getDataSource().getInputStream();
+            byte b[] = new byte[6];
+            bis.read(b, 0, 6);
+            String string = new String(b);
+            
+            ByteArrayDataSource source = 
+                new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream");
+            data.value = new DataHandler(source);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
     public OutputResponseAll echoAllAttachmentTypes(VoidRequest request, Holder<DataHandler>
attach1,
                                                     Holder<DataHandler> attach2, Holder<Source>
attach3,
                                                     Holder<Image> attach4, Holder<Image>
attach5) {

Modified: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java?view=diff&rev=542042&r1=542041&r2=542042
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java
(original)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java
Sun May 27 14:57:58 2007
@@ -41,7 +41,7 @@
     protected static final String SERVER_FAILED = 
         "server startup failed (not a log message)";
 
-    private static final boolean DEFAULT_IN_PROCESS = false;
+    private static final boolean DEFAULT_IN_PROCESS = true;
     
     private static final Logger LOG = Logger.getLogger(ServerLauncher.class.getName());
 
@@ -49,7 +49,7 @@
     final String className;
 
 
-    private final boolean debug = false;
+    private final boolean debug = true;
     private boolean inProcess = DEFAULT_IN_PROCESS;
     private AbstractTestServerBase inProcessServer;
     

Modified: incubator/cxf/trunk/testutils/src/main/resources/wsdl/swa-mime.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/resources/wsdl/swa-mime.wsdl?view=diff&rev=542042&r1=542041&r2=542042
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/resources/wsdl/swa-mime.wsdl (original)
+++ incubator/cxf/trunk/testutils/src/main/resources/wsdl/swa-mime.wsdl Sun May 27 14:57:58
2007
@@ -91,11 +91,13 @@
   <wsdl:message name="echoDataWithHeaderRequest">
     <wsdl:part name="text" element="types:headerText" />
     <wsdl:part name="data" type="xsd:base64Binary" />
+    <wsdl:part name="headerText" element="types:headerText" />
   </wsdl:message>
 
   <wsdl:message name="echoDataWithHeaderResponse">
     <wsdl:part name="text" element="types:headerText" />
     <wsdl:part name="data" type="xsd:base64Binary" />
+    <wsdl:part name="headerText" element="types:headerText" />
   </wsdl:message>
 
   <wsdl:message name="headerMessage">
@@ -159,14 +161,38 @@
       </wsdl:output>
     </wsdl:operation>
 
+    <wsdl:operation name="echoData">
+      <soap:operation soapAction="" style="literal" />
+      <wsdl:input>
+        <mime:multipartRelated>
+          <mime:part>
+            <soap:body parts="text" use="literal" />
+          </mime:part>
+          <mime:part>
+            <mime:content part="data" type="application/octet-stream" />
+          </mime:part>
+        </mime:multipartRelated>
+      </wsdl:input>
+      <wsdl:output>
+        <mime:multipartRelated>
+          <mime:part>
+            <soap:body parts="text" use="literal" />
+          </mime:part>
+          <mime:part>
+            <mime:content part="data" type="application/octet-stream" />
+          </mime:part>
+        </mime:multipartRelated>
+      </wsdl:output>
+    </wsdl:operation>
+
     <wsdl:operation name="echoDataWithHeader">
       <soap:operation soapAction="" style="literal" />
       <wsdl:input>
         <mime:multipartRelated>
           <mime:part>
             <soap:body parts="text" use="literal" />
-            <soap:header use="literal" part="text"
-              message="tns:headerMessage" />
+            <soap:header use="literal" part="headerText"
+              message="tns:echoDataWithHeaderRequest" />
           </mime:part>
           <mime:part>
             <mime:content part="data" type="application/octet-stream" />
@@ -177,8 +203,8 @@
         <mime:multipartRelated>
           <mime:part>
             <soap:body parts="text" use="literal" />
-            <soap:header use="literal" part="text"
-              message="tns:headerMessage" />
+            <soap:header use="literal" part="headerText"
+              message="tns:echoDataWithHeaderResponse" />
           </mime:part>
           <mime:part>
             <mime:content part="data" type="application/octet-stream" />

Modified: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ServiceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ServiceProcessor.java?view=diff&rev=542042&r1=542041&r2=542042
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ServiceProcessor.java
(original)
+++ incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ServiceProcessor.java
Sun May 27 14:57:58 2007
@@ -22,16 +22,21 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.http.HTTPBinding;
+import javax.wsdl.extensions.mime.MIMEContent;
 import javax.wsdl.extensions.mime.MIMEMultipartRelated;
+import javax.wsdl.extensions.mime.MIMEPart;
+import javax.wsdl.extensions.soap.SOAPHeader;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Element;
 
+import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.service.model.BindingInfo;
 import org.apache.cxf.service.model.BindingMessageInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -394,41 +399,11 @@
             if (SOAPBindingUtil.isSOAPBody(ext)) {
                 SoapBody soapBody = SOAPBindingUtil.getSoapBody(ext);
                 use = soapBody.getUse();
-            }            
-            
-            if (SOAPBindingUtil.isSOAPHeader(ext)) {
-                SoapHeader soapHeader = SOAPBindingUtil.getSoapHeader(ext);
-                boolean found = false;
-                for (JavaParameter parameter : jm.getParameters()) {
-                    if (soapHeader.getPart().equals(parameter.getPartName())) {
-                        setParameterAsHeader(parameter);
-                        found = true;
-                    }
-                }
-                if (Boolean.valueOf((String)context.get(ToolConstants.CFG_EXTRA_SOAPHEADER)).booleanValue()
-                    && !found) {
-                    // Header can't be found in java method parameters, in
-                    // different message
-                    // other than messages used in porttype operation
-                    ParameterProcessor processor = new ParameterProcessor(context);
-                    MessagePartInfo exPart = service.getMessage(soapHeader.getMessage())
-                        .getMessagePart(new QName(soapHeader.getMessage().getNamespaceURI(),
-                                                  soapHeader.getPart()));
-                        
-                    JavaType.Style jpStyle = JavaType.Style.IN;
-                    if (isInOutParam(soapHeader.getPart(), operation.getOutput())) {
-                        jpStyle = JavaType.Style.INOUT;
-                    }
-                    JavaParameter jp = processor.addParameterFromBinding(jm, exPart, jpStyle);
-                    if (soapHeader.getPart() != null && soapHeader.getPart().length()
> 0) {
-                        jp.getAnnotation().addArgument("partName", soapHeader.getPart());
-                    }
-                    setParameterAsHeader(jp);
-                }
+            } else if (SOAPBindingUtil.isSOAPHeader(ext)) {
+                processSoapHeader(jm, operation, ext);
             }
             if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
-                MIMEProcessor mimeProcessor = new MIMEProcessor(context);
-                mimeProcessor.process(jm, (MIMEMultipartRelated)ext, JavaType.Style.IN);
+                processMultipart(jm, operation, (MIMEMultipartRelated)ext, JavaType.Style.IN);
             }            
         }
         
@@ -466,8 +441,7 @@
                     }
                 }
                 if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
-                    MIMEProcessor mimeProcessor = new MIMEProcessor(context);
-                    mimeProcessor.process(jm, (MIMEMultipartRelated)ext, JavaType.Style.OUT);
+                    processMultipart(jm, operation, (MIMEMultipartRelated)ext, JavaType.Style.OUT);
                 }
             }           
         }
@@ -487,6 +461,106 @@
         }
     }
 
+    private void processSoapHeader(JavaMethod jm, BindingOperationInfo operation, ExtensibilityElement
ext) {
+        SoapHeader soapHeader = SOAPBindingUtil.getSoapHeader(ext);
+        boolean found = false;
+        for (JavaParameter parameter : jm.getParameters()) {
+            if (soapHeader.getPart().equals(parameter.getPartName())) {
+                setParameterAsHeader(parameter);
+                found = true;
+                break;
+            }
+        }
+        if (Boolean.valueOf((String)context.get(ToolConstants.CFG_EXTRA_SOAPHEADER)).booleanValue()
+            && !found) {
+            // Header can't be found in java method parameters, in
+            // different message
+            // other than messages used in porttype operation
+            ParameterProcessor processor = new ParameterProcessor(context);
+            MessagePartInfo exPart = service.getMessage(soapHeader.getMessage())
+                .getMessagePart(new QName(soapHeader.getMessage().getNamespaceURI(),
+                                          soapHeader.getPart()));
+                
+            JavaType.Style jpStyle = JavaType.Style.IN;
+            if (isInOutParam(soapHeader.getPart(), operation.getOutput())) {
+                jpStyle = JavaType.Style.INOUT;
+            }
+            JavaParameter jp = processor.addParameterFromBinding(jm, exPart, jpStyle);
+            if (soapHeader.getPart() != null && soapHeader.getPart().length() >
0) {
+                jp.getAnnotation().addArgument("partName", soapHeader.getPart());
+            }
+            setParameterAsHeader(jp);
+        }
+    }
+
+    private static String getJavaTypeForMimeType(MIMEPart mPart) {
+        if (mPart.getExtensibilityElements().size() > 1) {
+            return "javax.activation.DataHandler";
+        } else {
+            ExtensibilityElement extElement = (ExtensibilityElement)mPart.getExtensibilityElements().get(0);
+            if (extElement instanceof MIMEContent) {
+                MIMEContent mimeContent = (MIMEContent)extElement;
+                if ("image/jpeg".equals(mimeContent.getType()) || "image/gif".equals(mimeContent.getType()))
{
+                    return "java.awt.Image";
+                } else if ("text/xml".equals(mimeContent.getType())
+                           || "application/xml".equals(mimeContent.getType())) {
+                    return "javax.xml.transform.Source";
+                }  else {
+                    return "javax.activation.DataHandler";
+                }
+            }
+        }
+        return "javax.activation.DataHandler";
+    }
+
+    public void processMultipart(JavaMethod jm, BindingOperationInfo operation,
+                                 MIMEMultipartRelated ext, JavaType.Style style) throws ToolException
{
+        List mimeParts = ext.getMIMEParts();
+        Iterator itParts = mimeParts.iterator();
+        while (itParts.hasNext()) {
+            MIMEPart mPart = (MIMEPart)itParts.next();
+            Iterator extns = mPart.getExtensibilityElements().iterator();
+            while (extns.hasNext()) {
+                ExtensibilityElement extElement = (ExtensibilityElement)extns.next();
+                if (extElement instanceof MIMEContent) {
+                    MIMEContent mimeContent = (MIMEContent)extElement;
+                    String mimeJavaType = getJavaTypeForMimeType(mPart);
+                    if (JavaType.Style.IN.equals(style)) {
+                        String paramName = ProcessorUtil.mangleNameToVariableName(mimeContent.getPart());
+                        JavaParameter jp = jm.getParameter(paramName);
+                        if (jp == null) {
+                            Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
+                            throw new ToolException(message);
+                        }
+                        if (!jp.getClassName().equals(mimeJavaType)) {
+                            // jp.setType(mimeJavaType);
+                            jp.setClassName(mimeJavaType);
+                        }
+                    } else if (JavaType.Style.OUT.equals(style)) {
+                        String paramName = ProcessorUtil.mangleNameToVariableName(mimeContent.getPart());
+                        JavaType jp = jm.getParameter(paramName);
+                        if (jp == null) {
+                            //check return
+                            if (paramName.equals(jm.getReturn().getName())) {
+                                jp = jm.getReturn();
+                            }
+                        } else {
+                            ((JavaParameter)jp).setHolderClass(mimeJavaType);
+                        }
+                        if (jp == null) {
+                            Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent
+                                .getPart());
+                            throw new ToolException(message);
+                        } 
+                        jp.setClassName(mimeJavaType);
+                    }
+                } else if (extElement instanceof SOAPHeader) {
+                    processSoapHeader(jm, operation, extElement);
+                }
+            }
+        }
+    }
+    
     private Map getSoapOperationProp(BindingOperationInfo bop) {
         Map<String, Object> soapOPProp = new HashMap<String, Object>();
         if (bop.getExtensor(ExtensibilityElement.class) != null) {



Mime
View raw message