title: how can I fix "Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?"
body: <p>I have to create an soap request and it give me some errors after the creation of it.</p>
  
  <pre><code>com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
  at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(Unknown Source)
  at com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl.createMessage(Unknown Source)
  at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source)
  at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source)
  at packageH.SoapCall.main(SoapCall.java:41)
  </code></pre>
  
  <p>This is the code:</p>
  
  <pre><code>    public static void main(String[] args){
  
      try {
          String xml="&lt;soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:bcc=\"http://www.huawei.com/bme/cbsinterface/bccustomizedservices\" xmlns:cbs=\"http://www.huawei.com/bme/cbsinterface/cbscommon\" xmlns:bcc1=\"http://www.huawei.com/bme/cbsinterface/bccommon\"&gt;&lt;soapenv:Header/&gt;&lt;soapenv:Body&gt;&lt;bcc:QueryBalFuRequestMsg&gt;&lt;RequestHeader&gt;&lt;cbs:Version&gt;1&lt;/cbs:Version&gt;&lt;cbs:BusinessCode&gt;GetAllBalances&lt;/cbs:BusinessCode&gt;&lt;cbs:MessageSeq&gt;896879678676778968&lt;/cbs:MessageSeq&gt;&lt;cbs:AccessSecurity&gt;&lt;cbs:LoginSystemCode&gt;102&lt;/cbs:LoginSystemCode&gt;&lt;cbs:Password&gt;O2+SSm/iwzGMtKK7LP0WUi7UqvfMgB/bCebuArha6VM=&amp;amp;lt;&lt;/cbs:Password&gt;&lt;/cbs:AccessSecurity&gt;&lt;/RequestHeader&gt;&lt;QueryBalFuRequest&gt;&lt;bcc:QueryObj&gt;&lt;bcc:SubAccessCode&gt;&lt;bcc1:PrimaryIdentity&gt;550022002&lt;/bcc1:PrimaryIdentity&gt;&lt;/bcc:SubAccessCode&gt;&lt;/bcc:QueryObj&gt;&lt;bcc:QueryTarget&gt;0&lt;/bcc:QueryTarget&gt;&lt;/QueryBalFuRequest&gt;&lt;/bcc:QueryBalFuRequestMsg&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;";
          SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
          SOAPConnection soapConnection = soapConnectionFactory.createConnection();
          String serverURI = "http://localhost:8088/";
          String serverURI1="http://www.huawei.com/bme/cbsinterface/";
          MessageFactory messageFactory = MessageFactory.newInstance();
          SOAPMessage soapMessage =getSoapMessageFromString(xml);
          MimeHeaders headers = soapMessage.getMimeHeaders();
          headers.addHeader("SOAPAction", serverURI1  + "bccustomizedservices");
          headers.addHeader("SOAPAction", serverURI1  + "cbscommon");
          headers.addHeader("SOAPAction", serverURI1  + "bccommon");
          soapMessage.saveChanges();
          System.out.print("Request SOAP Message = ");
          soapMessage.writeTo(System.out);
          System.out.println();
          SOAPMessage soapResponse = soapConnection.call(soapMessage, serverURI);
          System.out.print("Request SOAP Message = ");
          soapMessage.writeTo(System.out);
          System.out.println("");
          TransformerFactory transformerFactory = TransformerFactory.newInstance();
          Transformer transformer = transformerFactory.newTransformer();
          Source sourceContent = soapResponse.getSOAPPart().getContent();
          System.out.print("\nResponse SOAP Message = ");
          StreamResult result = new StreamResult(System.out);
          transformer.transform(sourceContent, result);
          soapConnection.close();
      } catch (UnsupportedOperationException | SOAPException | IOException | TransformerException e) {
          e.printStackTrace();
      }
  
  }
  
  private static SOAPMessage getSoapMessageFromString(String xml) throws SOAPException, IOException {
      MessageFactory factory = MessageFactory.newInstance();
      SOAPMessage message = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8"))));
      return message;
  }
  </code></pre>