title: Java (web service - SOAP) - How do I add a SOAP handler on the client side and enable MTOM correct?
body: <p>Java - JDK 1.6.0.7 - WSGEN -version: JAX-WS RI 2.2.3-b01-</p>
  
  <hr>
  
  <p>I have the following problem:</p>
  
  <pre><code>SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding();
  binding.setMTOMEnabled(true);
  
  List&lt;Handler&gt; handlerChain = new ArrayList&lt;Handler&gt;();
  handlerChain.addAll(binding.getHandlerChain());
  handlerChain.add(new MyHandlerSecurity("admin", "admin"));
  binding.setHandlerChain(handlerChain);
  </code></pre>
  
  <p>With this code the SoapHeader is correct, but the attachment is always a inline base64 text.</p>
  
  <pre><code>//List&lt;Handler&gt; handlerChain = new ArrayList&lt;Handler&gt;();
  //handlerChain.addAll(binding.getHandlerChain());
  //handlerChain.add(new MyHandlerSecurity("admin", "admin"));
  //binding.setHandlerChain(handlerChain);
  </code></pre>
  
  <p>When handlerChain is commented out, you will see the attachment as an xop reference, but there is no SoapHeader and thus, the client is not authenticated...</p>
  
  <p>How can I add a handler on the client side and enable MTOM correct?</p>