You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by zouyue735 <zo...@hotmail.com> on 2016/06/06 06:38:02 UTC
Request with no content-type header gets 415 for jaxrs service
Hi, recently I tried to upgrade cxf version from 2.7.0 to 2.7.18 because
of some other issue. But with the newer version, request with no
content type header gets a 415, while in 2.7.0 this is not the case.
I read the code a little, when no content type is set in the
request, JAXRSInInterceptor set the content type to */*, this part is
the same as before
(JAXRSInInterceptor line 128 - 140)
String requestContentType = null;
List<String> ctHeaderValues = protocolHeaders.get(Message.CONTENT_TYPE);
if (ctHeaderValues != null && !ctHeaderValues.isEmpty()) {
requestContentType = ctHeaderValues.get(0);
message.put(Message.CONTENT_TYPE, requestContentType);
}
if (requestContentType == null) {
requestContentType = (String)message.get(Message.CONTENT_TYPE);
if (requestContentType == null) {
requestContentType = MediaType.WILDCARD;
}
}
and with */* content type, our service (consumes application/xml) can be matched.
But after matching, when
(JAXRSInInterceptor line 253)
List params = JAXRSUtils.processParameters(ori, values, message);
in
(JAXRSUtils line 745 - 755)
String contentType = (String)message.get(Message.CONTENT_TYPE);
if (contentType == null) {
org.apache.cxf.common.i18n.Message errorMsg =
new org.apache.cxf.common.i18n.Message("NO_CONTENT_TYPE_SPECIFIED",
BUNDLE,
ori.getHttpMethod());
LOG.fine(errorMsg.toString());
String defaultCt = (String)message.getContextualProperty(DEFAULT_CONTENT_TYPE);
contentType = defaultCt == null ? MediaType.APPLICATION_OCTET_STREAM : defaultCt;
}
the content type is default set to application/octet-stream for next process steps, then a 415 error is thrown.
In version 2.7.0, this part looks like
(JAXRSUtils line 653 - 662)
String contentType = (String)message.get(Message.CONTENT_TYPE);
if (contentType == null) {
org.apache.cxf.common.i18n.Message errorMsg =
new org.apache.cxf.common.i18n.Message("NO_CONTENT_TYPE_SPECIFIED",
BUNDLE,
ori.getHttpMethod());
LOG.fine(errorMsg.toString());
contentType = MediaType.WILDCARD;
}
My question is, is there any reason that this part get changed ? Is the behavior in 2.7.18 the expected behavior ?
--
View this message in context: http://cxf.547215.n5.nabble.com/Request-with-no-content-type-header-gets-415-for-jaxrs-service-tp5769326.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Request with no content-type header gets 415 for jaxrs service
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
Yes, forgot about it, sorry, set it as a contextual property, ex in
jaxrs:server/jaxrs:properties, and it should do it
Cheers, Sergey
On 07/06/16 03:33, zouyue735 wrote:
> Hi
>
> Thanks for replying
>
> I found the jira ticket when this change is added. I noticed that the
> property 'DEFAULT_CONTENT_TYPE' was added together with this change.
>
> private static final String DEFAULT_CONTENT_TYPE =
> "default.content.type";
>
> ....
>
> String defaultCt =
> (String)message.getContextualProperty(DEFAULT_CONTENT_TYPE);
>
> I haven't found other codes referencing this property, would configuring
> this property achieve the same effect ?
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Request-with-no-content-type-header-gets-415-for-jaxrs-service-tp5769326p5769353.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Re: Request with no content-type header gets 415 for jaxrs service
Posted by zouyue735 <zo...@hotmail.com>.
Hi
Thanks for replying
I found the jira ticket when this change is added. I noticed that the
property 'DEFAULT_CONTENT_TYPE' was added together with this change.
private static final String DEFAULT_CONTENT_TYPE =
"default.content.type";
....
String defaultCt =
(String)message.getContextualProperty(DEFAULT_CONTENT_TYPE);
I haven't found other codes referencing this property, would configuring
this property achieve the same effect ?
--
View this message in context: http://cxf.547215.n5.nabble.com/Request-with-no-content-type-header-gets-415-for-jaxrs-service-tp5769326p5769353.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Request with no content-type header gets 415 for jaxrs service
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
Thanks for this analysis
It is a spec requirement that if no CT is available then it is defaulted
to application/octet-stream and it was enforced in later CXF 2.7.x
releases, likely to make it pass some TCK tests which do verify this
spec condition.
Add a CXF in interceptor which will check if CT is available and will
set it to a wildcard or other type as needed.
Thanks, Sergey
On 06/06/16 07:38, zouyue735 wrote:
> Hi, recently I tried to upgrade cxf version from 2.7.0 to 2.7.18 because
> of some other issue. But with the newer version, request with no
> content type header gets a 415, while in 2.7.0 this is not the case.
>
>
> I read the code a little, when no content type is set in the
> request, JAXRSInInterceptor set the content type to */*, this part is
> the same as before
>
> (JAXRSInInterceptor line 128 - 140)
>
> String requestContentType = null;
>
> List<String> ctHeaderValues = protocolHeaders.get(Message.CONTENT_TYPE);
>
> if (ctHeaderValues != null && !ctHeaderValues.isEmpty()) {
>
> requestContentType = ctHeaderValues.get(0);
>
> message.put(Message.CONTENT_TYPE, requestContentType);
>
> }
>
> if (requestContentType == null) {
>
> requestContentType = (String)message.get(Message.CONTENT_TYPE);
>
>
>
> if (requestContentType == null) {
>
> requestContentType = MediaType.WILDCARD;
>
> }
>
> }
>
>
> and with */* content type, our service (consumes application/xml) can be matched.
>
> But after matching, when
>
> (JAXRSInInterceptor line 253)
>
> List params = JAXRSUtils.processParameters(ori, values, message);
>
>
> in
>
> (JAXRSUtils line 745 - 755)
>
> String contentType = (String)message.get(Message.CONTENT_TYPE);
>
>
> if (contentType == null) {
>
> org.apache.cxf.common.i18n.Message errorMsg =
>
> new org.apache.cxf.common.i18n.Message("NO_CONTENT_TYPE_SPECIFIED",
>
> BUNDLE,
>
> ori.getHttpMethod());
>
> LOG.fine(errorMsg.toString());
>
> String defaultCt = (String)message.getContextualProperty(DEFAULT_CONTENT_TYPE);
>
> contentType = defaultCt == null ? MediaType.APPLICATION_OCTET_STREAM : defaultCt;
>
> }
>
>
> the content type is default set to application/octet-stream for next process steps, then a 415 error is thrown.
>
>
> In version 2.7.0, this part looks like
>
> (JAXRSUtils line 653 - 662)
>
> String contentType = (String)message.get(Message.CONTENT_TYPE);
>
>
> if (contentType == null) {
>
> org.apache.cxf.common.i18n.Message errorMsg =
>
> new org.apache.cxf.common.i18n.Message("NO_CONTENT_TYPE_SPECIFIED",
>
> BUNDLE,
>
> ori.getHttpMethod());
>
> LOG.fine(errorMsg.toString());
>
> contentType = MediaType.WILDCARD;
>
> }
>
>
> My question is, is there any reason that this part get changed ? Is the behavior in 2.7.18 the expected behavior ?
>
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Request-with-no-content-type-header-gets-415-for-jaxrs-service-tp5769326.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/