You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dvsridhar <da...@cgifederal.com> on 2012/08/22 18:29:42 UTC

Camel redirect through Rest cxf:rsClient not keeping orgin (host) information in Http Headers

Hello,
We are using Jboss 7.1.1 as our app server and we use camel as the routing
layer. In the following configuration, vendorConsumer receives the request
and redirects the request to the actual provider. In response the provider
sends the data with corresponding hyper links. We create the hyperlink using
HttpHeader host(Host) and context (org.apache.cxf.request.uri) key values.

However for the key (Host)) as part of http header we are only receiving the
redirected URL Host (providerhost)  but not the origin Host name
(REMOTEHOST). *What's the best way to capture this?* I looked through all
HttpHeaders i don't have any key contains such information except the
breadcrumbId but its value has some unique format
([ID-REMOTEHOST-081075-2474-1345582555484-1-42],) not sure how far i can use
this. Do I need use custom http headers for this.

Another question on the same lines, *how do i get the actual protocol
information (http/https)?* 

*Note: *Some times we see the whole HttpHeader object it self is null. Not
sure why Jboss is behaving that way.. 

*Log of the HTTP Header:*
12:10:05,166 INFO  [com.dummy.common.utils.CamelCXFRedirectedURL]
(http--0.0.0 .0-8080-1) {Accept=[text/html, application/xhtml+xml,
application/xml;q=0.9, */* ;q=0.8], accept-encoding=[gzip, deflate],
accept-language=[en-us, en;q=0.5], bre
adcrumbid=[ID-REMOTEHOST-081075-2474-1345582555484-1-42],
cache-control=[no-cache] , camelcxfrsresponsegenerictype=[class
javax.ws.rs.core.Response], connection=[keep-alive], content-type=[*/*],
host=[PROVIDERHOST-097052:8080],
org.apache.cxf.request.uri=[/fdx-web-1.0/TestApp/Vendor/&3903&COOLEY/],
pragma=[no-cache], user-ag ent=[Mozilla/5.0 (Windows NT 5.1; rv:14.0)
Gecko/20100101 Firefox/14.0.1, Apache  CXF 2.5.1]}

 * /<camel:camelContext>
	<camel:route>
	   <camel:from uri="cxfrs://bean://vendorConsumer"/>
			
			<camel:removeHeader headerName="Content-Length" />       
	   <camel:to uri="cxfrs://bean://vendorProducer"/>       
	</camel:route>
 </camel:camelContext>

  <cxf:rsServer id="vendorConsumer" address="/Redirect/Vendor"
	serviceClass="com.dummy.rest.resource.impl.VendorRSImpl" 
	loggingFeatureEnabled="true">
	<cxf:extensionMappings>
      <entry key="json" value="application/json"/>
      <entry key="xml" value="application/xml"/>
    </cxf:extensionMappings>	
  </cxf:rsServer>

  <cxf:rsClient id="vendorProducer"
address="http://providerhost:8080/FDX/TestApp/Vendor" 
	serviceClass="com.dummy.rest.resource.api.VendorRS" inheritHeaders="true"
	loggingFeatureEnabled="true" >
  </cxf:rsClient>/*
Thanks,
Sridhar



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-redirect-through-Rest-cxf-rsClient-not-keeping-orgin-host-information-in-Http-Headers-tp5717882.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel redirect through Rest cxf:rsClient not keeping orgin (host) information in Http Headers

Posted by Willem jiang <wi...@gmail.com>.
Hi,

Current cxf:rsClient doesn't keep the origin host header by default.
But I think you can store the "Host" header value to "X-Forwarded-For"[1] header before you route the message into the camel-cxfrs producer.

Then your server should be able to get remote host from the "X-Forwarded-For"

For the question to get the remote request protocol information, I think you may need for the new coming camel release[2], as you can get the ServletRequest object with the header "HTTP.REQUEST" for the message header, and then you can set the header to as you want when forwarding the request. 

[1]http://en.wikipedia.org/wiki/X-Forwarded-For
[2]https://issues.apache.org/jira/browse/CAMEL-5405

-- 
Willem Jiang

FuseSource
Web: http://www.fusesource.com (http://www.fusesource.com/)
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Thursday, August 23, 2012 at 12:29 AM, dvsridhar wrote:

> Hello,
> We are using Jboss 7.1.1 as our app server and we use camel as the routing
> layer. In the following configuration, vendorConsumer receives the request
> and redirects the request to the actual provider. In response the provider
> sends the data with corresponding hyper links. We create the hyperlink using
> HttpHeader host(Host) and context (org.apache.cxf.request.uri) key values.
> 
> However for the key (Host)) as part of http header we are only receiving the
> redirected URL Host (providerhost) but not the origin Host name
> (REMOTEHOST). *What's the best way to capture this?* I looked through all
> HttpHeaders i don't have any key contains such information except the
> breadcrumbId but its value has some unique format
> ([ID-REMOTEHOST-081075-2474-1345582555484-1-42],) not sure how far i can use
> this. Do I need use custom http headers for this.
> 
> Another question on the same lines, *how do i get the actual protocol
> information (http/https)?* 
> 
> *Note: *Some times we see the whole HttpHeader object it self is null. Not
> sure why Jboss is behaving that way.. 
> 
> *Log of the HTTP Header:*
> 12:10:05,166 INFO [com.dummy.common.utils.CamelCXFRedirectedURL]
> (http--0.0.0 .0-8080-1) {Accept=[text/html, application/xhtml+xml,
> application/xml;q=0.9, */* ;q=0.8], accept-encoding=[gzip, deflate],
> accept-language=[en-us, en;q=0.5], bre
> adcrumbid=[ID-REMOTEHOST-081075-2474-1345582555484-1-42],
> cache-control=[no-cache] , camelcxfrsresponsegenerictype=[class
> javax.ws.rs.core.Response], connection=[keep-alive], content-type=[*/*],
> host=[PROVIDERHOST-097052:8080],
> org.apache.cxf.request.uri=[/fdx-web-1.0/TestApp/Vendor/&3903&COOLEY/],
> pragma=[no-cache], user-ag ent=[Mozilla/5.0 (Windows NT 5.1; rv:14.0)
> Gecko/20100101 Firefox/14.0.1, Apache CXF 2.5.1]}
> 
> * /<camel:camelContext>
> <camel:route>
> <camel:from uri="cxfrs://bean://vendorConsumer"/>
> 
> <camel:removeHeader headerName="Content-Length" /> 
> <camel:to uri="cxfrs://bean://vendorProducer"/> 
> </camel:route>
> </camel:camelContext>
> 
> <cxf:rsServer id="vendorConsumer" address="/Redirect/Vendor"
> serviceClass="com.dummy.rest.resource.impl.VendorRSImpl" 
> loggingFeatureEnabled="true">
> <cxf:extensionMappings>
> <entry key="json" value="application/json"/>
> <entry key="xml" value="application/xml"/>
> </cxf:extensionMappings> 
> </cxf:rsServer>
> 
> <cxf:rsClient id="vendorProducer"
> address="http://providerhost:8080/FDX/TestApp/Vendor" 
> serviceClass="com.dummy.rest.resource.api.VendorRS" inheritHeaders="true"
> loggingFeatureEnabled="true" >
> </cxf:rsClient>/*
> Thanks,
> Sridhar
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-redirect-through-Rest-cxf-rsClient-not-keeping-orgin-host-information-in-Http-Headers-tp5717882.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).
>