camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-10429 - CXFRS client requires Exchange.HTTP_URI instead of HTTP_PATH for Camel tranport
Date Sat, 05 Nov 2016 12:09:59 GMT
CAMEL-10429 - CXFRS client requires Exchange.HTTP_URI instead of HTTP_PATH for Camel tranport


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c69e59a3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c69e59a3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c69e59a3

Branch: refs/heads/camel-2.18.x
Commit: c69e59a3bb02a287d24a23783203bf5a0effd0d5
Parents: 3893465
Author: Tadayoshi Sato <sato.tadayoshi@gmail.com>
Authored: Sat Nov 5 16:49:01 2016 +0900
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Nov 5 13:09:47 2016 +0100

----------------------------------------------------------------------
 .../cxf/common/header/CxfHeaderHelper.java      | 117 ++++++++++++-------
 .../cxf/transport/CamelDestination.java         |   2 +-
 .../cxf/transport/CamelOutputStream.java        |   4 +-
 .../cxf/common/header/CxfHeaderHelperTest.java  |  10 +-
 .../common/message/CxfMessageHelperTest.java    | 115 ++++++++++++++++++
 .../cxf/common/message/RequestBody.xml          |   1 +
 .../camel/component/cxf/DefaultCxfBinding.java  |   4 +-
 .../cxf/jaxrs/DefaultCxfRsBinding.java          |  10 +-
 .../camel/component/cxf/util/CxfUtils.java      |  34 ------
 .../cxf/util/CxfMessageHelperTest.java          | 116 ------------------
 .../cxf/transport/CxfRsCamelTransport.xml       |   5 -
 .../camel/component/cxf/util/RequestBody.xml    |   1 -
 12 files changed, 201 insertions(+), 218 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
index f5099ab..a72e2a8 100644
--- a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
+++ b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
@@ -88,71 +88,100 @@ public final class CxfHeaderHelper {
         }
     }
 
-    public static void propagateCxfToCamel(HeaderFilterStrategy strategy,
-            Message message, Map<String, Object> headers, Exchange exchange) {
+    /**
+     * Propagates CXF headers to Camel message.
+     *
+     * @param strategy header filter strategy
+     * @param cxfMessage CXF message
+     * @param camelMessage Camel message
+     * @param exchange provides context for filtering
+     */
+    public static void propagateCxfToCamel(HeaderFilterStrategy strategy, Message cxfMessage,
+            org.apache.camel.Message camelMessage, Exchange exchange) {
 
         if (strategy == null) {
             return;
         }
 
+        // Copy the CXF HTTP headers to the camel headers
+        copyHttpHeadersFromCxfToCamel(strategy, cxfMessage, camelMessage, exchange);
+
         // Copy the CXF protocol headers to the camel headers
         Map<String, List<String>> cxfHeaders =
-            CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+            CastUtils.cast((Map<?, ?>) cxfMessage.get(Message.PROTOCOL_HEADERS));
         if (cxfHeaders != null) {
             for (Map.Entry<String, List<String>> entry : cxfHeaders.entrySet())
{
                 if (!strategy.applyFilterToExternalHeaders(entry.getKey(), entry.getValue(),
exchange)) {
                     List<String> values = entry.getValue();
-                    //headers.put(entry.getKey(), entry.getValue().get(0));
-                    Object evalue;
-                    if (values.size() > 1) {
-                        if (exchange.getProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED,
Boolean.FALSE, Boolean.class)) {
-                            StringBuilder sb = new StringBuilder();
-                            for (Iterator<String> it = values.iterator(); it.hasNext();)
{
-                                sb.append(it.next());
-                                if (it.hasNext()) {
-                                    sb.append(',').append(' ');
-                                }
-                            }
-                            evalue = sb.toString();
-                        } else {
-                            evalue = values;
-                        }
-                    } else {
-                        evalue = values.get(0);
-                    }
-                    headers.put(entry.getKey(), evalue);
+                    camelMessage.setHeader(entry.getKey(), protocolHeaderValuesToSingleValue(values,
exchange));
                 }
             }
         }
 
-        // propagate content type with the encoding information
-        // We need to do it as the CXF does this kind of thing in transport level
-        String key = Message.CONTENT_TYPE;
-        Object value = determineContentType(message);
+        // propagate request context
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Client.REQUEST_CONTEXT);
+
+        // propagate response context
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Client.RESPONSE_CONTEXT);
         
