cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r551502 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/ rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apach...
Date Thu, 28 Jun 2007 08:27:45 GMT
Author: ffang
Date: Thu Jun 28 01:27:43 2007
New Revision: 551502

URL: http://svn.apache.org/viewvc?view=rev&rev=551502
Log:
[CXF-741] get post invoke working for DataSource Provider

Added:
    incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData
Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java?view=diff&rev=551502&r1=551501&r2=551502
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java Thu
Jun 28 01:27:43 2007
@@ -42,6 +42,7 @@
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
@@ -349,5 +350,13 @@
         }
 
         return new QName(ns, localName, prefix);        
+    }
+    
+    public static Node  fromSource(Source src) throws Exception {
+
+        Transformer trans = TransformerFactory.newInstance().newTransformer();
+        DOMResult res = new DOMResult();
+        trans.transform(src, res);
+        return res.getNode();
     }
 }

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java?view=diff&rev=551502&r1=551501&r2=551502
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
Thu Jun 28 01:27:43 2007
@@ -38,12 +38,17 @@
 
 public class XMLBindingFactory extends AbstractBindingFactory {
 
+    public static final String XML_PARSER_DISABLED = "xml.parser.disabled";
+    public static final String ATTACHMENT_PARSER_DISABLED = "xml.parser.disabled";
+    
     public Binding createBinding(BindingInfo binding) {
         XMLBinding xb = new XMLBinding(binding);
-        
-        xb.getInInterceptors().add(new AttachmentInInterceptor());
-        xb.getInInterceptors().add(new StaxInInterceptor());
-        
+        if (!Boolean.TRUE.equals(binding.getProperty(ATTACHMENT_PARSER_DISABLED))) {
+            xb.getInInterceptors().add(new AttachmentInInterceptor());
+        }
+        if (!Boolean.TRUE.equals(binding.getProperty(XML_PARSER_DISABLED))) {
+            xb.getInInterceptors().add(new StaxInInterceptor());
+        }
         xb.getInFaultInterceptors().add(new XMLFaultInInterceptor());
         
         xb.getOutInterceptors().add(new StaxOutInterceptor());

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java?view=diff&rev=551502&r1=551501&r2=551502
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
Thu Jun 28 01:27:43 2007
@@ -22,6 +22,7 @@
 
 import java.util.List;
 
+import javax.activation.DataSource;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.handler.Handler;
@@ -31,6 +32,7 @@
 import org.apache.cxf.binding.soap.Soap12;
 import org.apache.cxf.binding.soap.SoapBindingFactory;
 import org.apache.cxf.binding.soap.model.SoapBindingInfo;
+import org.apache.cxf.binding.xml.XMLBindingFactory;
 import org.apache.cxf.common.injection.ResourceInjector;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.frontend.ServerFactoryBean;
@@ -132,6 +134,10 @@
                 && messageMode
                 && !implInfo.getProviderParameterType().equals(SOAPMessage.class))
{
                 bindingInfo.setProperty(SoapBindingFactory.MESSAGE_PROCESSING_DISABLED, Boolean.TRUE);
+            }
+            if (implInfo.getProviderParameterType().equals(DataSource.class)) {
+                bindingInfo.setProperty(XMLBindingFactory.XML_PARSER_DISABLED, Boolean.TRUE);
+                bindingInfo.setProperty(XMLBindingFactory.ATTACHMENT_PARSER_DISABLED, Boolean.TRUE);
             }
         }
             

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java?view=diff&rev=551502&r1=551501&r2=551502
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java
Thu Jun 28 01:27:43 2007
@@ -18,9 +18,13 @@
  */
 package org.apache.cxf.jaxws.interceptors;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.activation.DataSource;
+import javax.mail.util.ByteArrayDataSource;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamReader;
 
@@ -48,9 +52,14 @@
         this.type = type;
     }
 
