Announcement Announcement Module
Collapse
No announcement yet.
Issue with encoding and xml declaration in spring-ws Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with encoding and xml declaration in spring-ws

    Hi.

    I am trying to make a testsetup with a server and client which can send and receive a soap request with the xml encoding = "ISO-8859-1"

    On top of the soapenvelope i would like to have the xml declaration so i add the WRITE_XML_DECLARATION = true to the soapmessage

    But when I receive the request on the server it appears to have been reset somehow.

    The variable reads false in WRITE_XML_DECLARATION and the encoding says utf-8.

    Could anyone tell me what I'm doing wrong?

    The code snippet which sends the request:

    Code:
    TestDataDocument testDataDocument = (TestDataDocument) getWebServiceTemplate().marshalSendAndReceive(testRequestDocument,
    	new WebServiceMessageCallback() {
    		public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
    			SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
    			SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
    
    			try {
    	
    				soapMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "ISO-8859-1");					
    				soapMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
    
    			} catch (Exception exc) {
    				exc.printStackTrace();
    				throw new IOException( exc.getMessage() );
    			}
    		}
    	});
    The spring-ws-servlet.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<bean id="springws.webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
    		<property name="messageSenders">
    			<list>
    	     	<ref bean="httpSender" />
    			</list>
        </property>
    		<property name="marshaller" ref="springws.xmlBeansMarshaller" />
    		<property name="unmarshaller" ref="springws.xmlBeansMarshaller" />
    	</bean>
    
    	<bean id="springws.xmlBeansMarshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller" />
    
    	<!-- Inject timeout -->
    	<bean id="httpParams" class="org.apache.commons.httpclient.params.HttpClientParams">
    		<property name="soTimeout" value="120000" />
      </bean>
    
    	<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
    		<property name="params" ref="httpParams" />
      </bean>
    
      <bean id="httpSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
    		<constructor-arg>
    			<ref bean="httpClient"/>
    		</constructor-arg>
      </bean>
    </beans>
    Server-side

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<bean name="tester.service" class="test.service.TestServiceImpl">
    		<constructor-arg ref="springws.xmlBeansMarshaller" />
    	  <constructor-arg ref="springws.xmlBeansMarshaller" />
    	</bean>
    
    	<bean id="springws.xmlBeansMarshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller" />
    
    	<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    		<property name="mappings">
    			<props>
    				<prop key="{someuri}TestData">tester.service</prop>
    			</props>
    		</property>
    		<property name="interceptors">
    			<bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
    		</property>
    	</bean>
    </beans>
    I have extended my own ownAbstractMarshallingPayloadEndpoint so I can get the messageContext and write the soapenvelope to a file as this:

    Code:
    	...
    	
        public final void invoke(MessageContext messageContext) throws Exception {
          WebServiceMessage request = messageContext.getRequest();
    
    			OutputStream outputStream = new FileOutputStream("c:\\soapenvelope.txt");
    
    			// Write to file
          request.writeTo(outputStream);
    
          Object requestObject = unmarshalRequest(request);
          if(onUnmarshalRequest(messageContext, requestObject)) {
    				Object responseObject = invokeInternal(requestObject);
            
            if(responseObject != null) {
    					WebServiceMessage response = messageContext.getResponse();
              marshalResponse(responseObject, response);
              onMarshalResponse(messageContext, requestObject, responseObject);
            }
          }
        }
    Thanks in advance
Working...
X