首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在apache的spring流中获取HttpServletRequest

问如何在apache的spring流中获取HttpServletRequest
EN

Stack Overflow用户
提问于 2014-04-29 15:13:23
回答 1查看 3K关注 0票数 0

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

代码语言:javascript
复制
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对象。

提前谢谢你,下午

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-02 12:04:28

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

代码语言:javascript
复制
TransportContext context = TransportContextHolder.getTransportContext();
HttpServletConnection connection = (HttpServletConnection )context.getConnection();
HttpServletRequest request = connection.getHttpServletRequest();
String ipAddress = request.getRemoteAddr();

或者使用CXF代替Spring。CXF来自与骆驼相同的厨房,因此可能会更好地整合。使用CXF,您可以访问ServletRequest,如下所示(参见这里):

代码语言:javascript
复制
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");
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23368628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档