title: Getting Error in SOAP POST request using Apache CXF but curl works
body: <p>I'm having a very strange problem. I'm trying to do a SOAP POST request over HTTPS. When I'm sending the request from my code, I'm getting HTTP 500 error. Now from the cxf log if I copy the same SOAP message(header and body) that I got error for and post it using a simple curl request it's working fine. Below is how I'm creating service class and other initialization </p>
  
  <pre><code>URL wsdlurl = SOAPWebServiceTransport.class.getClassLoader().
          getResource("my.wsdl");
  OnlinePort service= new OnlinePortService(wsdlurl).getOnlinePortPort();
  Client proxy = ClientProxy.getClient(service);
  
  // Provides WS-Security
  WSS4JOutInterceptor wss4jOut = new WSS4JOutInterceptor();
  wss4jOut.setProperty("action", "UsernameToken");
  wss4jOut.setProperty("user", userName);
  wss4jOut.setProperty("passwordType", "PasswordText");
  wss4jOut.setProperty("password", password);
  wss4jOut.setProperty(WSHandlerConstants.ADD_UT_ELEMENTS,
          WSConstants.NONCE_LN + " " + WSConstants.CREATED_LN);
  wss4jOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, ServerPasswordCallback.class.getName());
  
  proxy.getEndpoint().getOutInterceptors().add(wss4jOut);
  setConduitProperties((HTTPConduit) proxy.getConduit(),url);
  </code></pre>
  
  <p>In the set conduit method I'm ignoring the ssl check (for development env only) and setting some header.</p>
  
  <pre><code>TLSClientParameters tcp = new TLSClientParameters();
  tcp.setDisableCNCheck(true);
  // Creating Trust Manager
  TrustManager[] trustAllCerts = new TrustManager[] {
      new X509TrustManager() {
          public java.security.cert.X509Certificate[] getAcceptedIssuers() {
              return null;
          }
  
          public void checkClientTrusted(
                  java.security.cert.X509Certificate[] certs, String authType) {
          }
  
          public void checkServerTrusted(
                  java.security.cert.X509Certificate[] certs, String authType) {
          }
  } };
  
  tcp.setTrustManagers(trustAllCerts);
  conduit.setTlsClientParameters(tcp);
  
  HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
  httpClientPolicy.setAllowChunking(false);
  httpClientPolicy.setAccept("*/*");
  httpClientPolicy.setContentType("text/xml;charset=UTF-8");
  httpClientPolicy.setHost(url.split("/")[2]);
  conduit.setClient(httpClientPolicy);
  </code></pre>
  
  <p>Any help would be highly appreciable.</p>
  
  <pre><code>Response-Code: 500
  Encoding: ISO-8859-1
  Content-Type: text/html;charset=ISO-8859-1
  Headers: {connection=[close], content-type=[text/html;charset=ISO-8859-1],
            Date=[Mon, 15 Jun 2015 06:42:09 GMT], Server=[Apache-Coyote/1.1],
            Set-Cookie=[JSESSIONID=FF0E4F5DCA42F700FFAC46BBD039FC20; Path=/; Secure],
            transfer-encoding=[chunked]}
  Payload: 
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  
  &gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html;
  &gt; charset=ISO-8859-1"/&gt; &lt;title&gt;Error Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt;Invalid
  &gt; Request &lt;/body&gt; &lt;/html&gt;
  
  
  at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:79)
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
      at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:797)
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1618)
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1491)
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1399)
      at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
      at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:188)
      at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
      at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:646)
      at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
      at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533)
      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
      at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
      at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
   Caused by: org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType.  Incoming portion of HTML stream: 
  </code></pre>
  
  <p><strong>CURL Request</strong></p>
  
  <p>curl -k --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:" --data @soaprequest.xml <a href="https://url" rel="noreferrer">https://url</a></p>
  
  <p><a href="http://pastebin.com/3pudPi3j" rel="noreferrer">Curl log in verbose</a> (ofcourse have changed some url port names0</p>
  
  <p><strong>Error response from server</strong></p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/&gt;
  &lt;title&gt;Error Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;Invalid Request
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>