[
https://issues.apache.org/jira/browse/CAMEL-12575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16564873#comment-16564873
]
ASF GitHub Bot commented on CAMEL-12575:
----------------------------------------
oscerd closed pull request #2446: CAMEL-12575:NPE on GET request with
Content-Type header
URL: https://github.com/apache/camel/pull/2446
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 0ecfd7b4972..1ae15e91fe3 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
@@ -40,6 +40,7 @@
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.spi.HeaderFilterStrategyAware;
import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.ObjectHelper;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.HttpHeaderHelper;
import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -92,8 +93,10 @@ public Object populateCxfRsResponseFromExchange(Exchange
camelExchange,
if
(response.getHeader(org.apache.cxf.message.Message.PROTOCOL_HEADERS) != null) {
Map<String, Object> headers = CastUtils.cast((Map<?,
?>)response.getHeader(org.apache.cxf.message.Message.PROTOCOL_HEADERS));
-
cxfExchange.getOutMessage().putIfAbsent(org.apache.cxf.message.Message.PROTOCOL_HEADERS,
+ if (!ObjectHelper.isEmpty(cxfExchange) &&
!ObjectHelper.isEmpty(cxfExchange.getOutMessage())) {
+
cxfExchange.getOutMessage().putIfAbsent(org.apache.cxf.message.Message.PROTOCOL_HEADERS,
new
TreeMap<>(String.CASE_INSENSITIVE_ORDER));
+ }
final Map<String, List<String>> cxfHeaders =
CastUtils.cast((Map<?, ?>)
cxfExchange.getOutMessage().get(org.apache.cxf.message.Message.PROTOCOL_HEADERS));
@@ -113,8 +116,10 @@ public Object populateCxfRsResponseFromExchange(Exchange
camelExchange,
cxfExchange.put(org.apache.cxf.message.Message.RESPONSE_CODE,
response.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class));
}
if (response.getHeader(Exchange.CONTENT_TYPE) != null) {
-
cxfExchange.getOutMessage().putIfAbsent(org.apache.cxf.message.Message.PROTOCOL_HEADERS,
+ if (!ObjectHelper.isEmpty(cxfExchange) &&
!ObjectHelper.isEmpty(cxfExchange.getOutMessage())) {
+
cxfExchange.getOutMessage().putIfAbsent(org.apache.cxf.message.Message.PROTOCOL_HEADERS,
new
TreeMap<>(String.CASE_INSENSITIVE_ORDER));
+ }
final Map<String, List<String>> cxfHeaders =
CastUtils.cast((Map<?, ?>)
cxfExchange.getOutMessage().get(org.apache.cxf.message.Message.PROTOCOL_HEADERS));
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> camel-cxfrs: NPE on GET request with Content-Type header
> --------------------------------------------------------
>
> Key: CAMEL-12575
> URL: https://issues.apache.org/jira/browse/CAMEL-12575
> Project: Camel
> Issue Type: Bug
> Components: camel-cxfrs
> Affects Versions: 2.21.1
> Reporter: Chris Ribble
> Assignee: Ramu
> Priority: Major
> Fix For: 2.21.3, 2.22.1, 2.23.0
>
>
> This commit
> [https://github.com/apache/camel/commit/e4ad40f2eebb68cfde175b171538e26b278f63f6]
> modified DefaultCxfRsBinding.populateCxfRsResponseFromExchange in a way that
> causes an NPE on line #116 when a GET request is made with the Content-Type
> header set. Since Camel copies the request headers into the response, this
> causes the check for Content-Type to find the header and the code after that
> assumes that cxfExchange.getOutMessage() is non-null.
> I can work around this by asking clients not to send the Content-Type header
> (which is generally meaningless for a GET), but I cannot force them not to
> send it. I think I can also add header filtering before the endpoint is
> executed to strip the Content-Type header for GET requests, but ideally
> DefaultCxfRsBinding.populateCxfRsResponseFromExchange would not call
> cxfExchange.getOutMessage().putIfAbsent if getOutMessage returns null.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)