java - 仍然无法从端点访问 SoapHeader

标签 java web-services soap spring-ws soapheader

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

java.lang.IllegalStateException: No adapter for endpoint when adding SoapHeader in the method signature of the handling method.

如果删除 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;
    }
}

最佳答案

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

关于java - 仍然无法从端点访问 SoapHeader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25980487/

相关文章:

java - 如何在java中克隆或创建Map的新副本

java - ubuntu下Intellij编译android的hello world项目时出错

html - 是否有将 HTML 转换为 PDF 的网络服务?

php - 在 PHP 中创建 SOAP 服务器的最佳解决方案是什么?

javascript - 如何在 javascript 中发送 SOAP 请求,就像在 SoapUI 中一样

java - 正则表达式 Java 非字母数字字符匹配

java - 在Java中加载资源中不同文件夹下的属性

c++ - gSOAP - 修改 HTTP POST header

python - 在不知道名称的情况下打印所有 POST 请求参数

.net - IEndpointBehavior ApplyClientBehavior 方法在行为添加到端点行为后未执行