title: Incorrect Content-Type for Soap Version. Got application/soap+xml but expected text/xml (Spring-Boot)
body: <p>I have a spring-boot application where i need to send a SOAP-Message (Version 1.2) and receive the reply. Timeout should be 30 seconds;</p>
  
  <p>Below is my class;</p>
  
  <pre><code>@Component
  public class SettingsSenderClient extends WebServiceGatewaySupport {
  
  @Autowired
  private DatabaseService databaseService;
  
  @Autowired
  public void setHttpComponentsMessageSender(HttpComponentsMessageSenderWithTimeout messageSenderWithTimeout) {
      WebServiceTemplate template = getWebServiceTemplate();
      template.setMessageSender(messageSenderWithTimeout);
    //template.setMessageFactory(messageFactory());
  }
  
  //@Bean(name = "webServiceTemplate")
  //public WebServiceTemplate webServiceTemplate() {
      //WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
      //webServiceTemplate.setMessageSender(httpComponentsMessageSender());
      //webServiceTemplate.setMessageFactory(messageFactory());
      //return webServiceTemplate;
  //}
  
  @Bean
  public SaajSoapMessageFactory messageFactory() {
      SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
      messageFactory.setSoapVersion(SoapVersion.SOAP_12);
      return messageFactory;
  }
  
  public void sendSettings() {
      List&lt;SettingsDetails&gt; settingsDetails = databaseService.getSettingsDetailBySettingsID();
      if (!settingsDetails.isEmpty()) {
          //Build the "SettingsRequest" SOAP Message From WSDL Generated Classes For Each Record
          settingsDetails.stream().forEachOrdered((settingsDetail) -&gt; {
              try {
                  //Build SettingsDetail Request
                  SettingsDetailRequest request = new SettingsDetailRequest();
                  request.setDetail1(settingsDetail.getSettingsDetail1());
                  request.setDetail2(settingsDetail.getSettingsDetail2());
  
                  //Log The URL To Send
                  String settingURL = settingsDetail.getSettingsURL();
                  LogService.info(this.getClass().getName(),"Sending Message on URL: " + deviceURL);
  
                  JAXBElement&lt;SettingsDetailResponse&gt; jaxbElementResponse = (JAXBElement&lt;SettingsDetailResponse&gt;) getWebServiceTemplate()
                          .marshalSendAndReceive(settingURL,
                                  new ObjectFactory().createSettingsDetailRequest(request), (WebServiceMessage message) -&gt; {
  
                              SaajSoapMessage soapMessage = (SaajSoapMessage) message;
                              SoapHeaderElement id = soapMessage.getSoapHeader().addHeaderElement(new QName(namespaceUrl, localpart, "sp"));
                              id.setText(settingsDetail.getSettingName());
                          });
  
                  SettingsDetailResponse response = jaxbElementResponse.getValue();
  
                  //Get The Response Status
                  String responseStatus = response.getStatus().value();
                  //Wait 1 Second in each loop
                  try {
                      TimeUnit.SECONDS.sleep(1);
                  } catch (InterruptedException ex) {
                      LogService.error(this.getClass().getName(), "Intrp Error");
                      LogService.error(this.getClass().getName(), ex);
                  }
              } catch (WebServiceIOException ex) {
                  LogService.error(this.getClass().getName(), ex.getMessage());
                  //Catch The Timeout Exception Here (How??? //TODO)
                  LogService.error(this.getClass().getName(), ex);
              }
          });
      } else {
          LogService.info(this.getClass().getName(), "No Records Found To Send Settings SOAP Message(s)");
      }
   }
  }
  </code></pre>
  
  <p>I have the <code>messageFactory</code> bean configured to use <code>SoapVersion.SOAP_12</code>.
  But still i get the Error:</p>
  
  <pre><code>[Exception: ]org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Unable to internalize message; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to internalize message
          at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:216)
          at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:60)
          at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)
          at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611)
          at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
          at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
          at com.myapp.ws.outgoing.SettingsSenderJobClient.lambda$sendSettings$1(SettingsSenderJobClient.java:107)
          at com.myapp.ws.outgoing.SettingsSenderJobClient$$Lambda$8/1215330412.accept(Unknown Source)
          at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
          at java.util.stream.ReferencePipeline$Head.forEachOrdered(Unknown Source)
          at com.myapp.ws.outgoing.SettingsSenderJobClient.sendSettings(SettingsSenderJobClient.java:71)
          at com.tingco.myapp.SettingsSenderJob.execute(SettingsSenderJob.java:24)
          at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
          at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
  Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to internalize message
          at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.init(Unknown Source)
          at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.&lt;init&gt;(Unknown Source)
          at com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl.&lt;init&gt;(Unknown Source)
          at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl.createMessage(Unknown Source)
          at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:188)
          ... 13 more
  Caused by: com.sun.xml.internal.messaging.saaj.soap.SOAPVersionMismatchException: Cannot create message: incorrect content-type for SOAP version. Got: application/soap+xml; charset=utf-8; action="/ChangeConfiguration" Expected: text/xml
          ... 18 more
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I removed the <code>SaajSoapMessageFactory</code> and did like below which is working. What is difference here? Arn't they both <code>messageFactories</code>?</p>
  
  <pre><code>@Bean
  public WebServiceMessageFactory webServiceMessageFactory() throws SOAPException {
      MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
      WebServiceMessageFactory webMessageFactory = new SaajSoapMessageFactory(messageFactory);
      return webMessageFactory;
  }
  
  @Autowired
  public void setHttpComponentsMessageSender(HttpComponentsMessageSenderWithTimeout messageSenderWithTimeout) throws SOAPException {
      WebServiceTemplate template = getWebServiceTemplate();
      template.setMessageSender(messageSenderWithTimeout);
      template.setMessageFactory(webServiceMessageFactory());
  }
  </code></pre>
  
  <p>If i do the same with <code>SaajSoapMessageFactory</code>, i get <code>nullpointer exception</code>.</p>