+    public Class getType() {
+        return type;
+    }
+    
     public void handleMessage(Message message) throws Fault {
         Exchange ex = message.getExchange();
         Endpoint e = ex.get(Endpoint.class);
+        
         if (e.getEndpointInfo().getBinding().getOperations().iterator().hasNext()) {
             BindingOperationInfo bop = e.getEndpointInfo().getBinding().getOperations().iterator().next();
             ex.put(BindingOperationInfo.class, bop);
@@ -70,6 +79,13 @@
         if (SOAPMessage.class.equals(type)) {
             SOAPMessage msg = message.getContent(SOAPMessage.class);
             params.add(msg);
+        } else if (DataSource.class.equals(type)) {
+            InputStream is = message.getContent(InputStream.class);
+            try {
+                params.add(new ByteArrayDataSource(is, (String) message.get(Message.CONTENT_TYPE)));
+            } catch (IOException e1) {
+                e1.printStackTrace();
+            }
         } else {
 
             XMLStreamReader r = message.getContent(XMLStreamReader.class);
@@ -92,5 +108,7 @@
         message.setContent(Object.class, params);
 
     }
+    
+    
 
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java?view=diff&rev=551502&r1=551501&r2=551502
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
Thu Jun 28 01:27:43 2007
@@ -39,15 +39,26 @@
         T ret = null;
         if ("GET".equalsIgnoreCase(method)) {
             ret = get(req);
+        }  else if ("POST".equalsIgnoreCase(method)) {
+            ret = post(req);
         }
+
         return ret;
     }
 
-    protected abstract T get(T req);
+    protected  T get(T req) {
+        return req;
+    }
+
     
     public WebServiceContext getWebServiceContext() { 
         return wsContext;
     }
+    
+    protected T post(T req) {
+        return req;
+    }
+
     
     public void publish(String url) { 
         Endpoint ep = Endpoint.create(HTTPBinding.HTTP_BINDING, this);

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java?view=diff&rev=551502&r1=551501&r2=551502
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
Thu Jun 28 01:27:43 2007
@@ -20,6 +20,8 @@
 package org.apache.cxf.systest.provider.datasource;
 
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.util.Properties;
@@ -32,6 +34,11 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.XMLUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -40,31 +47,54 @@
 
     static final Logger LOG = Logger.getLogger(DataSourceProviderTest.class.getName());
     private static final String TEST_URI = "http://localhost:9000/test/foo";
+    private static final String BOUNDARY = "----=_Part_4_701508.1145579811786";
+    private HttpURLConnection conn;
+    private URL url;
 
     @Before 
     public void launchServer() { 
         TestProvider tp = new TestProvider();
         tp.publish(TEST_URI);
+        
     }
     
+    @Before
+    public void createConnection() throws Exception {
+        url = new URL("http://localhost:9000/test/foo");
+        conn = (HttpURLConnection) url.openConnection();
+        conn.setDoOutput(true);
+    }
+
 
     @Test 
     public void invokeOnServer() throws Exception { 
-        URL url = new URL("http://localhost:9000/test/foo");
-        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        url = new URL("http://localhost:9000/test/foo");
+        conn = (HttpURLConnection) url.openConnection();
         printSource(new StreamSource(conn.getInputStream())); 
     }
     
-    public static void main(String[] args) throws Exception {
-
-        URL url = new URL("http://localhost:9000/test/foo");
-        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
-        String header = conn.getHeaderField("WWW-Authenticate");
-        LOG.info("header: " + header);
-        printSource(new StreamSource(conn.getInputStream())); 
+    @Test
+    public void postAttachmentToServer() throws Exception {
+        String contentType = "multipart/related; type=\"text/xml\"; "
+            + "start=\"attachmentData\"; "
+            + "boundary=\"" + BOUNDARY + "\"";
+
+        InputStream in = getClass().getResourceAsStream("/attachmentBinaryData");
+        assertNotNull("could not load test data", in);
+
+        conn.setRequestMethod("POST");
+        conn.addRequestProperty("Content-Type", contentType);
+        OutputStream out = conn.getOutputStream();
+        IOUtils.copy(in, out);
+        out.close();
+
+        Document d = (Document)XMLUtils.fromSource(new StreamSource(conn.getInputStream()));
+        Node n = d.getFirstChild();
+        assertEquals("bodyParts", n.getNodeName());
+        assertEquals("incorrect number of parts received by server", 2, Integer.parseInt(n.getTextContent()));
     }
 
-    private static void printSource(Source source) {
+    private void printSource(Source source) {
         try {
             ByteArrayOutputStream bos = new ByteArrayOutputStream();
             StreamResult sr = new StreamResult(bos);
@@ -79,4 +109,7 @@
             e.printStackTrace();
         }
     }
+    
+    
+
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java?view=diff&rev=551502&r1=551501&r2=551502
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
Thu Jun 28 01:27:43 2007
@@ -20,7 +20,16 @@
 package org.apache.cxf.systest.provider.datasource;
 
 
+/*import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;*/
+import java.util.Properties;
+import java.util.logging.Logger;
+
 import javax.activation.DataSource;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
 import javax.mail.util.ByteArrayDataSource;
 import javax.xml.ws.BindingType;
 import javax.xml.ws.Provider;
@@ -29,12 +38,17 @@
 import javax.xml.ws.WebServiceContext;
 import javax.xml.ws.WebServiceProvider;
 
+//import org.apache.cxf.helpers.IOUtils;
+
+
 
 @WebServiceProvider(serviceName = "ModelProvider")
 @ServiceMode(value = Service.Mode.PAYLOAD)
 @BindingType(value = "http://cxf.apache.org/bindings/xformat")
 public class TestProvider extends AbstractProvider<DataSource> implements Provider<DataSource>
{
 
+    static final Logger LOG = Logger.getLogger(TestProvider.class.getName());
+    
     @javax.annotation.Resource
     public void setWebServiceContext(WebServiceContext wsc) {
         super.setWebServiceContext(wsc);
@@ -44,6 +58,27 @@
     public DataSource invoke(DataSource req) {
         return super.invoke(req); 
     }
+    
+    protected DataSource post(DataSource req) {
+        String msg;
+        try {
+            LOG.info("content type: " + req.getContentType());
+
+            Session session = Session.getDefaultInstance(new Properties());
+            MimeMessage mm = new MimeMessage(session, req.getInputStream());
+                        
+            mm.addHeaderLine("Content-Type:" + req.getContentType());
+            MimeMultipart multipart = (MimeMultipart) mm.getContent();
+            msg = "<bodyParts>" + multipart.getCount() + "</bodyParts>";
+            
+            
+        } catch (Exception e) {
+            e.printStackTrace();
+            msg = "<fail/>";
+        }
+        return new ByteArrayDataSource(msg.getBytes(), "text/xml");
+    }
+
     
     @Override
     protected DataSource get(DataSource req) {

Added: incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData?view=auto&rev=551502
==============================================================================
--- incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData (added)
+++ incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData Thu Jun 28 01:27:43
2007
@@ -0,0 +1,19 @@
+
+------=_Part_4_701508.1145579811786
+Content-Type: text/xml
+Content-ID: <attachmentData>
+
+<foo>
+   <bar baz="wibble"/>
+</foo>
+
+------=_Part_4_701508.1145579811786
+Content-Type: application/base64
+Content-ID: <base64>
+
+TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
+IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
+dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
+dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
+ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=
+



Mime
View raw message