I am trying to bridge Camel REST endpoints to a backend server. Corresponding REST DSL is as follows:
from("rest:get:tt:/{id}")
.toF("%s/%s?bridgeEndpoint=true","http://192.168.1.1:80","jjjj/llll/pppp/{id}");
My expectation is that the request should be forwarded to http://192.168.1.1:80/jjjj/llll/pppp/id But what actually happens is that the request gets forwarded to http://192.168.1.1:80/jjjj/llll/pppp/%7Bid%7D/tt/id
Can any one suggest, what am I doing wrong and how I can achieve the desired behaviour? I am using Spring Boot Camel 2.3.4 which uses Camel 3.5.0 internally.
Mean while, I have found a work around that to use .to() instead of .toF(). With .to(), I achieved desired behavior. Camel route DSL is Something like
from("rest:get:tt:/{id}").to("rest:get:jjjj/llll/pppp/{id}?host=http://192.168.1.1:80")
But question still remains open that why it is not working with .toF().
Seems like you're using {id} syntax for http component uri, but I think it's only recognized by the rest component, so instead of having:
from("rest:get:tt:/{id}")
.toF("%s/%s?bridgeEndpoint=true", "http://192.168.1.1:80", "jjjj/llll/pppp/{id}");
you could try using dynamic endpoint .toD() with simple expression ${header.id}:
from("rest:get:tt:/{id}")
.toD("http://192.168.1.1:80/jjjj/llll/pppp/${header.id}?bridgeEndpoint=true");
Not exactly sure if that's what you're aiming for though
Related
We already have project which received request on REST EndPoint and by
using FINITE STATE Machine evaluate next action with Transition and
call action class accordingly.
I am assigned to evaluate possibility to migrate this part to apache camel.
But i am not seeing any value addition as in camel we already defined
routes and we can also use dynamic routing for evaluating next
endpoint.
I googled but couldnt find any Apache Camel example using FSM.
I need comments any use case where we can use FSM in Apache Camel or
we dont require due to nature of Camel.
if anyone found any links for google please share it to.
https://dzone.com/articles/why-developers-never-use-state
Regards,
I was trying to intercept from/to specific rabbitmq route something like the following,
interceptFrom(rabbitmq:localhost/someExchangeName?queue="somerRabbitMqQueueName").to("log:hello");
and i'm not getting anything there.
I've tested
intercept().to("log:hello") and i can confirm it's working, can anyone let me know if there's something else that i need to configure to make the intercept from/to works?
We're using Java DSL and Google Guice for dependency injection.
Some of the project setup as follows,
camel version: 2.18.3 (tried also 2.19.1)
camel-guice: 2.18.3
guice-multibindings: 4.1.0
camel-rabbitmq: 2.18.3
maven-compiler-plugin: 1.7
This was also asked on the Camel mailing list.
Make sure it can match the actual url, so make sure they are exact the
same if you are not using wildcard (*), you can just do
interceptFrom("rabbitmq:localhost/xxx*")
Or try with
interceptFrom("rabbitmq:localhost/xxx?queue=foo*")
See also the Camel documentation, and about the wildcard pattern (in the bottom of the page): http://camel.apache.org/intercept
I currently have a camel route that exposes a cxf endpoint. When a messages comes through the endpoint I would first enrich that message with some information from another webservice and then do more processing afterwards. However, I want make the first half of this route synchronous so I can send back a response to whomever called my exposed cxf endpoint.
The route looks something like this:
from(cxf:CxfEndpoint)
.process(someProcessing)
.to(cxf:ExternalCxfEndpoint)
.to(activemq:queue:somequeue)
//return a response back to caller here
from(activemq:queue:somequeue)
... //additional processing here
...
The reason for this is because when a message comes via my exposed cxf endpoint I don't know if it's a valid message. I need to first validate it with the message enrichment. Once the message is enriched, I want let whomever sent the message know that their message is accepted but don't want them to wait for the message to make it through the whole route as that could take hours.
Does anyone know how this would work?
Thanks in advance!
I believe all you need to do is set exchangePattern to InOnly a.k.a. make it an Event Message. This should have your route not wait for a reply from ActiveMQ. Camel exchange will default to InOut when it's originating from a web service, as in your case.
A related question with an answer from a Camel dev here.
Also see this one for some details on the behavior when your broker is down.
Yes definitely , 100% possible. A simple example would be this :
From cxf endpoint
Store your request in a camel property or header
To xslt - generate xslt for cxf endpoint - Synchronous flow
Reset your original payload using set body.
Wiretap Endpoint - to any endpoint downstream or even a route , this becomes asynchronous . This won't take part in the above sync response .
Note- step 2 & 4 may not be required, it depends on your use case .
There are whole lots of things you can do, I just gave a very simple example . It doesn't need to be wiretap as well, but wiretap helps us not to write any additional custom exceptional handling.
Actually I am playing with apache-camel 2.15.2, the REST DSL available since Camel 2.14 is not complicated. However I can't find in the official documentation how to retrieve a query parameter, basically I would like to target my REST service in this way:
http://myServer/myService/myMethod?myQueryParam=myValue
Is that possible, or is there any workaround ?
Thanks in advance.
Camel uses the REST/HTTP component of choice (restlet, jetty, servlet, netty-http, spark-rest, etc) which maps query parameters as Camel message headers.
So yes you can with the rest-dsl exposes a REST service where clients can call it with query parameters, which is then mapped to Camel message headers during routing.
The concept of routing is nice in theory but in practice, I am a bit confused. I have a CXF method in my webservice
public Response someMethod(Request r) {
}
what I don't get is I need to route the Request to some further node so am I really supposed to do that in the java code or will camel generate an interface(asynch hopefully) that I can wire that node up to some transformer to a next node validator to some store and forward, etc and then finally have the store and forward reply with a Response that is somehow sent out the socket the Request came in from originally.
In the above method, I am forced to return the response back to the client in that method, right?
If I am supposed to put the code in the webservices method, is there some camel context I am supposed to call into?
Also, I want the "RAW" parameters of the SOAP method call and don't want to deal with SOAP Header and then also need to expose some REST apis as well that just accept a String.
EDIT: The proxy example from the answer below is the closest I have seen but even that one if I want to short cut and not even call the real webservice at an earlier node in the pipeline, I can't. I seem to have to call the end webservice code which is not wanted as we don't have any webservice code. We are trying to run it through existing pojos from a webservice call. If the validation node fails, we want to return a response, if it succeeds we want to forward the request on to another node where if that node fails we return a response or if it succeeds we want to forward the request on. There seems to be nothing for this??? Also, this seems like a pretty typical case to me so I am surprised or I am not getting something with all these ESB frameworks(mule, camel so far).
thanks,
Dean
Look at this official Example, it'll show how to do this
Or this Cxf proxy example if you want the RAW request
If you are in a Spring MVC webapp already - you could perhaps do this a bit easier with Spring WS and Jaxb. But that is a matter of taste. Example code here
never solved, we dropped camel as it is quite a pain compared to rolling your own.