1

我正在尝试使用 Spring-WS 2.0.4.RELEASE、SOAP-1.2、JAXB-2.1、Spring 3.1.0.RELEASE 编写 Web 服务客户端。

当我从我的 spring bean 向 web 服务发出请求时,我得到了以下异常跟踪。

org.springframework.ws.client.WebServiceTransportException:  [500]
                at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:663)
                at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:587)
                at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
                at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:384)
                at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:378)
                at com.comp.proj.services.common.impl.MailClientImpl.postMail(MailClientImpl.java:66)

我的spring bean定义是:

<bean id="mailServiceClient" class="org.springframework.ws.client.core.WebServiceTemplate" >
        <constructor-arg ref="emailSoapMsgFactory" type="org.springframework.ws.WebServiceMessageFactory" />
        <property name="defaultUri" value="http://server:8080/Process/EmailNotifyService"/>
        <property name="marshaller" ref="emailJAXBBMarshaller"></property>
        <property name="unmarshaller" ref="emailJAXBBMarshaller"></property>
    </bean>

    <bean id="emailJAXBBMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
       <property name="classesToBeBound">
            <list>
                <value>com.comp.proj.common.dto.EMailInputType</value>
                <value>com.comp.proj.common.dto.EMailOutputType</value>                
            </list>
        </property>
    </bean>

     <!-- Message factory for the service template. -->
     <bean id="emailSoapMsgFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
        <property name="soapVersion">
            <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
        </property>
    </bean>

令人困惑的是,当我尝试在 SoapUI中发布相同的消息(从调试日志中提取)时,它运行良好。 我不确定是什么导致了这个问题(来自堆栈跟踪)。

可能是一些图书馆问题吗?任何帮助深表感谢。

根据请求附加日志:

SOAP UI RAW-Tab data:
---------------------
POST http://server:8080/Process/EmailNotifyService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="/ActionURL"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: server:8080
Content-Length: 11117

SOAP UI 日志:

------------
1:49:34,627 DEBUG [HttpConnection] Open connection to server:8080
1:49:34,630 DEBUG [header] >> "POST /Process/EmailNotifyService HTTP/1.1[\r][\n]"
1:49:34,631 DEBUG [HttpMethodBase] Adding Host request header
1:49:34,639 DEBUG [header] >> "Accept-Encoding: gzip,deflate[\r][\n]"
1:49:34,639 DEBUG [header] >> "Content-Type: application/soap+xml;charset=UTF-8;action="/ActionURL"[\r][\n]"
1:49:34,639 DEBUG [header] >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
1:49:34,640 DEBUG [header] >> "Host: server:8080[\r][\n]"
1:49:34,640 DEBUG [header] >> "Content-Length: 11117[\r][\n]"
1:49:34,640 DEBUG [header] >> "[\r][\n]"
1:49:34,643 DEBUG [EntityEnclosingMethod] Request body sent
1:49:34,767 DEBUG [header] << "HTTP/1.1 200 OK[\r][\n]"
1:49:34,768 DEBUG [header] << "HTTP/1.1 200 OK[\r][\n]"
1:49:34,770 DEBUG [header] << "Server: Apache-Coyote/1.1[\r][\n]"
1:49:34,771 DEBUG [header] << "Content-Type: application/soap+xml;charset=utf-8[\r][\n]"
1:49:34,772 DEBUG [header] << "Content-Length: 437[\r][\n]"
1:49:34,774 DEBUG [header] << "Date: Wed, 20 Jun 2012 07:49:34 GMT[\r][\n]"
1:49:34,776 DEBUG [header] << "[\r][\n]"
1:49:34,785 DEBUG [HttpMethodBase] Resorting to protocol version default close connection policy
1:49:34,785 DEBUG [HttpMethodBase] Should NOT close connection, using HTTP/1.1
1:49:34,786 DEBUG [HttpConnection] Releasing connection back to connection manager.
1:49:34,788 DEBUG [IdleConnectionHandler] Adding connection at: 1340178574788
1:49:34,825 INFO  [AbstractHttpRequestDesktopPanel] Got response for [MailNotifyEventSourceBinding.NotifyEmail:Request 1] in 168ms (437 bytes)

应用程序调试日志:

