如何在apache基于Camel的spring-ws EIP流程中获取HttpServletRequest

时间:2014-04-29 15:13:24

标签: apache-camel spring-ws

我有一个简单的Apache Camel EIP流程,其入口点是spring-ws Web服务。如何访问服务请求的HttpServletRequest对象?

from("spring-ws:uri:http://localhost:8080/test-ws-1.0/ws/TestService?endpointMapping=#endpointMapping")
.log("body is:\n${body}")
.process(new HttpRequestParserProcessor())

我希望能够从HttpRequestParserProcessor中获取请求的用户主体名称和请求的远程IP地址。当我调试处理器时,对象中的Exchange显示为SpringWebserviceMessage对象。

提前致谢, PM。

1 个答案:

答案 0 :(得分:2)

来自http://docs.spring.io/spring-ws/sites/1.5/reference/html/common.html

TransportContext context = TransportContextHolder.getTransportContext();
HttpServletConnection connection = (HttpServletConnection )context.getConnection();
HttpServletRequest request = connection.getHttpServletRequest();
String ipAddress = request.getRemoteAddr();

或者使用CXF代替Spring-WS。 CXF与Camel位于同一厨房,因此可能更好地集成。使用CXF,您可以访问ServletRequest,如下所示(请参阅here):

org.apache.cxf.message.Message cxfMessage = in.getHeader(CxfConstants.CAMEL_CXF_MESSAGE, org.apache.cxf.message.Message.class);
ServletRequest request = (ServletRequest)cxfMessage.get("HTTP.REQUEST");