问题
I am new to web services. After much googling and trying everything that's been posted about accessing the SoapHeader
from endpoints, I still cannot get it to work. I'm getting the following error:
java.lang.IllegalStateException: No adapter for endpoint when adding SoapHeader in the method signature of the handling method.
If I remove the SoapHeader
parameter, I do not have any issues.
<?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>
Endpoint class:
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;
}
}
回答1:
You probably need to add a org.springframework.ws.soap.server.endpoint.adapter.method.SoapMethodArgumentResolver
bean to the methodArgumentResolvers
list.
回答2:
Actually, Andreas, you are right. Adding SoapMethodArgumentResolver bean to the methodArgumentResolvers list does work. I was trying to access the MessageContext in the endpoint instead of the SoapHeader. For the MessageContext, I added MessageContextMethodArgumentResolver.
来源:https://stackoverflow.com/questions/25980487/still-cannot-access-soapheader-from-endpoint