Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic authentication in a Spring Ws Client

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

like image 380
user1611418 Avatar asked Dec 19 '25 00:12

user1611418


1 Answers

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>
like image 80
artbristol Avatar answered Dec 20 '25 16:12

artbristol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!