-        if (value != null && !strategy.applyFilterToExternalHeaders(key, value, exchange))
{
-            headers.put(Exchange.CONTENT_TYPE, value);
+        // propagate response code
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Message.RESPONSE_CODE,
Exchange.HTTP_RESPONSE_CODE);
+    }
+
+    private static Object protocolHeaderValuesToSingleValue(List<String> values, Exchange
exchange) {
+        if (values.size() < 2) {
+            return values.get(0);
         }
+        if (!exchange.getProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.FALSE,
Boolean.class)) {
+            return values;
+        }
+        StringBuilder sb = new StringBuilder();
+        Iterator<String> it = values.iterator();
+        while (it.hasNext()) {
+            sb.append(it.next());
+            if (it.hasNext()) {
+                sb.append(',').append(' ');
+            }
+        }
+        return sb.toString();
+    }
 
-        // propagate request context
-        key = Client.REQUEST_CONTEXT;
-        value = message.get(key);
-        if (value != null && !strategy.applyFilterToExternalHeaders(key, value, exchange))
{
-            headers.put(key, value);
+    public static void copyHttpHeadersFromCxfToCamel(HeaderFilterStrategy strategy, Message
cxfMessage,
+            org.apache.camel.Message camelMessage, Exchange exchange) {
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Message.REQUEST_URI,
Exchange.HTTP_URI);
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Message.HTTP_REQUEST_METHOD,
Exchange.HTTP_METHOD);
+
+        // We need remove the BASE_PATH from the PATH_INFO
+        String pathInfo = (String) cxfMessage.get(Message.PATH_INFO);
+        String basePath = (String) cxfMessage.get(Message.BASE_PATH);
+        if (pathInfo != null && basePath != null && pathInfo.startsWith(basePath))
{
+            pathInfo = pathInfo.substring(basePath.length());
+        }
+        if (pathInfo != null) {
+            camelMessage.setHeader(Exchange.HTTP_PATH, pathInfo);
         }
 
