CAMEL-8253 Fixed the IndexOutOfBoundsException of the DefaultCxfRsBinding
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6968de10 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6968de10 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6968de10 Branch: refs/heads/camel-2.13.x Commit: 6968de1021f82448a1bb799495f60175e787992c Parents: 84f1390 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Sat Jan 17 20:34:13 2015 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Sat Jan 17 21:41:10 2015 +0800 ---------------------------------------------------------------------- .../cxf/jaxrs/DefaultCxfRsBinding.java | 2 +- .../cxf/jaxrs/DefaultCxfRsBindingTest.java | 26 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/6968de10/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 13deace..653fad7 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 @@ -302,7 +302,7 @@ public class DefaultCxfRsBinding implements CxfRsBinding, HeaderFilterStrategyAw for (Map.Entry<String, List<String>>entry : headers.entrySet()) { // just make sure the first String element is not null if (headerFilterStrategy.applyFilterToExternalHeaders(entry.getKey(), entry.getValue(), camelExchange) - || entry.getValue().get(0) == null) { + || entry.getValue().isEmpty()) { LOG.trace("Drop CXF message protocol header: {}={}", entry.getKey(), entry.getValue()); } else { // just put the first String element, as the complex one is filtered http://git-wip-us.apache.org/repos/asf/camel/blob/6968de10/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBindingTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBindingTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBindingTest.java index 40ddb47..2617a37 100644 --- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBindingTest.java +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBindingTest.java @@ -16,10 +16,20 @@ */ package org.apache.camel.component.cxf.jaxrs; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.camel.Exchange; +import org.apache.camel.Message; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.DefaultExchange; +import org.apache.camel.impl.DefaultHeaderFilterStrategy; +import org.apache.camel.impl.DefaultMessage; import org.apache.camel.util.IOHelper; +import org.apache.cxf.message.MessageImpl; import org.junit.Assert; import org.junit.Test; @@ -41,5 +51,21 @@ public class DefaultCxfRsBindingTest extends Assert { charset = IOHelper.getCharsetName(exchange); assertEquals("Get a worng charset name", "UTF-8", charset); } + + @Test + public void testCopyProtocolHeader() { + DefaultCxfRsBinding cxfRsBinding = new DefaultCxfRsBinding(); + cxfRsBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy()); + Exchange exchange = new DefaultExchange(context); + Message camelMessage = new DefaultMessage(); + org.apache.cxf.message.Message cxfMessage = new MessageImpl(); + Map<String, List<String>> headers = new HashMap<String, List<String>>(); + headers.put("emptyList", Collections.EMPTY_LIST); + headers.put("zeroSizeList", new ArrayList<String>(0)); + cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers); + cxfRsBinding.copyProtocolHeader(cxfMessage, camelMessage, exchange); + assertNull("We should get nothing here", camelMessage.getHeader("emptyList")); + assertNull("We should get nothing here", camelMessage.getHeader("zeroSizeList")); + } }