Ho difficoltà a chiamare un WebService SOAP 1.2 tramite WebServiceTemplate di Spring-ws. Manca la richiesta SOAPAction in Http Header e il server genera un errore con "Impossibile gestire la richiesta senza un parametro di azione valido. Fornisci un'azione soap valida". Sono stato in grado di capire che l'azione SOAP mancava monitorando tramite wireshark. Anch'io non sono dietro nessun proxy.Spring WebServiceTemplate SOAPAction mancante nell'intestazione HTTP
Mi sono assicurato che l'XML SOAP che sto tentando di inviare sia valido eseguendo la richiesta tramite TCP Mon (strumento come SOAP UI) ed è stato in grado di ottenere una risposta.
Ecco il mio config primavera:
<?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>
E questo è il mio codice 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());
}
}
Sembra che tu abbia impostato le intestazioni di azione SOAP in più modi qui a destra - utilizzando 'actionCallBack', utilizzando esplicitamente' new SoapActionCallback..', entrambi gli approcci non funzionano? –
Quello è corretto. Entrambi gli approcci restituiscono lo stesso errore. – user1546703
È necessaria un'intestazione 'http: // networksolutions.com/ReadOrder' a destra - quale intestazione si vede sul filo usando wireshark. Voglio solo assicurarti di non inviare 'https: // ecomapi.networksolutions.com/soapservice.asmx'. Questo è uno strumento semplice per catturare ciò che sta andando avanti e indietro - http://sourceforge.net/projects/nettool/ –