-        // propagate response context
-        key = Client.RESPONSE_CONTEXT;
-        value = message.get(key);
-        if (value != null && !strategy.applyFilterToExternalHeaders(key, value, exchange))
{
-            headers.put(key, value);
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Message.CONTENT_TYPE,
Exchange.CONTENT_TYPE);
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Message.ENCODING,
Exchange.HTTP_CHARACTER_ENCODING);
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Message.QUERY_STRING,
Exchange.HTTP_QUERY);
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, Message.ACCEPT_CONTENT_TYPE,
Exchange.ACCEPT_CONTENT_TYPE);
+    }
+
+    private static void copyMessageHeader(HeaderFilterStrategy strategy, Exchange exchange,
+            Message cxfMessage, org.apache.camel.Message camelMessage, String key) {
+        copyMessageHeader(strategy, exchange, cxfMessage, camelMessage, key, key);
+    }
+
+    private static void copyMessageHeader(HeaderFilterStrategy strategy, Exchange exchange,
+            Message cxfMessage, org.apache.camel.Message camelMessage, String cxfKey, String
camelKey) {
+        Object value = cxfMessage.get(cxfKey);
+        if (Message.CONTENT_TYPE.equals(cxfKey)) {
+            // propagate content type with the encoding information
+            // We need to do it as the CXF does this kind of thing in transport level
+            value = determineContentType(cxfMessage);
         }
-        
-        // propagate response code
-        key = Message.RESPONSE_CODE;
-        value = message.get(key);
-        if (value != null && !strategy.applyFilterToExternalHeaders(key, value, exchange))
{
-            headers.put(Exchange.HTTP_RESPONSE_CODE, value);
+        if (value != null && !strategy.applyFilterToExternalHeaders(cxfKey, value,
exchange)) {
+            camelMessage.setHeader(camelKey, value);
         }
     }
     

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
index 16a3e5b..007d994 100644
--- a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
+++ b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
@@ -253,7 +253,7 @@ public class CamelDestination extends AbstractDestination implements Configurabl
         // copy the camel in message header to the out message
         camelExchange.getOut().getHeaders().putAll(camelExchange.getIn().getHeaders());
         CxfHeaderHelper.propagateCxfToCamel(headerFilterStrategy, outMessage,
-                                            camelExchange.getOut().getHeaders(), camelExchange);
+                                            camelExchange.getOut(), camelExchange);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelOutputStream.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelOutputStream.java
b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelOutputStream.java
index 06ffcb8..68d88ca 100644
--- a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelOutputStream.java
+++ b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelOutputStream.java
@@ -89,7 +89,7 @@ class CamelOutputStream extends CachedOutputStream {
         exchange.setProperty(Exchange.TO_ENDPOINT, this.targetCamelEndpointUri);
         CachedOutputStream outputStream = (CachedOutputStream) outMessage.getContent(OutputStream.class);
         // Send out the request message here, copy the protocolHeader back
-        CxfHeaderHelper.propagateCxfToCamel(this.headerFilterStrategy, outMessage, exchange.getIn().getHeaders(),
exchange);
+        CxfHeaderHelper.propagateCxfToCamel(this.headerFilterStrategy, outMessage, exchange.getIn(),
exchange);
 
         // TODO support different encoding
         exchange.getIn().setBody(outputStream.getInputStream());
@@ -173,4 +173,4 @@ class CamelOutputStream extends CachedOutputStream {
     }
     
     
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
index 5c84f6b..9d80955 100755
--- a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
+++ b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
@@ -82,11 +82,11 @@ public class CxfHeaderHelperTest extends Assert {
         cxfHeaders.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
         cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, cxfHeaders);
         cxfMessage.put(Message.RESPONSE_CODE, "200");
-        
-        Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
+
         CxfHeaderHelper.propagateCxfToCamel(new DefaultHeaderFilterStrategy(), 
-                                            cxfMessage, camelHeaders, exchange);
+                                            cxfMessage, exchange.getIn(), exchange);
 
+        Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
         assertEquals("urn:hello:world", camelHeaders.get("soapaction"));
         assertEquals("urn:hello:world", camelHeaders.get("SoapAction"));
         assertEquals("241", camelHeaders.get("content-length"));
@@ -106,10 +106,10 @@ public class CxfHeaderHelperTest extends Assert {
         cxfHeaders.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
         cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, cxfHeaders);
 
-        Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
         CxfHeaderHelper.propagateCxfToCamel(new DefaultHeaderFilterStrategy(), 
-                                            cxfMessage, camelHeaders, exchange);
+                                            cxfMessage, exchange.getIn(), exchange);
 
