Apache Camel Endpoint URI validation - apache-camel

When I got an error inside an Endpoint URI the camel context wont start.
It seems like Camel validates in a first step every Endpoint URI before starting the context.
Can someone pleas tell me, how this works?
Am I right?
I cant figure it out.

Yes Camel validates that it has been configured correctly when it startup. This happens as part of starting the Camel routes.
Its like misconfiguring any other software which will report an error for you to fix.
There is some tooling which you can use to validate your source code to find endpoints that has been misconfigured. I wrote a blog entry about this: http://www.davsclaus.com/2016/01/cheers-fabric8-camel-maven-plugin-to.html

Related

Bridging http request with path variable in CAMEL REST

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

Sending email with camel

I'm having issues sending an email out through camel with the java dsl.
I've been using the camel mail guide but I receive the following error.
Caused by: [com.sun.mail.util.MailConnectException - Couldn't connect to host, port: smtp.google.com, 25; timeout 30000]
Here is what I have in my route
from("timer://foo?period=5000") // Create a message every 5 seconds
.setHeader("subject", simple("hello from camel"))
.setBody(simple("camel"))
.log("sending?")
.to("smtps://smtp.google.com?password=mypass123&username=user#custom.com&From=user#custom.com&To=testuser#gmx.com");
The email service is actually provided by gmail. Now I did see a gmail plugin, but its pretty tough to find an example, so I thought I would use the standard method for now. But if someone knows the solution using it, I welcome it!
PS. I have camel-mail dependency and thecamel-google-mail which I'm not using.
Versions 2.20.2
It was due to less secure apps not fully being turned off.
Use this link here https://www.google.com/settings/security/lesssecureapps
Also some of the silly mistakes pointed out in the comments.
Thanks!

interceptFrom and interceptSendToEndpoint not working

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

How to access a remote web service by Camel CXF endpoint?

I was looking up online how to create a Camel's CXF producer (i.e. create a CXF endpoint that would produce a request to some local/remote web service). Generally, all the examples I could find would list the following steps:
First define the cxfEndpoint attributes:
<cxf:cxfEndpoint
id="orderEndpoint"
address="http://localhost:9000/order/"
serviceClass="camelinaction.order.OrderEndpoint"/>
Then send the request to that endpoint:
...to("cxf:bean:orderEndpoint");
Hmmm. I don't understand the concept. If this is a remote web service, all I usually have is the URL of the WSDL. I can get from it the address of the service... but I don't know what the serviceClass is and I don't have it on my classpath.
So how do I define that cxfEndpoint in case I only have the URL of the WSDL?
Or is there another type of endpoint I should use in that case?
I would suggest looking into WSDL first for cxf. Below are two links that I think should help you out quite a lot and has helped me in the past as well.
http://code.notsoclever.cc/camel-cxf-component-wsdl-first-example/
https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.0/html-single/Web_Services_and_Routing_with_Camel_CXF/index.html#ImplWs-WsdlFirst
On the Red Hat site you will need to start at chapter 3.
Hope this helps.

Camel route does not log when deployed in ServiceMix

I referred below article and created dependencies and log4j properties
http://camel.apache.org/how-do-i-use-log4j.html
Here is my simple route
from("direct:start")
.routeId("LogEipInfoLevelRoute")
.log(LoggingLevel.INFO, "Displaying Something - ${body}")
.to("mock:result");
Once i deploy my route in servicemix, im checking service mix log. I couldnt find any such message logged. except the route creation message with specified id.
Am i checking it in the wrong place?
You need to send a message to the direct:start endpoint for anyting to happen.
If you just want to see something going on, then you can use a timer instead of direct, eg
from("timer:foo?period=5000")
to figure a new message every 5 seconds. Notice the message body is null from a timer.
I assume that you are using OSGI Based ServiceMix version
Please execute following command in karaf console:
karaf#root> log:display | grep Displaying
More about ServiceMix logging systems can be found under http://servicemix.apache.org/docs/4.4.x/users-guide/logging-system.html
You must pass something to direct:start for something to happen. You can read more here about using direct : http://camel.apache.org/direct.html
I would just suggest using a timer to kick off your route. Once your route is kicked off by the timer your log will be written out to your log file.

Resources