Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] REST service proxy route

Hello!
Using Talend ESB, I want to proxy my REST service that is deployed, for example, on: http://hostnameA:8080/web_app to http://hostnameB:8085/web_app. That means, when I want to invoke the service (http://hostnameA:8080/web_app), I need to invoke them on: http://hostnameB:8085/web_app. It is just a simple proxy route.
I tried to do this using TOS and Talend ESB Studio, but without result. I tried something similar with Axis web services and works fine. My configuration for this case was:
Part of camel-config.xml file



address="http://proxy_hostname:8090/application/service/TokenService"
endpointName="s0683p000009M9p6.pngervice"
serviceName="s:TokenService"
wsdlURL="etc/TokenService.wsdl"
xmlns:s="http://tempo.intalio.org/security/tokenService/"/>


serviceName="serviceNS:TokenService"
endpointName="serviceNS0683p000009M9p6.pngervice" address="http://hostname:8080/axis2/services/TokenService">

....









Can someone help me?
Thanks in advance!

Labels (1)
  • Other

27 Replies
Anonymous
Not applicable
Author

Hi,
I found the solution to proxy authentication parameters from my Proxy service to REST internal service.
I added the following line to the cProcessor component:
exchange.getOut().setHeader("Authorization",exchange.getIn().getHeader("Authorization"));
It isn't necessary to use the cSetHeader component.
I have another question:
As you have seen, my REST internal service has this endpoint:
http://mashina:8080/alfresco/service/abitecm/process/28/doctypes/banka.odobravanjeKredita.gotovinski.kreditniZahtjev
"28" is a parameter and the "banka.odobravanjeKredita.gotovinski.kreditniZahtjev" is also a parameter
This endpoint was just for testing. The real endpoint is:
http://mashina:8080/alfresco/service/abitecm/process/PARAMETER1/doctypes/PARAMETER2
My requirement is: I want to be able to invoke the REST Internal service using the Proxy service by sending the parameters PARAMETER1 and PARAMETER2.
How should I configure my endpoints in the Proxy service and REST Internal service to meet my requirement? Do I need to re-configure my cProccesor component (Proxy)?
Thanks in advance!
Anonymous
Not applicable
Author

Hi,
When you say parameters to you mean HTTP header, or perhaps using a query string?
You can get access to query or set your own custom HTTP headers:
System.out.println("uri: " + exchange.getIn().getHeader(org.apache.camel.Exchange.HTTP_URI));
System.out.println("params: " + exchange.getIn().getHeader(org.apache.camel.Exchange.HTTP_QUERY));
System.out.println("Param1="+ exchange.getIn().getHeader("X-Param1")); <---- you can add a header quite easily using the REST Client from Firefox.

Setting your own headers is quite simply. Using the query string you need to parse the string and then access the values.
Note: just a general note, if security is an issue, you should never expose any of the internal proxies URL, even if it's only part of the full URL. Rather, better off provide a mapping with the ProxyService, thereby the external client never understands any part of the internal REST service.
Thanks
Anonymous
Not applicable
Author

Hi,
No, I don't want to use a HTTP header as a parameter.
My REST service has two parameters - "28" and "banka.odobravanjeKredita.gotovinski.kreditniZahtjev": http://mashina:8080/alfresco/service/abitecm/process/28/doctypes/banka.odobravanjeKredita.gotovinski.kreditniZahtjev
The response of this service is a link to a document for process number 228" and doctype "banka.odobravanjeKredita.gotovinski.kreditniZahtjev".
A response can also be another document link, for another process, eg. 256 and other doctype, eg. banka.odobravanjeKredita.gotovinski.IsplatnaLista.
The request is the same, but with other parameters:
http://mashina:8080/alfresco/service/abitecm/process/256/doctypes/banka.odobravanjeKredita.gotovinski.IsplatnaLista
How should I configure the endpoints in Proxy service (cMessageEndpoint_1) and Internal Service (cMessageEndpoint_2) to be able to call the Internal service with other parameters using the same route?
Thanks
Anonymous
Not applicable
Author

Hi,
Try the following - connect a http message_endpoint to a cProcessor to another http Message_endpoint.
1. configure your jetty listener to allow all matching URIs (see http://camel.apache.org/how-do-i-let-jetty-match-wildcards.html)
"jetty:http://localhost:9000?matchOnUriPrefix=true"

2. In the cProcessor you need to grab the inbound URI and set the URI for the request to the Internal service
//grab inbound URI
String inbound=(String)exchange.getIn().getHeader(org.apache.camel.Exchange.HTTP_URI);
// setup URI for internal service
exchange.getOut().setHeader(org.apache.camel.Exchange.HTTP_URI, constant("http://localhost:8888"+inbound));

3. connect your cProcessor to a message endpoint (http://localhost/doesnotmatter") <--- the component only needs to be a "http://something"

Basically this should create a new URL based on the inbound URI for the resource + the Internal host/port, in my case localhost:8888
Cheers
Anonymous
Not applicable
Author

Hi cydnes,
the route is finally completed and works fine. :-)) I've tested the route with various hostname configurations and REST service parameters - all routes are working fine and I get the expected result -> link to my document.
For those who want the same functionality, my final configuration is:
1. Proxy Service endpoint (cMessageEndpoint_1):
"jetty:http://hostnameA:8085/alfresco/service/abitecm/process?matchOnUriPrefix=true"
2. Proxify (cProcessor):
//If I do not remove the header, you will get the error "host parameter is null"
exchange.getIn().removeHeaders("CamelHttpPath");
//grab inbound URI
String inbound=(String)exchange.getIn().getHeader("CamelHttpUri");
// setup URI for internal service
exchange.getOut().setHeader("CamelHttpUri", constant("http://hostnameB:8080"+inbound));
//setup Authorization
exchange.getOut().setHeader("Authorization",exchange.getIn().getHeader("Authorization"));
//Create response message
exchange.getOut();
3. REST Internal Service (cMessageEndpoint_2:
"http://hostnameB:8080"
That's it!
Thanks a lot for your help!
Best Regards
Anonymous
Not applicable
Author

Great! Nice to see it working.
One suggestion is to use the Context mechanism to allow for configuration of the hosts and ports for the Proxy endpoint and also the internal web server.
In the Proxy Service URL, set it to
"jetty:http://"+context.host + ":"+ context.port +"?matchOnUriPrefix=true"

In the cProcessor, use the context variables ->>
String inbound=(String)exchange.getIn().getHeader(org.apache.camel.Exchange.HTTP_URI);
System.out.println("> " + "http://"+context.internal_host+":"+context.internal_port+inbound);
// set URI for internal service
exchange.getOut().setHeader(org.apache.camel.Exchange.HTTP_URI, constant("http://"+context.internal_host+":"+context.internal_port+inbound));

Lastly create the 4 context values with default values in the properties panel
host=0.0.0.0
port=80
internal_host=myhost
internal_port=8000
Anonymous
Not applicable
Author

Hi cydnes,
Thanks for your suggestions!
_AnonymousUser
Specialist III

Hi,
can you tell how do we put certificate in this configuration?
So our endpoint is now: https://hostnameB:8443 and we have problem with certificate.
Where and how to set certificate so that service also work on https?
Thanks and regards,
Jurica
Here is an error:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1731)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1206)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:925)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:637)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:89)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:828)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.flushRequestOutputStream(MultiThreadedHttpConnectionManager.java:1565)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2116)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at org.apache.camel.component.http.HttpProducer.executeMethod(HttpProducer.java:195)
at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:100)
at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:77)
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:104)
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:272)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:98)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:77)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)