Question

Could anyone guide me on how to add Basic Http authentication when using Spring WS , namely the WebserviceTemplate class for writing a Web Service CLient?

Thanks

Was it helpful?

Solution

You need to set the messageSender to use Commons HTTP. See here http://static.springsource.org/spring-ws/site/reference/html/client.html

<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
    <constructor-arg ref="messageFactory"/>
    <property name="messageSender">
        <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
            <property name="credentials">
                <bean class="org.apache.commons.httpclient.UsernamePasswordCredentials">
                    <constructor-arg value="john"/>
                    <constructor-arg value="secret"/>
                </bean>
            </property>
        </bean>
    </property>
    <property name="defaultUri" value="http://example.com/WebService"/>
</bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top