cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r502283 - in /incubator/cxf/trunk: rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/ rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/ rt/databinding/jaxb/src/test/ja...
Date Thu, 01 Feb 2007 16:55:20 GMT
Author: eglynn
Date: Thu Feb  1 08:55:18 2007
New Revision: 502283

URL: http://svn.apache.org/viewvc?view=rev&rev=502283
Log:
Applying patch for CXF-398 from Sergey Beryozkin.

Added:
    incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/XMLBindingFactoryTest.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentStreamSourceXMLProvider.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/attachmentData
Modified:
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderChainObserver.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletDestination.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
    incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java

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=502283&r1=502282&r2=502283
==============================================================================
--- 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 Feb  1 08:55:18 2007
@@ -30,6 +30,7 @@
 import org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor;
 import org.apache.cxf.binding.xml.interceptor.XMLMessageInInterceptor;
 import org.apache.cxf.binding.xml.interceptor.XMLMessageOutInterceptor;
+import org.apache.cxf.interceptor.AttachmentInInterceptor;
 import org.apache.cxf.interceptor.StaxInInterceptor;
 import org.apache.cxf.interceptor.StaxOutInterceptor;
 import org.apache.cxf.interceptor.URIMappingInterceptor;
@@ -58,8 +59,10 @@
 
         XMLBinding xb = new XMLBinding();
         
+        xb.getInInterceptors().add(new AttachmentInInterceptor());
         xb.getInInterceptors().add(new StaxInInterceptor());
         xb.getInInterceptors().add(new XMLMessageInInterceptor());
+        xb.getInInterceptors().add(new URIMappingInterceptor());
         
         xb.getInFaultInterceptors().add(new XMLFaultInInterceptor());
         
@@ -69,8 +72,6 @@
         xb.getOutFaultInterceptors().add(new StaxOutInterceptor());
         xb.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
         
-        xb.getInInterceptors().add(new URIMappingInterceptor());
-
         return xb;
     }
 

