title: SOAP client basic auth: HTTP response '401: Unauthorized'
body: <p>I'm trying to creat a SOAP client that has to call a server that uses http basic authentication.
  I get the following error:</p>
  
  <pre><code>    org.apache.cxf.interceptor.Fault: Could not send Message.
  at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
  ...
  Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '401: Unauthorized' when communicating with http://localhost:8080/SpringMVCTest/services/ContractService?wsdl=ContractService.wsdl
  </code></pre>
  
  <p>My app-config.xml is:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;  
  
      &lt;security:http auto-config="true"&gt;  
          &lt;security:intercept-url pattern="/services/*"/&gt;  
          &lt;security:http-basic/&gt;  
      &lt;/security:http&gt;  
  
      &lt;security:authentication-manager&gt;
         &lt;security:authentication-provider&gt;
             &lt;security:user-service&gt;
             &lt;security:user name="wsuser1" password="pw123" authorities="wsuser" /&gt;
             &lt;/security:user-service&gt;
         &lt;/security:authentication-provider&gt;
      &lt;/security:authentication-manager&gt;
  
      &lt;bean id="client" class="hu.bz.ikti.insurance.service.insurer.ContractService"
          factory-bean="clientFactory" factory-method="create"/&gt;
  
      &lt;bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"&gt;
          &lt;property name="serviceClass" value="hu.bz.ikti.insurance.service.insurer.ContractService"/&gt;
          &lt;property name="address" value="http://localhost:8080/SpringMVCTest/services/ContractService?wsdl=ContractService.wsdl"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>The http basic auth is configured in the servers web.xml:</p>
  
  <pre><code>   &lt;security-constraint&gt;  
      &lt;web-resource-collection&gt;  
        &lt;url-pattern&gt;/services/*&lt;/url-pattern&gt;  
      &lt;/web-resource-collection&gt;  
      &lt;auth-constraint&gt;  
        &lt;role-name&gt;wsuser&lt;/role-name&gt;  
      &lt;/auth-constraint&gt;  
    &lt;/security-constraint&gt;  
    &lt;login-config&gt;  
      &lt;auth-method&gt;BASIC&lt;/auth-method&gt;  
    &lt;/login-config&gt;  
    &lt;security-role&gt;  
      &lt;role-name&gt;webservice&lt;/role-name&gt;  
    &lt;/security-role&gt;
  </code></pre>
  
  <p>In tomcat-users.xml the user is added: </p>
  
  <pre><code>&lt;user username="wsuser1" password="pw123" roles="wsuser"/&gt;
  </code></pre>
  
  <p>I can open the wsdl in the browser giving username/password.
  What can cause this 401: Unauthorized error in the client?</p>