I have a simple Apache Camel EIP flow where the entry point is a spring-ws web service. How do I get access to a service request's HttpServletRequest object?
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. When I debug the processor, the Exchange's in object is shown as a SpringWebserviceMessage object.
Thanks in advance, PM.
From 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 is from the same kitchen as Camel and therefore may be better integrated. With CXF you have access to the ServletRequest
as follows (see 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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.