views:

98

answers:

1

I am utilizing spring to do all of the marshalling/unmarshalling of my bean objects (via jaxb2Marshaller/WebServiceTemplate). For debugging purposes, I would like to be able to spit out the request/response XML. Does anyone know if this is possible? Thanks.

A: 

Alternative A: Use a TCP monitor

A TCP/IP monitor does the job very well!

If you're using Eclipse, the TCP/IP monitor view is a very good solution.

With a TCP monitor, you send the client's request to the montior, the monitor prints the request and forwards it to the server. The response is sent back from the server to the monitor. After printing to the monitor's display, the monitor sends the request back to the client.

Alternative B: Use an interceptor

To spit out all messages with errors, you should use Spring WS's validation support.

Config to enable validation on the client side:

<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:8081/ws-demo/account-balance-service" />
    <property name="interceptors">
        <list>
            <ref bean="payloadValidatingInterceptor" />
        </list>
    </property>
</bean>

<bean id="payloadValidatingInterceptor"
          class="org.springframework.ws.client.support
         .interceptor.PayloadValidatingInterceptor">
    <property name="schema"
        value="file:WebContent/WEB-INF/schemas/account-balance-service.xsd" />
    <property name="validateRequest" value="true" />
    <property name="validateResponse" value="true" />
</bean>

You can also add your own interceptor that can do whatever you want with the payload. I have written more about validating on client-side here and server-side here.

Espen
was looking for something to log response/requests when an error has occurred.
wuntee
I added alternative b to answer your comment.
Espen