+        Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
         assertEquals("peach", camelHeaders.get("MyFruitHeader"));
         assertEquals("cappuccino, espresso", camelHeaders.get("MyBrewHeader"));
     } 

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/message/CxfMessageHelperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/message/CxfMessageHelperTest.java
b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/message/CxfMessageHelperTest.java
new file mode 100644
index 0000000..c9ff43c
--- /dev/null
+++ b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/message/CxfMessageHelperTest.java
@@ -0,0 +1,115 @@
+/**
+ * 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.camel.component.cxf.common.message;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.IOHelper;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CxfMessageHelperTest extends Assert {
+    private static final String REQUEST_STRING =
+        "<testMethod xmlns=\"http://camel.apache.org/testService\"/>";
+    private DefaultCamelContext context = new DefaultCamelContext();
+
+    
+    // setup the default context for testing
+    @Test
+    public void testGetCxfInMessage() throws Exception {
+        HeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
+        org.apache.camel.Exchange exchange = new DefaultExchange(context);
+        // String
+        exchange.getIn().setBody("hello world");
+        org.apache.cxf.message.Message message = CxfMessageHelper.getCxfInMessage(
+                headerFilterStrategy, exchange, false);
+        // test message
+        InputStream is = message.getContent(InputStream.class);
+        assertNotNull("The input stream should not be null", is);
+        assertEquals("Don't get the right message", toString(is), "hello world");
+
+        // DOMSource
+        URL request = this.getClass().getResource("RequestBody.xml");
+        File requestFile = new File(request.toURI());
+        FileInputStream inputStream = new FileInputStream(requestFile);
+        XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(inputStream);
+        DOMSource source = new DOMSource(StaxUtils.read(xmlReader));
+        exchange.getIn().setBody(source);
+        message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
+        is = message.getContent(InputStream.class);
+        assertNotNull("The input stream should not be null", is);
+        assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
+
+        // File
+        exchange.getIn().setBody(requestFile);
+        message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
+        is = message.getContent(InputStream.class);
+        assertNotNull("The input stream should not be null", is);
+        assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
+
+        // transport header's case insensitiveness
+        // String
+        exchange.getIn().setBody("hello world");
+        exchange.getIn().setHeader("soapAction", "urn:hello:world");
+        message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
+        // test message
+        Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+        
+        // verify there is no duplicate
+        assertNotNull("The headers must be present", headers);
+        assertTrue("There must be one header entry", headers.size() == 1);
+        
+        // verify the soapaction can be retrieved in case-insensitive ways
+        verifyHeader(headers, "soapaction", "urn:hello:world");
+        verifyHeader(headers, "SoapAction", "urn:hello:world");
+        verifyHeader(headers, "SOAPAction", "urn:hello:world");
+    }
+
+    private void verifyHeader(Map<String, List<String>> headers, String name,
String value) {
+        List<String> values = headers.get(name);
+        assertTrue("The entry must be available", values != null && values.size()
== 1);
+        assertEquals("The value must match", values.get(0), value);
+    }
+
+    private String toString(InputStream is) throws IOException {
+        StringBuilder out = new StringBuilder();
+        CachedOutputStream os = new CachedOutputStream();
+        IOHelper.copy(is, os);
+        is.close();
+        os.writeCacheTo(out);
+        return out.toString();
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf-transport/src/test/resources/org/apache/camel/component/cxf/common/message/RequestBody.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/test/resources/org/apache/camel/component/cxf/common/message/RequestBody.xml
b/components/camel-cxf-transport/src/test/resources/org/apache/camel/component/cxf/common/message/RequestBody.xml
new file mode 100644
index 0000000..1f170f0
--- /dev/null
+++ b/components/camel-cxf-transport/src/test/resources/org/apache/camel/component/cxf/common/message/RequestBody.xml
@@ -0,0 +1 @@
+<testMethod xmlns="http://camel.apache.org/testService"/>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
index bbad18a..de771da 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
@@ -43,8 +43,8 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
+import org.apache.camel.component.cxf.common.header.CxfHeaderHelper;
 import org.apache.camel.component.cxf.common.message.CxfConstants;
-import org.apache.camel.component.cxf.util.CxfUtils;
 import org.apache.camel.component.cxf.util.ReaderInputStream;
 import org.apache.camel.impl.DefaultAttachment;
 import org.apache.camel.spi.HeaderFilterStrategy;
@@ -532,7 +532,7 @@ public class DefaultCxfBinding implements CxfBinding, HeaderFilterStrategyAware
         camelHeaders.put(CxfConstants.CAMEL_CXF_MESSAGE, cxfMessage);
         
         // Copy the http header to CAMEL as we do in camel-cxfrs
-        CxfUtils.copyHttpHeadersFromCxfToCamel(cxfMessage, camelMessage);
+        CxfHeaderHelper.copyHttpHeadersFromCxfToCamel(headerFilterStrategy, cxfMessage, camelMessage,
exchange);
         
         if (cxfHeaders != null) {
             for (Map.Entry<String, List<String>> entry : cxfHeaders.entrySet())
{

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
index c060734..eb936ff 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
@@ -29,8 +29,8 @@ import javax.ws.rs.core.Response;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.component.cxf.common.header.CxfHeaderHelper;
 import org.apache.camel.component.cxf.common.message.CxfConstants;
-import org.apache.camel.component.cxf.util.CxfUtils;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.camel.util.ExchangeHelper;
@@ -108,7 +108,7 @@ public class DefaultCxfRsBinding implements CxfRsBinding, HeaderFilterStrategyAw
         org.apache.cxf.message.Message cxfMessage = cxfExchange.getInMessage();
         
         // TODO use header filter strategy and cxfToCamelHeaderMap
-        CxfUtils.copyHttpHeadersFromCxfToCamel(cxfMessage, camelMessage);
+        CxfHeaderHelper.copyHttpHeadersFromCxfToCamel(headerFilterStrategy, cxfMessage, camelMessage,
camelExchange);
         
         // setup the charset from content-type header
         setCharsetWithContentType(camelExchange);
@@ -275,12 +275,6 @@ public class DefaultCxfRsBinding implements CxfRsBinding, HeaderFilterStrategyAw
         this.cxfToCamelHeaderMap = cxfToCamelHeaderMap;
     }
     
-    protected void copyMessageHeader(org.apache.cxf.message.Message cxfMessage, Message camelMessage,
String cxfKey, String camelKey) {
-        if (cxfMessage.get(cxfKey) != null) {
-            camelMessage.setHeader(camelKey, cxfMessage.get(cxfKey));
-        }
-    }
-    
     @SuppressWarnings("unchecked")
     protected void copyProtocolHeader(org.apache.cxf.message.Message cxfMessage, Message
camelMessage, Exchange camelExchange) {
         Map<String, List<String>> headers = (Map<String, List<String>>)cxfMessage.get(org.apache.cxf.message.Message.PROTOCOL_HEADERS);

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfUtils.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfUtils.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfUtils.java
index 27edb54..45894fb 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfUtils.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfUtils.java
@@ -29,8 +29,6 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.IOUtils;
@@ -62,38 +60,6 @@ public final class CxfUtils {
         return converter.toString(converter.toDOMSource(writer.getDocument()), null);
     }
     
-    public static void copyHttpHeadersFromCxfToCamel(org.apache.cxf.message.Message cxfMessage,
-                                                     org.apache.camel.Message camelMessage)
{
-        copyMessageHeader(cxfMessage, camelMessage, org.apache.cxf.message.Message.REQUEST_URI,
Exchange.HTTP_URI);
-        
-        copyMessageHeader(cxfMessage, camelMessage, org.apache.cxf.message.Message.HTTP_REQUEST_METHOD,
Exchange.HTTP_METHOD);
-        
-        // We need remove the BASE_PATH from the PATH_INFO
-        String pathInfo = (String)cxfMessage.get(org.apache.cxf.message.Message.PATH_INFO);
-        String basePath = (String)cxfMessage.get(org.apache.cxf.message.Message.BASE_PATH);
-        if (pathInfo != null && basePath != null && pathInfo.startsWith(basePath))
{
-            pathInfo = pathInfo.substring(basePath.length());
-        }
-        if (pathInfo != null) {
-            camelMessage.setHeader(Exchange.HTTP_PATH, pathInfo);
-        }
-        
-        copyMessageHeader(cxfMessage, camelMessage, org.apache.cxf.message.Message.CONTENT_TYPE,
Exchange.CONTENT_TYPE);
-        
-        copyMessageHeader(cxfMessage, camelMessage, org.apache.cxf.message.Message.ENCODING,
Exchange.HTTP_CHARACTER_ENCODING);
-        
-        copyMessageHeader(cxfMessage, camelMessage, org.apache.cxf.message.Message.QUERY_STRING,
Exchange.HTTP_QUERY);
-        
-        copyMessageHeader(cxfMessage, camelMessage, org.apache.cxf.message.Message.ACCEPT_CONTENT_TYPE,
Exchange.ACCEPT_CONTENT_TYPE);
-        
-    }
-    
-    private static void copyMessageHeader(org.apache.cxf.message.Message cxfMessage, Message
camelMessage, String cxfKey, String camelKey) {
-        if (cxfMessage.get(cxfKey) != null) {
-            camelMessage.setHeader(camelKey, cxfMessage.get(cxfKey));
-        }
-    }
-    
     private static void writeElement(Element e,
                                     XMLStreamWriter writer,                             
      
                                     Map<String, String> namespaces)

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfMessageHelperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfMessageHelperTest.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfMessageHelperTest.java
deleted file mode 100644
index cdbdfef..0000000
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfMessageHelperTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * 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.camel.component.cxf.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.dom.DOMSource;
-
-import org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy;
-import org.apache.camel.component.cxf.common.message.CxfMessageHelper;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.impl.DefaultExchange;
-import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.camel.util.IOHelper;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.staxutils.StaxUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class CxfMessageHelperTest extends Assert {
-    private static final String REQUEST_STRING =
-        "<testMethod xmlns=\"http://camel.apache.org/testService\"/>";
-    private DefaultCamelContext context = new DefaultCamelContext();
-
-    
-    // setup the default context for testing
-    @Test
-    public void testGetCxfInMessage() throws Exception {
-        HeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
-        org.apache.camel.Exchange exchange = new DefaultExchange(context);
-        // String
-        exchange.getIn().setBody("hello world");
-        org.apache.cxf.message.Message message = CxfMessageHelper.getCxfInMessage(
-                headerFilterStrategy, exchange, false);
-        // test message
-        InputStream is = message.getContent(InputStream.class);
-        assertNotNull("The input stream should not be null", is);
-        assertEquals("Don't get the right message", toString(is), "hello world");
-
-        // DOMSource
-        URL request = this.getClass().getResource("RequestBody.xml");
-        File requestFile = new File(request.toURI());
-        FileInputStream inputStream = new FileInputStream(requestFile);
-        XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(inputStream);
-        DOMSource source = new DOMSource(StaxUtils.read(xmlReader));
-        exchange.getIn().setBody(source);
-        message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
-        is = message.getContent(InputStream.class);
-        assertNotNull("The input stream should not be null", is);
-        assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
-
-        // File
-        exchange.getIn().setBody(requestFile);
-        message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
-        is = message.getContent(InputStream.class);
-        assertNotNull("The input stream should not be null", is);
-        assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
-
-        // transport header's case insensitiveness
-        // String
-        exchange.getIn().setBody("hello world");
-        exchange.getIn().setHeader("soapAction", "urn:hello:world");
-        message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
-        // test message
-        Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
-        
-        // verify there is no duplicate
-        assertNotNull("The headers must be present", headers);
-        assertTrue("There must be one header entry", headers.size() == 1);
-        
-        // verify the soapaction can be retrieved in case-insensitive ways
-        verifyHeader(headers, "soapaction", "urn:hello:world");
-        verifyHeader(headers, "SoapAction", "urn:hello:world");
-        verifyHeader(headers, "SOAPAction", "urn:hello:world");
-    }
-
-    private void verifyHeader(Map<String, List<String>> headers, String name,
String value) {
-        List<String> values = headers.get(name);
-        assertTrue("The entry must be available", values != null && values.size()
== 1);
-        assertEquals("The value must match", values.get(0), value);
-    }
-
-    private String toString(InputStream is) throws IOException {
-        StringBuilder out = new StringBuilder();
-        CachedOutputStream os = new CachedOutputStream();
-        IOHelper.copy(is, os);
-        is.close();
-        os.writeCacheTo(out);
-        return out.toString();
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/transport/CxfRsCamelTransport.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/transport/CxfRsCamelTransport.xml
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/transport/CxfRsCamelTransport.xml
index 02b5027..1c7de85 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/transport/CxfRsCamelTransport.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/transport/CxfRsCamelTransport.xml
@@ -51,14 +51,9 @@
             <setHeader headerName="Content-Type">
                 <constant>text/plain</constant>
             </setHeader>
-            <setHeader headerName="CamelHttpUri">
-                <simple>/greeting/hello/${body}</simple>
-            </setHeader>
-            <!-- doesn't work for Camel tranport
             <setHeader headerName="CamelHttpPath">
                 <simple>/greeting/hello/${body}</simple>
             </setHeader>
-            -->
             <setHeader headerName="CamelHttpMethod">
                 <constant>GET</constant>
             </setHeader>

http://git-wip-us.apache.org/repos/asf/camel/blob/c69e59a3/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/RequestBody.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/RequestBody.xml
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/RequestBody.xml
deleted file mode 100644
index 1f170f0..0000000
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/RequestBody.xml
+++ /dev/null
@@ -1 +0,0 @@
-<testMethod xmlns="http://camel.apache.org/testService"/>
\ No newline at end of file


Mime
View raw message