I am stuck using Camel CXF 2.6.0 (yes, I know I'm behind) and need to get the
IP address of the remote system making an HTTP POST to my cxfbean:
<!-- Define the camel route -->
<camel:route id="restApis">
<camel:from
uri="jetty:{{protocol}}://0.0.0.0:{{port}}/rest/?matchOnUriPrefix=true&handlers=securityHandler"/>
<camel:to
uri="cxfbean:restfulService?providers=#restExceptionMapper" />
<camel:log message="done"/>
</camel:route>
My restfulService handles the posts. When I turn on tracing, I see
07:10:29,783 | INFO | qtp26579196-144 | Tracer | 76
- org.apache.camel.camel-core - 2.6.0 | ID-centora-45480-1352207331927-4-1 >>>
(restApis)
from(https://0.0.0.0:9091/rest/?matchOnUriPrefix=true&handlers=securityHandler)
--> restfulService <<< Pattern:InOut, Headers:{Host=test.com:9091,
CamelHttpMethod=POST, CamelHttpServletRequest=[POST /rest/domain/feed]@19570394
org.eclipse.jetty.server.Request@12a9eda, Accept-Encoding=gzip,deflate,
CamelHttpServletResponse=HTTP/1.1 200
In my bean I have the function
@POST
@Path("{domainName}/{domainChild}")
@Consumes({MediaType.APPLICATION_RESTMS_XML,
MediaType.APPLICATION_RESTMS_JSON, MediaType.APPLICATION_XML,
MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_RESTMS_XML,
MediaType.APPLICATION_RESTMS_JSON, MediaType.APPLICATION_XML,
MediaType.APPLICATION_JSON})
public Response post(@PathParam("domainName") String domainName,
@PathParam("domainChild") String domainChildName,
JAXBElement<RestXml> restXml) {
...
}
I have tried to add the parameter Exchange (camel), Exchange (cxf), Message,
etc all to no avail due to no longer having a mapping for my sample test post.
I want to know if there is a way for me to access that header
"CamelHttpServletRequest" inside of this bean's function? My end goal is
simply to get the HttpRequest or ServletRequest or whatever request that will
have the "getRemoteAddress" function exposed on it. I've been through the
jaxrs core annotations and cannot seem to figure out how to get a handle to the
original incoming request, or any context object that may contain the IP
address of whoever is making the call to my servlet. I thought maybe UriInfo
or Request (from javax.ws.rs.core) contexts would have the info I'm looking
for, but if they do, I can't figure them out.
I have also looked at building a custom provider, but I can't figure out how to
build one that not only gets the IP address, but manages to provide it along
the route to my cxfbean. Is there a way I can do something like get the IP and
then set it as a QueryParam for my bean to consume?
Any and all help would be greatly appreciated!
Thanks,
Zach Calvert