我正在寻找一种将 http 标头信息与 SOAP 消息一起转发到 Spring Endpoint 的方法,以便访问 IP 地址等详细信息。
相关web.xml:
<servlet>
<servlet-name>SoapHost</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SoapHost</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
SoapHost-servlet.xml:
<?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/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
<!-- To detect @Endpoint -->
<sws:annotation-driven />
<!-- To detect @Service, @Component etc -->
<context:component-scan base-package="za.co.mycee.soaphost" />
<!-- To generate dynamic wsdl for SoapHost Services -->
<sws:dynamic-wsdl
id="SoapHost"
portTypeName="SoapHost"
locationUri="/ws/SoapHost"
targetNamespace="http://www.mycee.co.za/SoapHost">
<sws:xsd location="/WEB-INF/SoapHost.xsd" />
</sws:dynamic-wsdl>
<!-- Validate Request and Response -->
<sws:interceptors>
<bean id="MyCeeSoapHost" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="schema" value="/WEB-INF/SoapHost.xsd" />
<property name="validateRequest" value="true" />
<property name="validateResponse" value="true" />
</bean>
</sws:interceptors>
</beans>
端点:
@Endpoint
public class ...Endpoint {
@Autowired
...Service ...Service;
@Autowired
...Service ...Service;
@Autowired
...Service ...Service;
@ResponsePayload
@PayloadRoot(localPart = "...Request", namespace = "http://www.mycee.co.za/SoapHost")
public ...Response do...(@RequestPayload ...Request request) {
...
// get IP address here
// get some other info from headers here
...
}
}
我尝试将其添加为参数之一:
@ResponsePayload
@PayloadRoot(localPart = "...Request", namespace = "http://www.mycee.co.za/SoapHost")
public ...Response do...(
@RequestPayload ...Request request,
HttpServletRequest httpServletRequest) {
但这会在 XML 响应中返回错误:“端点没有适配器”和“您的端点是否使用 @Endpoint 注释,或者它是否实现了受支持的接口,如 MessageHandler 或 PayloadEndpoint”