Вопрос

I am using Spring WebServiceTemplate in my client side code to send request to an existing 3rd party web service.

<bean id="vehicleQuotationWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
    <constructor-arg ref="messageFactory"/>
    <property name="marshaller" ref="vehicleQuotationMarshaller" />
    <property name="unmarshaller" ref="vehicleQuotationMarshaller" />
    <property name="faultMessageResolver" ref="vehicleServiceClientFaultMessageResolver" />
    <property name="defaultUri" value="http://localhost:8080/quote/endpoints"/>
</bean>

Everything was working fine until they added security check from the server side. Right now, in order to pass the server side security authenication, I need to pass some values from a cookie to the server. This I can do easily in SoapUI by modifying the http header (adding the cookie's value there), but my question is how can I do it in Java code with the Spring's WebServiceTemplate?

enter image description here

Это было полезно?

Решение

You can extend the WebServiceTemplate or in a more easy way use a custom sender who extends Spring's

org.springframework.ws.transport.http.CommonsHttpMessageSender

and set in your bean definition

<bean id="vehicleQuotationWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
    <constructor-arg ref="messageFactory"/>
    <property name="marshaller" ref="vehicleQuotationMarshaller" />
    <property name="unmarshaller" ref="vehicleQuotationMarshaller" />
    <property name="faultMessageResolver" ref="vehicleServiceClientFaultMessageResolver" />
    <property name="defaultUri" value="http://localhost:8080/quote/endpoints"/>
    <property name="messageSender">
        <bean class="org.springframework.ws.transport.http.MyHttpComponentsMessageSender"/>
    </property>
</bean>

take a look at Spring forums

JSESSIONID and setting cookie for WebServiceTemplate

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top