2015-11-17 216 views
2

同事,我需要幫助調用Web服務。 我用org.springframework.ws.client調用WS,代碼如下:SOAPExceptionImpl:無效的Content-Type:text/html。這是一個錯誤消息,而不是SOAP響應?

Response response = (Response) getWebServiceTemplate().marshalSendAndReceive(
       "http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import", 
       request, 
       new SoapActionCallback("http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import")); 

我也可以打電話WS和使用這個鏈接http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import(它看起來很奇怪)使用SOAP UP得到響應。它工作正常。

從IDE運行代碼後,我收到一個堆棧跟蹤:

Exception in thread "main" java.lang.IllegalStateException: Failed to execute CommandLineRunner 
    at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:677) 
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:693) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:969) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:958) 
    at com.mayacomp.feeder.Application.main(Application.java:33) 
Caused by: org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response? 
    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.mayacomp.feeder.Client.createApplication(ExternalChannelClient.java:133) 
    at com.mayacomp.feeder.Application.lambda$0(Application.java:45) 
    at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:674) 
    ... 5 more 
Caused by: 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.MessageImpl.<init>(Unknown Source) 
    at com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl.<init>(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 

所以,問題的根源是: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?

你能推薦一些解決方法來解決這個問題? 如果需要,我隨時可以獲得任何其他信息。謝謝。

UPDATE 我的理解這個問題是在明年的事情: 在請求通過客戶端發送我有: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns3:request xmlns:ns3="http://mayacom/Generic/Ws">

,但應該有: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://mayacom/Generic/Ws"> <soapenv:Header/> <soapenv:Body> <ws:request>

如何設置呢?

@Bean 
public Jaxb2Marshaller marshaller() { 
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 
    marshaller.setContextPath("com.mayacomp.feeder.Client"); 
    return marshaller; 
} 


    @Bean 
     public ExternalChannelClient externalChannelClient(Jaxb2Marshaller marshaller) { 
      ExternalChannelClient client = new ExternalChannelClient(); 
      client.setDefaultUri("http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import"); 
      client.setMarshaller(marshaller); 
      client.setUnmarshaller(marshaller); 
      return client; 
     } 

回答

1

您的服務返回錯誤Content-Type HTTP標頭。

見你堆棧跟蹤:

at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92) 
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611) 

這意味着響應解析,並com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType想只處理type=text/xmltype=application/soap+xml

+1

我可以以某種方式讓客戶端使用內容類型:text/html作爲迴應嗎? – May12

+0

另外我檢查了在wireshare中的響應。真的有'content-type:text/html'和有關異常的信息,比如'驗證步驟之前的一般異常:java.lang.Exception:Error:否響應中的Root元素!'。 – May12

+0

所以,也許你的服務器不能正常工作? –

相關問題