繁体   English   中英

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

[英]How to get HttpServletRequest in apache Camel based spring-ws EIP flow

我有一个简单的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的in对象显示为SpringWebserviceMessage对象。

PM,提前谢谢。

来自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 ,如下所示(请参阅此处 ):

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");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM