I am trying to use a SOAP-based web service with class org.springframework.ws.client.core.WebServiceTemplate version of Spring WS 2.2.2, for example:
webServiceTemplate.setDefaultUri(uri); webServiceTemplate.setMessageSender(new SOAPMessageSenderWithAuth()); res = (RESPONSE) webServiceTemplate.marshalSendAndReceive(request);
The request is built with the class that was generated from the WSDL files of the web service.
The web service was successfully tested using the SOAP interface, but when accessing it with Java, the exception was β SoapMessageCreationException: Could not create message from InputStream: cannot create envelope from this source (SAAJ0511) β and β Cannot create envelope from this source, because the root the item is not named "Envelope" (SAAJ0514) . "
Does anyone have any tips for this exception?
Thanks in advance!
Spring bean for webServiceTemplate is defined as follows:
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate" p:marshaller-ref="jaxbMarshaller" p:unmarshaller-ref="jaxbMarshaller" p:defaultUri="..."> <constructor-arg ref="messageFactory"/> <property name="messageSender"> <bean class="org.springframework.ws.transport.http.HttpComponentsMessageSender"> <property name="credentials"> <bean class="org.apache.http.auth.UsernamePasswordCredentials"> <constructor-arg value="..."/> <constructor-arg value="..."/> </bean> </property> </bean> </property> </bean>
An exception:
org.springframework.ws.soap.SoapMessageCreationException: could not create message from InputStream: cannot create envelope from this source :; nested exception - com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: cannot create an envelope from this source
This is the class for the web service client using the Spring WS template:
import javax.annotation.Resource; import org.apache.log4j.Logger; import org.springframework.ws.client.WebServiceIOException; import org.springframework.ws.client.core.WebServiceTemplate; import com.myproject.soap.client.services.SOAPWebServiceClient; public class DefaultSOAPWebServiceClient<REQUEST, RESPONSE> implements SOAPWebServiceClient<REQUEST, RESPONSE> { private final static Logger LOG = Logger.getLogger(DefaultSOAPWebServiceClient.class.getName()); @Resource(name = "webServiceTemplate") private WebServiceTemplate webServiceTemplate; @Override public RESPONSE sendAndReceive(final REQUEST request, final String uri) { LOG.info("SOAP URL-" + uri); LOG.info("REQUEST-" + request.toString()); RESPONSE res = null; try { res = (RESPONSE) webServiceTemplate.marshalSendAndReceive(uri, request); } catch (final WebServiceIOException e) { e.printStackTrace(); LOG.error("Service with URI: " + uri + " is unreachable"); } return res; } }
The sendAndReceive method is called as follows:
public MYDATAResponse createCustomer(final MYDATA request) { return (MYDATAResponse) soapWebServiceClient.sendAndReceive((REQUEST) request, getCreateCustomerURI()); }