2012-06-20 11:42:27,975 DEBUG: org.springframework.ws.client.core.WebServiceTemplate - Opening [org.springframework.ws.transport.http.CommonsHttpConnection@19c5ce6] to [http://server:8080/Process/EmailNotifyService]
2012-06-20 11:42:28,032 DEBUG: org.springframework.ws.soap.saaj.support.SaajUtils - SOAPElement [com.sun.xml.messaging.saaj.soap.ver1_2.Envelope1_2Impl] implements SAAJ 1.3
2012-06-20 11:42:28,045 DEBUG: org.springframework.ws.soap.saaj.support.SaajUtils - SOAPElement [com.sun.xml.messaging.saaj.soap.ver1_2.Body1_2Impl] implements SAAJ 1.3
2012-06-20 11:42:28,083 DEBUG: org.springframework.ws.client.MessageTracing.sent - Sent request [<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Header/><env:Body><ns2:input_Mail_Type xmlns:ns2="http://www.namespace.com/modified"><ns2:cc/><ns2:plainData>           
    &lt;!-- Outermost table --&gt;&#13;
                &lt;table cellspacing="0" border="0" cellpadding="0" width="700"&#13;
                    style="border:1px solid #c9c1b5; background:#f1eee7;"&gt;&#13;
                    &lt;tr&gt;&#13;
                        &lt;td&gt;&#13;
                        &lt;/td&gt;&#13;
                    &lt;/tr&gt;&#13;
                &lt;/table&gt;          &#13;
</ns2:plainData><ns2:subject>Test</ns2:subject><ns2:To>b@b.com</ns2:To><ns2:contentType>text/html</ns2:contentType><ns2:app_id>x01</ns2:app_id><ns2:username>x</ns2:username><ns2:password>x</ns2:password></ns2:input_Mail_Type></env:Body></env:Envelope>
2012-06-20 11:42:28,189 DEBUG: httpclient.wire.header - >> "Accept-Encoding: gzip[\r][\n]"
2012-06-20 11:42:28,190 DEBUG: httpclient.wire.header - >> "Accept: application/soap+xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2[\r][\n]"
2012-06-20 11:42:28,191 DEBUG: httpclient.wire.header - >> "Content-Type: application/soap+xml; charset=utf-8[\r][\n]"
2012-06-20 11:42:28,192 DEBUG: httpclient.wire.header - >> "Content-Length: 11342[\r][\n]"
2012-06-20 11:42:28,192 DEBUG: httpclient.wire.header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
2012-06-20 11:42:28,193 DEBUG: httpclient.wire.header - >> "Host: server:8080[\r][\n]"
2012-06-20 11:42:28,292 DEBUG: org.apache.commons.httpclient.methods.EntityEnclosingMethod - Request body sent
2012-06-20 11:42:28,295 DEBUG: httpclient.wire.header - << "HTTP/1.1 500 [\r][\n]"
2012-06-20 11:42:28,295 DEBUG: httpclient.wire.header - << "HTTP/1.1 500 [\r][\n]"
2012-06-20 11:42:28,318 DEBUG: org.springframework.ws.client.core.WebServiceTemplate - Received error for request [SaajSoapMessage {http://www.namespace.com/modified}input_Mail_Type]
2012-06-20 11:42:28,320 DEBUG: httpclient.wire.content - << "<html><head><title>Apache Tomcat/5.5.25 - Error report</title> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.25</h3></body> </html>"
4

2 回答 2

3

迟到的答案,但希望它对某人有所帮助。当 spring-ws 没有使用 marhsalSendAndRecieve() 发送 SoapAction 时出现此错误。糟糕的是,这种情况没有记录在任何地方,最终使用 Fiddler 定位,SoapUI 和 web 服务请求之间的唯一差异是缺少 SoapAction。

将 WebServiceMessageCallback 添加到 webServiceTemplate.marshalSendAndRecieve 以将 SoapAction 设置为消息:

template.marshalSendAndReceive( serviceURL, jaxbRequest, 
                                new WebServiceMessageCallback() {
    @Override
    public void doWithMessage( WebServiceMessage message ) 
                                    throws IOException, TransformerException {
        ( (SoapMessage) message ).setSoapAction( "/mySoapAction" );
    }
}
于 2013-09-20T07:23:32.107 回答
1

我遇到了这个问题,几乎没有堆栈跟踪细节。原来这是我通过客户端发送到请求中的数据的验证异常。例如,在 SOAPUI 中:

..在代码中我会发送空值,这会出错,但如果我发送“”,这是可行的。

于 2013-07-29T16:52:08.333 回答