title: Spring Boot SOAP WebService Integration Test with BasicAuth
body: <p>I have a SpringBoot SOAP WebService annotated with @RolesAllowed(&quot;SOME_ROLE&quot;). The production code works correct, i.e. if I send a SOAP-Request with the header &quot;<strong>Authorization: Basic ENCODED_USERNAME_PASSWORD</strong>&quot;, service pass, if this header is not provided, then 401 comes back.</p>
  <p>The problem is with Integration Tests. Below is a code snippet:</p>
  <pre><code>@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  @ActiveProfiles(&quot;test&quot;)
  @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
  @AutoConfigureWebTestClient
  class MyApplicationIT {
      @LocalServerPort
      int randomServerPort;
  
      @Test
      void find() {
          MyServicePortType port = getServicePort();
          port.findResult();
      }
  
  private MyServicePortType getServicePort() {
          final URL wsdlUrl;
          try {
              wsdlUrl = new URL(&quot;http&quot;, &quot;localhost&quot;, randomServerPort, &quot;wsdl/data.wsdl&quot;);
          } catch (MalformedURLException e) {
              throw new RuntimeException(e);
          }
          final MyService service = new MyService (wsdlUrl);
          final QName portName = new QName(&quot;some_url&quot;, &quot;My_PortTypeSoap11&quot;);
          final MyServicePortType port = service.getPort(portName, MyServicePortType .class);
          final Map&lt;String, List&lt;Object&gt;&gt; headers = new HashMap&lt;&gt;();
          headers.put(&quot;Authorization&quot;, singletonList(&quot;Basic &quot; + &quot;ENCODED_USERNAME_PASSWORD&quot;));
          }
          final Map&lt;String, Object&gt; requestContext = ((BindingProvider) port).getRequestContext();
          requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
          // requestContext.put(BindingProvider.USERNAME_PROPERTY, &quot;manager_user_and_test_user&quot;);
          // requestContext.put(BindingProvider.PASSWORD_PROPERTY, &quot;secret&quot;);
          return port;
      }
  }
  </code></pre>
  <p>I have tried out both combinations - to put Authorization header <code>MessageContext.HTTP_REQUEST_HEADERS</code> and to put properties <code>BindingProvider.USERNAME_PROPERTY</code> and <code>BindingProvider.PASSWORD_PROPERTY</code>.</p>
  <p>Both does not work. I always get the following 401 error message.
  Once again - only by running Integration Tests.</p>
  <p>Is this related to wrong client (port) configuration or something to do with ldap schema used for tests?</p>
  <pre><code>rg.apache.cxf.interceptor.Fault: Could not send Message.
      at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:67)
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
      at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:441)
      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:356)
      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:314)
      at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
      at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
      at com.sun.proxy.$Proxy228.findFragebogen(Unknown Source)
      ...
  at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
      at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
      at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
      at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
      at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
      at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
      at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
      at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
      at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
      at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
      at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
      at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
      at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
  Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '401: null' when communicating with http://localhost:37248/ws
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.doProcessResponseCode(HTTPConduit.java:1619)
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1626)
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1571)
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1371)
      at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
      at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:671)
      at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63)
      ... 74 common frames omitted    
  </code></pre>