[SWS-520] HTTP Accept header field contains invalid type, and omits text/xml Created: 25/May/09  Updated: 04/May/12  Resolved: 02/Jun/09

Status: Closed
Project: Spring Web Services
Component/s: Core
Affects Version/s: 1.5.7
Fix Version/s: 1.5.8

Type: Bug Priority: Major
Reporter: Nigel Charman Assignee: Arjen Poutsma
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Spring/WS client,


The Spring-WS client sends an HTTP Accept request-header field that is invalid according to the HTTP 1.1 spec.

The header that the Spring-WS client sends is:

Accept: text/html, image/gif, image/jpeg, ; q=.2, */; q=.2

The fourth media-range in this field does not include the mandatory "/" and subtype.

The definition of the Accept header in the HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) is:

Accept = "Accept" ":"
#( media-range [ accept-params ] )

media-range = ( "/"

( type "/" "*" )
( type "/" subtype )
) *( ";" parameter )

I would have also expected the Accept header field to contain "text/xml" explicitly (for SOAP 1.1), and not to Accept "text/html", "image/gif" or "image/jpeg".

My spring-client-context.xml is:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

<bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
<property name="payloadCaching" value="false" />

<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="marshaller" ref="marshaller" />
<property name="unmarshaller" ref="marshaller" />
<property name="defaultUri" value="http://localhost:8079/jibx-ws-seismic/soap/quake-service" />
<property name="messageFactory" ref="messageFactory"/>

<!-- A JiBX-based payload marshaller/unmarshaller. -->
<bean id="marshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
<property name="targetClass" value="com.sosnoski.seismic.common.Query" />

Comment by Nigel Charman [ 25/May/09 ]

Oops, some of the text got a bit mangled. The Accept header field sent by Spring-WS client is:

Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

and the text from the HTTP spec should read:

       Accept         = "Accept" ":"
                        #( media-range [ accept-params ] )

       media-range    = ( "*/*"
                        | ( type "/" "*" )
                        | ( type "/" subtype )
                        ) *( ";" parameter )

Comment by Arjen Poutsma [ 25/May/09 ]

The Accept header is actually set by the JDK HttpURLConnection, so as a workaround you can inject the CommonsHttpMessageSender into the template, instead of the default HttpUrlConnectionMessageSender.

I'll see whether we can fix this header in 1.5.8

Comment by Nigel Charman [ 25/May/09 ]

The CommonsHttpMessageSender does provide a workaround since it omits the Accept header field . The spec says "If no Accept header field is present, then it is assumed that the client accepts all media types.". I'd suggest that this isn't strictly true, and you may want to consider explicitly setting the Accept types for all the MessageSender implementations.

Thanks for your help.

Comment by Arjen Poutsma [ 02/Jun/09 ]

This is now fixed for Axiom; SAAJ already set the Accept header itself.

Comment by Nigel Charman [ 08/Nov/09 ]

The fix works for me. Thanks

Comment by Arjen Poutsma [ 04/May/12 ]

Closing old issues

Generated at Wed Nov 14 17:26:48 UTC 2018 using JIRA 7.9.2#79002-sha1:3bb15b68ecd99a30eb364c4c1a393359bcad6278.