简体   繁体   English

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

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

I have a simple Apache Camel EIP flow where the entry point is a spring-ws web service. 我有一个简单的Apache Camel EIP流程,其入口点是spring-ws Web服务。 How do I get access to a service request's HttpServletRequest object? 如何访问服务请求的HttpServletRequest对象?

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

I would like to be able to get the request's user principal name and request's remote IP address from within HttpRequestParserProcessor. 我希望能够从HttpRequestParserProcessor中获取请求的用户主体名称和请求的远程IP地址。 When I debug the processor, the Exchange's in object is shown as a SpringWebserviceMessage object. 当我调试处理器时,Exchange的in对象显示为SpringWebserviceMessage对象。

Thanks in advance, PM. PM,提前谢谢。

From http://docs.spring.io/spring-ws/sites/1.5/reference/html/common.html : 来自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();

Or use CXF instead of Spring-WS. 或者使用CXF代替Spring-WS。 CXF is from the same kitchen as Camel and therefore may be better integrated. CXF与Camel位于同一厨房,因此可能更好地集成。 With CXF you have access to the ServletRequest as follows (see here ): 使用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