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.

Reply via email to