java - SOAP client basic auth: HTTP response '401: Unauthorized' -


i'm trying creat soap client has call server uses http basic authentication. following error:

    org.apache.cxf.interceptor.fault: not send message. @ org.apache.cxf.interceptor.messagesenderinterceptor$messagesenderendinginterceptor.handlemessage(messagesenderinterceptor.java:64) ... caused by: org.apache.cxf.transport.http.httpexception: http response '401: unauthorized' when communicating http://localhost:8080/springmvctest/services/contractservice?wsdl=contractservice.wsdl 

my app-config.xml is:

    <?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"       xmlns:security="http://www.springframework.org/schema/security"       xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xsi:schemalocation="http://www.springframework.org/schema/beans      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd     http://www.springframework.org/schema/security       http://www.springframework.org/schema/security/spring-security-3.1.xsd">        <security:http auto-config="true">           <security:intercept-url pattern="/services/*"/>           <security:http-basic/>       </security:http>        <security:authentication-manager>        <security:authentication-provider>            <security:user-service>            <security:user name="wsuser1" password="pw123" authorities="wsuser" />            </security:user-service>        </security:authentication-provider>     </security:authentication-manager>      <bean id="client" class="hu.bz.ikti.insurance.service.insurer.contractservice"         factory-bean="clientfactory" factory-method="create"/>      <bean id="clientfactory" class="org.apache.cxf.jaxws.jaxwsproxyfactorybean">         <property name="serviceclass" value="hu.bz.ikti.insurance.service.insurer.contractservice"/>         <property name="address" value="http://localhost:8080/springmvctest/services/contractservice?wsdl=contractservice.wsdl"/>     </bean>  </beans> 

the http basic auth configured in servers web.xml:

   <security-constraint>       <web-resource-collection>         <url-pattern>/services/*</url-pattern>       </web-resource-collection>       <auth-constraint>         <role-name>wsuser</role-name>       </auth-constraint>     </security-constraint>     <login-config>       <auth-method>basic</auth-method>     </login-config>     <security-role>       <role-name>webservice</role-name>     </security-role> 

in tomcat-users.xml user added:

<user username="wsuser1" password="pw123" roles="wsuser"/> 

i can open wsdl in browser giving username/password. can cause 401: unauthorized error in client?

according cxf documentation here:

https://cxf.apache.org/docs/jax-ws-configuration.html (see configuring spring client (option 2))

the correct way set username , password using username , password properties in clientfactory bean configuration.

so add these inside clientfactory bean:

<property name="username" value="yourusername"/> <property name="password" value="yourpassword"/> 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -