You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by contactreji <co...@gmail.com> on 2015/06/08 20:24:32 UTC
Camel Restlet
Hi
I am trying to do a POC using camel-restlet component. I was wondering if I
use something like follows
<route>
<from uri="restlet:http://0.0.0.0:8181/cars/100?httpMethods=get,post"/>
........
</route>
Suppose I hit the endpoint with
*http://localhost:8181/cars/100?color=red&model=2015* with a http GET
method, how do I access the *color=red* data in camel exchange. where does
it get stored?
When i print the camel header CamelHttpQuery, I can see it printint as
color=red&model=2015. Is there any way i can have 2 separate headers in
camel exchange named color, model populated with red,2015 respectively?
Cheers
Reji
-----
Reji Mathews
Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & Jboss Fuse ESB | Mule ESB )
LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
Twitter - reji_mathews
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by Gnanaguru S <gn...@gmail.com>.
By the way, you can give it a try with Rest DSL as well !
Cheers
Guru
@tallguru
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5767996.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by contactreji <co...@gmail.com>.
Hi Ravindra
In my code its like follows for the restlet consumer endpoint.
<from uri="restlet:
http://0.0.0.0:8181/cars/{id}?httpMethods=get,post"/>
Am sorry but in my first post, I accidentally kept it /100.
I understand that the values in path parameters will get mapped as headers.
I was interested more in queryparams.
Was thinking if there is some neater way out without any extra parse logic.
Nevertheless, parsing CamelHttpQuery has served the purpose.
Cheers
Reji
-----
Reji Mathews
Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & Jboss Fuse ESB | Mule ESB )
LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
Twitter - reji_mathews
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5768006.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by Ravindra Godbole <go...@gmail.com>.
Hi
You will have to parse the query string yourself.
In order to get the values in header and use the api to get the same, you
will have to set the endpoint uri correctly.
For example
<from uri="restlet:
http://0.0.0.0:8181/cars/100/{color}/{year}?httpMethods=get,post"/>
If your request is like this ...
http://0.0.0.0:8181/cars/100/red/2004, then you can access the values in
code like this..
String color = exchange.getIn().getHeader("color", String.class);
String year = exchange.getIn().getHeader("year", String.class);
For more details refer to https://camel.apache.org/restlet.html
On Mon, Jun 8, 2015 at 11:54 PM, contactreji <co...@gmail.com> wrote:
> Hi
>
> I am trying to do a POC using camel-restlet component. I was wondering if I
> use something like follows
>
> <route>
> <from uri="restlet:http://0.0.0.0:8181/cars/100?httpMethods=get,post"/>
> ........
> </route>
>
> Suppose I hit the endpoint with
> *http://localhost:8181/cars/100?color=red&model=2015* with a http GET
> method, how do I access the *color=red* data in camel exchange. where does
> it get stored?
> When i print the camel header CamelHttpQuery, I can see it printint as
> color=red&model=2015. Is there any way i can have 2 separate headers in
> camel exchange named color, model populated with red,2015 respectively?
>
> Cheers
> Reji
>
>
>
> -----
> Reji Mathews
> Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel
> & Jboss Fuse ESB | Mule ESB )
> LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
> Twitter - reji_mathews
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
- Ravi
*[ View My Youtube Channel
<https://www.youtube.com/playlist?list=PL5Y_TlNjh0D59A4K3yQQR7gNAslnxDmRB>
]*
Phone: +91 *98 509 760 91*
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
I have created a separate thread for the XML issue,
http://camel.465427.n5.nabble.com/Parsing-a-XML-in-DSL-td5770368.html
Can you please help me out? I shall delete the threads irrelevant to this
thread
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770369.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Agree, my bad. I will create new discussion going forward. I will test this
and let you know if it worked for me. If not, then i shall create a new
thread and let you know on the same.
Thanks a lot for your help. Appreciate it.
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770366.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Can you please help me with parsing an XML to get a node's value? Am trying
with xpath as given below
<xpath>/data/Provider()</xpath>
But this doesn't work. My input to a route is XML and i want to get a node's
value and route it based on it. I tried this
<xpath>${in.body}/data/Provider()</xpath>
But that didn't work either.
Can you please let me know how to resolve this?
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770364.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Am using JBOSS server. I have a question related to passing arguments to a
Javascript. In my route am calling a JavaScript this way,
<to uri="language:javascript:file:/generatetoken.js" />
Is there a way to pass arguments to this Javascript?
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770284.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
I was able to resolve the issue. It was due to a JAR which was conflicting
with a newer version JAR. After removing the old JAR I am able to send the
message to Rest API.
Thanks a lot for your help. Really appreciate it.
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770264.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
But i just noticed that when i have HTTPS and mention :443 as the port
number, i get the header missing error again. So basically the header is not
being set for some reason. But i don't understand why
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770261.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Is there a difference in way it works in browser? Coz i see that when i
access the REST URL in browser i don't get any SSL errors coz of the CA
trusted certs the URL has. Do you reckon having .jks file in classpath is
the only way to access URL over HTTPS connection?
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770256.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Although one concern i have is that if the certificate from Server is changed
in future then i have to import new cert. Can you let me know how to access
the keystore in route URI? Is there any specific attribute to mention the
keystore?
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770233.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Thanks for letting me know. Am fairly new to Camel. Should i place the
certificate in my Trusted certs directory, or should i handle it in my
route?
Also,Can you please provide me an example on how to use Camel-jetty for
invoking REST API?
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770231.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
My connection was meant to be HTTPS but i was using HTTP in my URL. Now when
i change my URL to HTTPS, i get the following error,
WARNING [org.restlet] (Restlet-69709808) Exception while writing the
message headers.: javax.net.ssl.SSLException: Unrecognized SSL message,
plaintext connection?
Can you let me know how to resolve this?
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770227.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Also, i have another question on how to pass arguments to a Javascript from
route. I have the following route,
<route id="callTokenService">
<from uri="direct:inter1" />
<log message="Routing to Javascript" loggingLevel="INFO" />
<log message="Message body ${in.body}" loggingLevel = "INFO" />
<to uri="language:javascript:file:/data/product/generatetoken.js" />
When i try to pass arguments to this Javascript (generatetoken(key).js), it
throws error saying file not found. The argument is being considered as a
file name here. Can you let me know how to pass arguments to a Javascript?
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770216.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
This is the error message i get
04:25:01,428 INFO [callRestAPI] (Camel (camelAgent) thread #2 -
JmsConsumer[ISEEOutboundQueue]) Routing to RestAPI
04:25:01,430 INFO [callRestAPI] (Camel (camelAgent) thread #2 -
JmsConsumer[ISEEOutboundQueue]) Headers set in Javascript
{Authorization=MyToken,
Content-Type=application/atom+xml;type=entry;charset=utf-8}
04:25:01,861 ERROR [org.apache.camel.processor.DefaultErrorHandler]
(Restlet-910628961) Failed delivery for exchangeId: Exhausted after
delivery attempt: 1 caught:
org.apache.camel.component.restlet.RestletOperationException: Restlet
operation failed invoking http://MyRESTAPI/public/messages with statusCode:
401 /n responseBody:<Error><Code>401</Code><Detail>MissingToken: The
authorization header was not found.
TrackingId:da04b482-9d16-4d71-8899-17c0df90d273_G22,TimeStamp:8/2/2015
8:25:02 AM</Detail></Error>:
org.apache.camel.component.restlet.RestletOperationException: Restlet
operation failed invoking http://MyRESTAPI/public/messages with statusCode:
401 /n responseBody:<Error><Code>401</Code><Detail>MissingToken: The
authorization header was not found.
TrackingId:da04b482-9d16-4d71-8899-17c0df90d273_G22,TimeStamp:8/2/2015
8:25:02 AM</Detail></Error>
at
org.apache.camel.component.restlet.RestletProducer.populateRestletProducerException(RestletProducer.java:193)
[camel-restlet-2.10.3.jar:2.10.3]
at
org.apache.camel.component.restlet.RestletProducer$1.handle(RestletProducer.java:93)
[camel-restlet-2.10.3.jar:2.10.3]
at
org.restlet.engine.http.connector.BaseClientHelper.handleInbound(BaseClientHelper.java:714)
[org.restlet-2.0.5.jar:]
at
org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
[org.restlet-2.0.5.jar:]
at
org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
[org.restlet-2.0.5.jar:]
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
[org.restlet-2.0.5.jar:]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
[rt.jar:1.6.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[rt.jar:1.6.0_45]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_45]
And this is the route i use,
<route id="callRESTAPI">
<from uri="direct:inter2" />
<log message="Routing to RESTAPI" loggingLevel="INFO" />
<setHeader headerName="Authorization">
<simple>Sometokenvalue</simple>
</setHeader>
<to uri="restlet"http://MYRESTAPI/public/messages"/>
<to uri="direct:inter3" />
</route>
Can you please let me know what am missing here?
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770214.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Yes, it is Authorization. I have tested it from a local REST client with the
same header, and that works fine.
I just noticed that when i set the headers i get an error message saying
there are no consumers to process the message. But when i don't set the
headers i get the error of header missing
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770212.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by Gnanaguru S <gn...@gmail.com>.
This looks like, the API which you are calling is not expecting this header.
Are you sure it is 'Authorization' ? It can be something else as well, like
X.Authorization.
Otherwise I dont see an issue with the way you are setting the header.
Cheers
Guru
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770210.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by "anish.somadevan" <ne...@gmail.com>.
Am having a similar kind of issue where am not able to send custom headers to
a REST URL using camel restlet. This is my route,
<route id="callRESTAPI">
<from uri="Myapplication" />
<from uri="direct:start"/>
<setHeader headerName="Authorization">
<simple>token</simple>
</setHeader>
<to uri="restlet:http://MyRESTAPI/messages"/>
</route>
But i get a error message from the API mentioning that the header is
missing. Is there a way to set Custom headers in camel restlet and pass it
during the API call?
Thanks,
Anish
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5770209.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by Gnanaguru S <gn...@gmail.com>.
Not sure how much this will help, but you can always do this ${headers}.
Which will print all the headers available for you !
Cheers
Guru
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5768043.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Restlet
Posted by jkorab <ja...@gmail.com>.
Hi Reji,
contactreji wrote
> Suppose I hit the endpoint with
*
> http://localhost:8181/cars/100?color=red&model=2015
*
> with a http GET method, how do I access the
*
> color=red
*
> data in camel exchange. where does it get stored?
HTTP consumer endpoints such as Jetty (and I am guessing therefore Restlet
as well) put the URI parameters directly into exchange headers. So to access
the color, all you have to do is something like:
<log message="Received request for ${header[color]}"/>
Jakub
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Restlet-tp5767988p5768022.html
Sent from the Camel - Users mailing list archive at Nabble.com.