![](/img/trans.png)
[英]How to add a value from a cookie to the HTTP header in Spring WebServiceTemplate?
[英]Spring WebServiceTemplate SOAPAction missing in HTTP Header
我很難通過Spring-ws WebServiceTemplate調用SOAP 1.2 WebService。 正在進行的請求缺少Http Header中的SOAPAction,並且服務器拋出錯誤“無法處理沒有有效操作參數的請求。請提供有效的soap操作。” 通過wireshark監控,我能夠發現SOAP Action丟失了。 我也不支持任何代理。
通過TCP Mon(像SOAP UI這樣的工具)運行請求,我確保我嘗試發送的SOAP XML是有效的,並且能夠獲得響應。
這是我的春季配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
</property>
</bean>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory" />
<property name="defaultUri" value="https://ecomapi.networksolutions.com/soapservice.asmx" />
<property name="messageSender">
<bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender" /> </property>
</bean>
這是我的java代碼:
public void simpleSendAndReceive() {
try{
StreamSource source = new StreamSource(new StringReader(MESSAGE));
StreamResult result = new StreamResult(System.out);
SoapActionCallback actionCallBack = new SoapActionCallback("https://ecomapi.networksolutions.com/soapservice.asmx") {
public void doWithMessage(WebServiceMessage msg) {
SoapMessage smsg = (SoapMessage)msg;
smsg.setSoapAction("http://networksolutions.com/ReadOrder");
}
};
webServiceTemplate.sendSourceAndReceiveToResult(
"https://ecomapi.networksolutions.com/soapservice.asmx",
source,
new SoapActionCallback("http://networksolutions.com/ReadOrder"),
// actionCallBack,
result);
System.out.println(source.getInputStream().toString());
System.out.println(result.getWriter().toString());
}catch (SoapFaultClientException e) {
System.out.println(e.getFaultCode());
System.out.println(e.getFaultStringOrReason());
System.out.println(e.fillInStackTrace().getLocalizedMessage());
} catch (WebServiceIOException we) {
System.out.println(we.getRootCause());
}
}
我遇到了同樣的問題,我將其追溯到com.sun.xml.messaging.saaj.soap.MessageImpl實現的1.3.2版本中的一個錯誤( http://java.net/jira/browse/SAAJ- 37 )。 我升級到1.3.19版本,一切都很好。
問題 : -
在將請求寫入輸出流之前,將調用saveChanges()方法。 該類的1.3.2版本在其“saveChanges”方法的實現中覆蓋了“Content-Type”請求標頭。
我有一個類似的問題,這是由於package-info.java文件中的XmlSchema注釋的命名空間與我試圖調用的SOAP服務的預期不同。 這是因為我使用xjc從xsd生成jaxb請求和響應對象,我從wsdl部分縫合在一起加上我以前連接的服務的xsd頭,所以這是我的一個純粹的剪切和粘貼錯誤但是這里關於命名空間的上一個答案很快就讓我誤解了我的錯誤。
SOAPAction僅在SOAP 1.1中是必需的,請參閱內容類型一節 。
SOAP 1.2中已刪除SOAP 1.1強制SOAPAction HTTP標頭。 取而代之的是application / soap + xml媒體類型的可選動作參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.