I am trying to consume a SOAP based web service with the class org.springframework.ws.client.core.WebServiceTemplate of Spring WS 2.2.2 release, like this:
我正在尝试使用基于SOAP的web服务来使用class org.springframework.ws.client.core。Spring WS 2.2.2发布版的WebServiceTemplate:
webServiceTemplate.setDefaultUri(uri);
webServiceTemplate.setMessageSender(new SOAPMessageSenderWithAuth());
res = (RESPONSE) webServiceTemplate.marshalSendAndReceive(request);
The request is built with a class that has been generated from WSDL-files of the web service.
该请求是使用从web服务的wsdl文件生成的类构建的。
The webservice has been successfully tested with SOAP UI, but when accessing it with Java the Exception "SoapMessageCreationException: Could not create message from InputStream: Unable to create envelope from given source (SAAJ0511)" and "Unable to create envelope from given source because the root element is not named 'Envelope' (SAAJ0514)" is thrown.
用肥皂webservice已经成功测试了UI,但当访问与Java异常”SoapMessageCreationException:无法创建消息从InputStream:无法创建信封从给定源(SAAJ0511)”和“无法从给定源创建信封,因为根元素不是叫“信封”(SAAJ0514)”。
Does anyone have any advice for this exception?
有人对这个例外有什么建议吗?
Thanks in advance!
提前谢谢!
The Spring bean for webServiceTemplate is defined as following:
webServiceTemplate的Spring bean定义如下:
<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>
The Exception is:
唯一的例外是:
org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Unable to create envelope from given source: ; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source
org.springframework.ws.soap。SoapMessageCreationException:无法从InputStream创建消息:无法从给定的源创建信封:;嵌套异常是com.sun.xml.internal. message . saajax . soapexceptionimpl:无法从给定的源创建信封
This is the class for the Web Service Client using the Spring WS Template:
这是使用Spring WS模板的Web服务客户机的类:
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;
/**
*
* @param <REQUEST>
* @param <RESPONSE>
*/
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 method sendAndReceive is called like this:
sendAndReceive方法如下:
public MYDATAResponse createCustomer(final MYDATA request)
{
return (MYDATAResponse) soapWebServiceClient.sendAndReceive((REQUEST) request, getCreateCustomerURI());
}
1 个解决方案
#1
0
If you are getting the exception while parsing the response from service, try sending the request from soap UI and check if it is working. If it is working in soap ui and not here, then you are not getting proper response, that can be because of improper request. In my case the issue was my endpoint url in code consists of "?wsdl". After removing it worked perfectly fine.
如果在解析来自服务的响应时遇到异常,请尝试从soap UI发送请求并检查它是否正常工作。如果它在soap ui中工作,而不是在这里,那么您将得不到适当的响应,这可能是由于不适当的请求。在我的例子中,问题是代码中的端点url由“?wsdl”组成。去除后,效果非常好。
#1
0
If you are getting the exception while parsing the response from service, try sending the request from soap UI and check if it is working. If it is working in soap ui and not here, then you are not getting proper response, that can be because of improper request. In my case the issue was my endpoint url in code consists of "?wsdl". After removing it worked perfectly fine.
如果在解析来自服务的响应时遇到异常,请尝试从soap UI发送请求并检查它是否正常工作。如果它在soap ui中工作,而不是在这里,那么您将得不到适当的响应,这可能是由于不适当的请求。在我的例子中,问题是代码中的端点url由“?wsdl”组成。去除后,效果非常好。