Added: incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/XMLBindingFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/XMLBindingFactoryTest.java?view=auto&rev=502283
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/XMLBindingFactoryTest.java
(added)
+++ incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/XMLBindingFactoryTest.java
Thu Feb  1 08:55:18 2007
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.xml;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.binding.Binding;
+import org.apache.cxf.interceptor.AttachmentInInterceptor;
+import org.apache.cxf.interceptor.Interceptor;
+
+public class XMLBindingFactoryTest extends TestCase {
+    
+    public void testContainsInAttachmentInterceptor() {
+        XMLBindingFactory xbf = new XMLBindingFactory();
+        Binding b = xbf.createBinding(null);
+        
+        boolean found = false;
+        for (Interceptor interseptor : b.getInInterceptors()) {
+            if (interseptor instanceof AttachmentInInterceptor) {
+                found = true;
+            }
+        }
+        
+        assertTrue("No in attachment interceptor found", found);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/XMLBindingFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
Thu Feb  1 08:55:18 2007
@@ -62,13 +62,12 @@
         Object obj = null;
         InputStream is = input.getContent(InputStream.class);
 
+        if (is == null) {
+            // TODO LOG ERROR here
+            return null;
+        } 
         try {
-            // Tolerate empty InputStream in order to deal with HTTP GET
-            if (is == null || is.available() == 0) {
-                // TODO LOG ERROR here
-                return null;
-            }
-
+            
             // Processing Souce type
             if (DOMSource.class.isAssignableFrom(type)) {
                 Document doc = XMLUtils.parse(is);

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
Thu Feb  1 08:55:18 2007
@@ -57,8 +57,6 @@
         assertTrue(XMLUtils.toString((Source)source).contains(expected));
     }
 
-    // XMLMessageDataReader needs to tolerate empty input stream
-    // in order to deal with HTTP GET, no exceptions should be thrown.
     public void testReadEmptyInputStream() throws Exception {
         InputStream is = getTestStream("../resources/emptyReq.xml");
         assertNotNull(is);
@@ -68,6 +66,10 @@
         XMLMessage xmlMsg = new XMLMessage(msg);
 
         Object source = reader.read(null, xmlMsg, DOMSource.class);
+        assertNull(source);
+        
+        msg.setContent(InputStream.class, null);
+        source = reader.read(null, xmlMsg, DOMSource.class);
         assertNull(source);
     }
 

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderChainObserver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderChainObserver.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderChainObserver.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderChainObserver.java
Thu Feb  1 08:55:18 2007
@@ -19,9 +19,13 @@
 
 package org.apache.cxf.jaxws;
 
+import javax.activation.DataSource;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.binding.Binding;
+import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.interceptor.AttachmentInInterceptor;
 import org.apache.cxf.jaxws.interceptors.DispatchInInterceptor;
 import org.apache.cxf.jaxws.interceptors.DispatchOutInterceptor;
 import org.apache.cxf.jaxws.support.JaxWsImplementorInfo;
@@ -52,10 +56,6 @@
         exchange.setInMessage(message);
         message.setExchange(exchange);
 
-        // message.setContent(Class.class, implInfo.getProviderParameterType());
-        // message.setContent(javax.xml.ws.Service.Mode.class,
-        // implInfo.getServiceMode());
-
         exchange.put(javax.xml.ws.Service.Mode.class, implInfo.getServiceMode());
         exchange.put(Class.class, implInfo.getProviderParameterType());
 
@@ -78,6 +78,13 @@
 
         // Modified the binding in interceptors
         endpoint.getBinding().getInInterceptors().clear();
+        
+        Class type = message.getExchange().get(Class.class);
+        if (!DataSource.class.isAssignableFrom(type)
+            && !SoapMessage.class.isAssignableFrom(type)) {
+            endpoint.getBinding().getInInterceptors().add(new AttachmentInInterceptor());
+        }
+        
         endpoint.getBinding().getInInterceptors().add(new DispatchInInterceptor());
         chain.add(endpoint.getBinding().getInInterceptors());
         // Modified the binding out interceptors

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java
Thu Feb  1 08:55:18 2007
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxws.interceptors;
 
 import java.io.InputStream;
+import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
@@ -44,6 +45,8 @@
 
 public class DispatchInInterceptor extends AbstractInDatabindingInterceptor {
 
+    private static final Logger LOG = Logger.getLogger(DispatchInInterceptor.class.getName());
+    
     public DispatchInInterceptor() {
         super();
         setPhase(Phase.READ);
@@ -51,6 +54,12 @@
 
     @SuppressWarnings("unchecked")
     public void handleMessage(Message message) throws Fault {
+        
+        if (isGET(message)) {
+            LOG.info("DispatchInInterceptor skipped in HTTP GET method");
+            return;
+        }
+        
         Service.Mode m = message.getExchange().get(Service.Mode.class);
         Class type = message.getExchange().get(Class.class);
 

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
Thu Feb  1 08:55:18 2007
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxws.interceptors;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import javax.activation.DataSource;
@@ -115,7 +116,9 @@
             transformer.transform((Source)obj, new StreamResult(os));
         }
         if (obj instanceof DataSource) {
+            InputStream is = ((DataSource)obj).getInputStream();
             IOUtils.copy(((DataSource)obj).getInputStream(), os);
+            is.close();
         }
     }
 

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletDestination.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletDestination.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletDestination.java
Thu Feb  1 08:55:18 2007
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
@@ -189,6 +190,26 @@
      * @param headers the current set of headers
      */
     protected void copyResponseHeaders(Message message, HttpServletResponse response) {
+        
+        Map<?, ?> headers = (Map<?, ?>)message.get(Message.PROTOCOL_HEADERS);
+        if (null != headers) {
+            if (!headers.containsKey(Message.CONTENT_TYPE)) {
+                setContentType(message, response);
+            }
+            for (Iterator<?> iter = headers.keySet().iterator(); iter.hasNext();) {
+                String header = (String)iter.next();
+                List<?> headerList = (List<?>)headers.get(header);
+                for (Object value : headerList) {
+                    response.addHeader(header, (String)value);
+                }
+            }
+        } else {
+            setContentType(message, response);
+        }
+        
+    }
+
+    protected void setContentType(Message message, HttpServletResponse response) {
         String ct = (String) message.get(Message.CONTENT_TYPE);
         String enc = (String) message.get(Message.ENCODING);
         
@@ -201,7 +222,6 @@
             response.setContentType("text/xml; charset=" + enc);
         }
     }
-    
     
     
     protected void doMessage(MessageImpl inMessage) throws IOException {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
Thu Feb  1 08:55:18 2007
@@ -18,15 +18,20 @@
  */
 package org.apache.cxf.jaxws.support;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.activation.DataHandler;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.handler.MessageContext;
 
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
+import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 
@@ -129,7 +134,11 @@
         if (null != requestHeaders) {
             ctx.put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
         }       
-               
+
+        addMessageAttachments(ctx, 
+                              exchange.getInMessage(), 
+                              MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+        
         Message outMessage = exchange.getOutMessage();
         if (null != outMessage) {
             Object responseHeaders =
@@ -141,6 +150,26 @@
             ctx.put(MessageContext.HTTP_RESPONSE_HEADERS, responseHeaders);
         }   
         return ctx;
+    }
+    
+    private static void addMessageAttachments(MessageContext ctx,
+                                              Message message,
+                                              String propertyName) {
+        Map<String, DataHandler> dataHandlers = null;
+
+        Collection<Attachment> attachments = message.getAttachments();
+        if (attachments != null) {
+            
+            //preserve the order of iteration
+            dataHandlers = new LinkedHashMap<String, DataHandler>();
+            for (Attachment attachment : attachments) {
+                dataHandlers.put(attachment.getId(), attachment.getDataHandler());
+            }
+        }
+
+        ctx.put(propertyName, 
+                dataHandlers == null ? Collections.EMPTY_MAP
+                                     : Collections.unmodifiableMap(dataHandlers));
     }
     
     public static void updateWebServiceContext(Exchange exchange, MessageContext ctx) {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java
Thu Feb  1 08:55:18 2007
@@ -18,14 +18,20 @@
  */
 package org.apache.cxf.jaxws.support;
 
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.Map;
 
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.handler.MessageContext;
 
 import junit.framework.TestCase;
 
+import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -103,6 +109,10 @@
         Object outMessageHeader = outMessage.get(Message.PROTOCOL_HEADERS);
         assertEquals("the outMessage PROTOCOL_HEADERS should be update", responseHeader,
outMessageHeader);
         
+        Object inAttachments = ctx.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+        assertNotNull("inbound attachments object must be initialized", inAttachments);
+        assertTrue("inbound attachments must be in a Map", inAttachments instanceof Map);
+        assertTrue("no inbound attachments expected", ((Map)inAttachments).isEmpty());
     }
     
     public void testUpdateWebServiceContext() {
@@ -125,4 +135,36 @@
         assertEquals("incorrect response code returned", RESPONSE_CODE, respCode);
     }
 
+    @SuppressWarnings("unchecked")
+    public void testCreateWebServiceContextWithInAttachments() {
+        Exchange exchange = new ExchangeImpl();
+        Message inMessage = new MessageImpl();
+        
+        Collection<Attachment> attachments = new LinkedList<Attachment>();
+
+        DataSource source = EasyMock.createNiceMock(DataSource.class);
+        DataHandler handler1 = new DataHandler(source);
+        attachments.add(new AttachmentImpl("part1", handler1));
+        DataHandler handler2 = new DataHandler(source);
+        attachments.add(new AttachmentImpl("part2", handler2));
+        inMessage.setAttachments(attachments);
+        
+        inMessage.putAll(message);
+        exchange.setInMessage(inMessage);
+        exchange.setOutMessage(new MessageImpl());
+        
+        MessageContext ctx = ContextPropertiesMapping.createWebServiceContext(exchange);
+        
+        Object inAttachments = ctx.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+        assertNotNull("inbound attachments object must be initialized", inAttachments);
+        assertTrue("inbound attachments must be in a Map", inAttachments instanceof Map);
+        Map<String, DataHandler> dataHandlers = (Map)inAttachments;
+        assertEquals("two inbound attachments expected", 2, dataHandlers.size());
+        
+        assertTrue("part1 attachment is missing", dataHandlers.containsKey("part1"));
+        // should do as it's the same instance
+        assertTrue("part1 handler is missing", dataHandlers.get("part1") == handler1);
+        assertTrue("part2 attachment is missing", dataHandlers.containsKey("part2"));
+        assertTrue("part2 handler is missing", dataHandlers.get("part2") == handler2);
+    }
 }

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
Thu Feb  1 08:55:18 2007
@@ -204,10 +204,13 @@
      * @param headers the current set of headers
      */
     protected void copyResponseHeaders(Message message, HttpResponse response) {
-        response.setContentType((String) message.get(Message.CONTENT_TYPE));
-
         Map<?, ?> headers = (Map<?, ?>)message.get(Message.PROTOCOL_HEADERS);
         if (null != headers) {
+            
+            if (!headers.containsKey(Message.CONTENT_TYPE)) {
+                response.setContentType((String) message.get(Message.CONTENT_TYPE));
+            }
+            
             for (Iterator<?> iter = headers.keySet().iterator(); iter.hasNext();) {
                 String header = (String)iter.next();
                 List<?> headerList = (List<?>)headers.get(header);
@@ -215,6 +218,8 @@
                     response.addField(header, (String)value);
                 }
             }
+        } else {
+            response.setContentType((String) message.get(Message.CONTENT_TYPE));
         }
     }
 

Modified: incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java?view=diff&rev=502283&r1=502282&r2=502283
==============================================================================
--- incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
Thu Feb  1 08:55:18 2007
@@ -223,10 +223,13 @@
      * @param headers the current set of headers
      */
     protected void copyResponseHeaders(Message message, HttpServletResponse response) {
-        response.setContentType((String) message.get(Message.CONTENT_TYPE));
-
         Map<?, ?> headers = (Map<?, ?>)message.get(Message.PROTOCOL_HEADERS);
         if (null != headers) {
+            
+            if (!headers.containsKey(Message.CONTENT_TYPE)) {
+                response.setContentType((String) message.get(Message.CONTENT_TYPE));
+            }
+            
             for (Iterator<?> iter = headers.keySet().iterator(); iter.hasNext();) {
                 String header = (String)iter.next();
                 List<?> headerList = (List<?>)headers.get(header);
@@ -234,6 +237,8 @@
                     response.addHeader(header, (String)value);
                 }
             }
+        } else {
+            response.setContentType((String) message.get(Message.CONTENT_TYPE));
         }
     }
 

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java?view=auto&rev=502283
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java
Thu Feb  1 08:55:18 2007
@@ -0,0 +1,122 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.provider;
+
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.ws.Endpoint;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.systest.common.ClientServerSetupBase;
+import org.apache.cxf.systest.common.ClientServerTestBase;
+import org.apache.cxf.systest.common.TestServerBase;
+
+public class AttachmentProviderXMLClientServerTest extends ClientServerTestBase {
+
+    public static class Server extends TestServerBase {
+
+        protected void run() {
+            Object implementor = new AttachmentStreamSourceXMLProvider();
+            String address = "http://localhost:9033/XMLServiceAttachment";
+            Endpoint.publish(address, implementor);
+        }
+
+        public static void main(String[] args) {
+            try {
+                Server s = new Server();
+                s.start();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                System.exit(-1);
+            } finally {
+                System.out.println("done!");
+            }
+        }
+    }
+
+    public static Test suite() throws Exception {
+        TestSuite suite = new TestSuite(AttachmentProviderXMLClientServerTest.class);
+        return new ClientServerSetupBase(suite) {
+            public void startServers() throws Exception {
+                assertTrue("server did not launch correctly",
+                        launchServer(Server.class));
+            }
+        };
+    }
+
+    public void testRequestWithAttachment() throws Exception {
+        
+        HttpURLConnection connection =  
+            (HttpURLConnection)new URL("http://localhost:9033/XMLServiceAttachment").openConnection();
+        connection.setRequestMethod("POST");
+        
+        String ct = "multipart/related; type=\"text/xml\"; " + "start=\"rootPart\"; "
+                    + "boundary=\"----=_Part_4_701508.1145579811786\"";
+        connection.addRequestProperty("Content-Type", ct);
+        
+        connection.setDoOutput(true);
+        
+        InputStream is = getClass().getResourceAsStream("attachmentData");
+        IOUtils.copy(is, connection.getOutputStream());
+        connection.getOutputStream().close();
+        is.close();
+        
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder builder = factory.newDocumentBuilder();
+        assertEquals("wrong content type", "application/xml+custom", connection.getContentType());
+        Document result = builder.parse(connection.getInputStream());
+        assertNotNull("result must not be null", result);
+        
+        connection.getInputStream().close();
+        
+        NodeList resList = result.getDocumentElement().getElementsByTagName("att");
+        assertEquals("Two attachments must've been encoded", 2, resList.getLength());
+        
+        verifyAttachment(resList, "foo", "foobar");
+        verifyAttachment(resList, "bar", "barbaz");
+    }
+
+    private void verifyAttachment(NodeList atts, String contentId, String value) {
+
+        for (int i = 0; i < atts.getLength(); i++) {
+            Element expElem = (Element)atts.item(i);
+            String child = expElem.getFirstChild().getNodeValue();
+            if (contentId.equals(expElem.getAttribute("contentId"))
+                && (Base64Utility.encode(value.getBytes()).equals(child)
+                    || Base64Utility.encode((value + "\n").getBytes()).equals(child))) {
+                return;    
+            }
+        }
+        
+        fail("No encoded attachment with id " + contentId + " found");
+    }
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentStreamSourceXMLProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentStreamSourceXMLProvider.java?view=auto&rev=502283
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentStreamSourceXMLProvider.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentStreamSourceXMLProvider.java
Thu Feb  1 08:55:18 2007
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.cxf.systest.provider;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.activation.DataHandler;
+import javax.annotation.Resource;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Provider;
+import javax.xml.ws.Service;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceProvider;
+import javax.xml.ws.handler.MessageContext;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.message.Message;
+
+@WebServiceProvider(serviceName = "AttachmentStreamSourceXMLProvider")
+@ServiceMode(value = Service.Mode.PAYLOAD)
+@javax.xml.ws.BindingType(value = "http://cxf.apache.org/bindings/xformat")
+public class AttachmentStreamSourceXMLProvider implements Provider<StreamSource> {
+
+    @Resource
+    protected WebServiceContext wsContext;
+    
+    @SuppressWarnings("unchecked")
+    public StreamSource invoke(StreamSource source) {
+        
+        MessageContext mc = wsContext.getMessageContext();
+        
+        String httpMethod = (String)mc.get(MessageContext.HTTP_REQUEST_METHOD);
+        if ("POST".equals(httpMethod)) {
+            
+            int count = 0;
+            // we really want to verify that a root part is a proper XML as expected
+            DOMResult result = new DOMResult();
+            try {
+                Transformer transformer = XMLUtils.newTransformer();
+                transformer.transform(source, result);
+                count = 
+                    Integer.parseInt(((Document)result.getNode()).getDocumentElement().getAttribute("count"));
+            } catch (Exception ex) {
+                // ignore
+            }
+            
+            Map<String, DataHandler> dataHandlers = 
+                (Map)mc.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+            StringBuilder buf = new StringBuilder();
+            buf.append("<response>");
+            int i = 0;
+            for (Map.Entry<String, DataHandler> entry : dataHandlers.entrySet()) {
+                if (i++ > count) {
+                    break;
+                }
+                try {
+                    InputStream is = entry.getValue().getInputStream();
+                    ByteArrayOutputStream bous = new ByteArrayOutputStream();
+                    IOUtils.copy(is, bous);
+            
+                    buf.append("<att contentId=\"" + entry.getKey() + "\">");
+                    buf.append(Base64Utility.encode(bous.toByteArray()));
+                    buf.append("</att>");
+                    
+                } catch (IOException ioe) {
+                    ioe.printStackTrace();
+                }
+            }
+            buf.append("</response>");
+            
+            Map<Object, List<?>> respHeaders = (Map)mc.get(MessageContext.HTTP_RESPONSE_HEADERS);
+            List<String> contentTypeValues = new ArrayList<String>();
+            contentTypeValues.add("application/xml+custom");
+            respHeaders.put(Message.CONTENT_TYPE, contentTypeValues);
+            
+            return new StreamSource(new StringReader(buf.toString()));
+        }
+        return source;
+        
+    }
+
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentStreamSourceXMLProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/attachmentData
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/attachmentData?view=auto&rev=502283
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/attachmentData
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/attachmentData
Thu Feb  1 08:55:18 2007
@@ -0,0 +1,20 @@
+
+------=_Part_4_701508.1145579811786
+Content-Type: text/xml
+Content-ID: <rootPart>
+
+<attachmentRequest count="2"/>
+
+------=_Part_4_701508.1145579811786
+Content-Type: image/jpeg
+Content-Transfer-Encoding: binary
+Content-ID: <foo>
+
+foobar
+------=_Part_4_701508.1145579811786--
+Content-Type: image/jpeg
+Content-Transfer-Encoding: binary
+Content-ID: <bar>
+
+barbaz
+------=_Part_4_701508.1145579811786--
\ No newline at end of file



Mime
View raw message