仍然无法从端点访问SoapHeader

时间:2014-09-22 18:09:03

标签: java web-services soap spring-ws soapheader

我是网络服务新手。经过大量的谷歌搜索并尝试了有关从端点访问SoapHeader的所有内容,我仍然无法让它工作。我收到以下错误:

  

java.lang.IllegalStateException:添加时没有端点适配器   SoapHeader在处理方法的方法签名中。

如果删除SoapHeader参数,我没有任何问题。

<?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:context="http://www.springframework.org/schema/context"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:annotation-config />
<context:component-scan base-package="services" />
<sws:annotation-driven />

<sws:interceptors>
    <bean id="validatingInterceptor"
        class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
        <property name="schema" value="/WEB-INF/schemas/cfPostBack2015.xsd" />
        <property name="validateRequest" value="true"/> 
        <property name="validateResponse" value="true"/> 
    </bean> 
    <bean id="loggingInterceptor"
        class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" /> 
</sws:interceptors>

<sws:static-wsdl id="postBackService2015"
    location="/WEB-INF/schemas/postBackService2015.wsdl" />

<bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller" />
<bean id="marshallingPayloadMethodProcessor"
    class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
    <constructor-arg ref="marshaller"/>  
    <constructor-arg ref="marshaller"/>  
</bean>

<bean id="defaultMethodEndpointAdapter"
    class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
    <property name="methodArgumentResolvers">
        <list>
            <ref bean="marshallingPayloadMethodProcessor" />
        </list>
    </property>
    <property name="methodReturnValueHandlers">
        <list>
            <ref bean="marshallingPayloadMethodProcessor" />
        </list>
    </property>
</bean>


<bean id="postbackService"
    class="PostBackServiceImpl" />
<bean id="postBackEndpoint"
    class="PostBackEndpoint">
    <property name="postBackService" ref="postBackService" />
</bean>

</beans>

端点类:

package endpoints;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.springframework.ws.soap.SoapHeader;

import PostBackService;
import cfPostBack.x2015.PostBackRequestDocument;
import cfPostBack.x2015.PostBackResponseDocument;

@Endpoint
public class PostBackServiceEndpoint {
    private static final String TARGET_NAMESPACE = 
        "http://services/cfPostBack/2015/";

    @Resource(name="postBackService")
    private PostBackService postBackService;

    @Autowired                                                                             
    public PostBackServiceEndpoint(PostBackService postBackService) {
        this.postBackService = postBackService;
    }

    @PayloadRoot(localPart = "postBackRequest", namespace = TARGET_NAMESPACE)
    @ResponsePayload
    public PostBackResponseDocument getPostBackResponse(
        @RequestPayload PostBackRequestDocument request, SoapHeader soapHeader) 
        throws Exception {

        PostBackResponseDocument response = 
            postBackService.processPostBackRequest(request);

        return response;
    }

    public void setPostBackService(PostBackService postBackService) {
        this.postBackService = postBackService;
    }
}

2 个答案:

答案 0 :(得分:2)

您可能需要将org.springframework.ws.soap.server.endpoint.adapter.method.SoapMethodArgumentResolver bean添加到methodArgumentResolvers列表中。

答案 1 :(得分:0)

实际上,安德烈亚斯,你是对的。将SoapMethodArgumentResolver bean添加到methodArgumentResolvers列表确实有效。我试图访问端点中的MessageContext而不是SoapHeader。对于MessageContext,我添加了MessageContextMethodArgumentResolver。