One Star

Api Management and routes

Hi all, 
I have a route that's calling a Rest Web service. (see in my little drawing Smiley Tongue)
I have 2 questions please: 
1: what it's wrong with the el exptression I'm using, I retrieve a json data; whan I use a "rout" link between the cMessageRouter and the cProcessor, everything works just fine, but when I try to filter the output, it doesn't work, I also tried the type "simple".
2: how can I  "call the route from an API Manager" (the green part in the drawing )if I can say it this way? is there a component that has to be added to the route? 
If I consume the Rest web service directly, I juste have to use the URL, put it in the API Manager. Now that I'm using the bus, I'm a little confused. 
Thank you for your time
-Regards  
20 REPLIES
One Star

Re: Api Management and routes

I thought about using the cJMS component, but I didn't find any tutorials showing how to send a message from a route to an another application. this link isn't very helpful in my case Smiley Sad
Fifteen Stars

Re: Api Management and routes

You appear to be using the Simple language incorrectly. I am assuming that "id" is a header. Check out the use of the Simple language here. Also, have you set this header anywhere?
About your second question, you wouldn't normally "call a route". A route is just there ready to act on your data. However you can use a cCXF component and a WSDL to enable you to send messages to the route via a SOAP service call. This is reasonably tricky if you are not familiar with the toolset and a little difficult to remotely talk someone through. However, there are tutorials around for this I am sure. Talend actually provide a guide to this component here.
You could use the cJMS component and consume messages from an ActiveMQ. Talend provide instructions on this here.
Rilhia Solutions
One Star

Re: Api Management and routes

Actyually "id" isn't a header, it's a part of the json object
One Star

Re: Api Management and routes

I know that I don't normally call a route, it's just that I didn't know how to express what I want to do.
Normally, so as to consume my service web, I use the URL "localhost:8080/appli..." now I want to introduce the bus between the web service and the api manager, so I can no longer use the URL, I have to  "call the route"/"send a message from the route" (I'm sorry I don't know which is correct) from/to the API manager 
PS: I'm not sure if I can use your solution since I have a REST service, not a SOAP
Fifteen Stars

Re: Api Management and routes

OK. Maybe look at Camel JSONPath to identify the "id". What you are doing in the route at the moment looks like you are trying to retrieve a header using the Simple language. I can't give you the answer here as I would need to try it out to work it out myself.
With regard to calling the API Manager, I misunderstood. I thought you were talking about initiating the route replacing the cTimer. You will need to give us more information on the API Manager. What interfaces does it supply? The whole point of an ESB is that it can communicate with different systems in a plethora of different ways, so you will be able to communicate with it. But what are the options?
Rilhia Solutions
One Star

Re: Api Management and routes

Well, I'm using the API Manager "APIMAN".
What I'm asked to do, is to  place the bus just in the middle, so that communication between the Rest web service, Apiman and BonitaSoft would be garanteed using routes. 
So I made a route consuming the web service, 
my quetsion, in other terms, would be, how could the route send the json it has received from the web service, to the API manager?? 
because normally,apiman would implement the URL "localhost:..." I've already used in the cHTTP component, but now, Apiman will receive the output of the route.
I hope my question is more clear now. 
please find the  architecture of my project attached.
Fifteen Stars

Re: Api Management and routes

I don't know APIMAN I am afraid. But briefly Googling it has revealed that is provides a REST API service. In which case I imagine you can use that to communicate with it. You need to use a cHttp configured as a client to do this.
To get the response from the cHttp you have used previously, you may want to use a cProcessor component to interrogate the Exchange object. Take a look at this for examples of working with the Exchange object.
Unfortunately Talend ESB is much easier to work with if you are familiar and comfortable working with Java. As a product of that, it is harder to help in this situation by simply suggesting using particular components. I think you will need to use a bit Java to deal with getting hold of the JSON string .....
String json = exchange.getIn().getBody(String.class);

....or ....
${in.body}

....if you want to use the Simple language in your cHttp component sending the JSON.

I would have to try a few things out before I got it right. That is what I recommend here. The more you try out, the more you will learn. Unless someone has carried out this exact task, I reckon it will take some time with a lot of backwards and forwards exchanges before you get the answer.
Rilhia Solutions
One Star

Re: Api Management and routes

I'm afraid I still didn't make myself clear enough. 
Firstly, I've already used the bit of code 
System.out.println("Body received: " +exchange.getIn().getHeader("CamelFileName") +"\nContent:\n " +exchange.getIn().getBody(String.class));

in the cProcessor to print the json body I received from my web service, here's the output: 
,"routingConstraintsLigneses":[],"routeses":[]}]

Now concerning the matter with Apiman. The whole point of using a bus, is to garantee communication between different systems, if I'm not mistaken. 
My systems are: 
  1: a service web
  2: an api manager
normally, I would use the the URL "localhost:..." as an endpoint in apiman to consume the web service, which would be: 
   ==JSON==>
now I want to put talend between those two systems: 
   ==json==>  Talend(route)  ==>  
in my case, apiman should consume the route message instead of getting it from the web service directly. 
the point is, I don't know how could a route "deliver" a message to an other system, wether it's apiman or sth else. 
as show in the screenshot, I should write an "api endpoint", when I exposed the web service directly, I just had to put the URL, but now that I introduced the bus in the middle, I don't know how to "expose the route" ,if I may say,in apiman. 
Fifteen Stars

Re: Api Management and routes

OK, so you are familiar with the Exchange object. That is good to know. 
The problem we have here is that you are not explaining how you can communicate with APIMAN. I have suggested via a REST service, but that is a guess from quickly Googling APIMAN. APIMAN is not a Talend product. While an ESB is meant to enable communication between devices/systems, you need to know the interfaces that are available. If your interface was a Java API, I would say call it in a cProcessor component. If it is A REST service, I would say call it via a cHttp configured as a client. It could even be a flat file that needs to be placed into a particular location to be consumed by APIMAN. As I do not know what the interface is or the details of that interface, I can't really give any more info than I have already.
Rilhia Solutions
Fifteen Stars

Re: Api Management and routes

If I understand you correctly, without Talend you are communicating with APIMAN using a REST service. If that is the case you can do that with Talend using the cHttp component. It needs to be configured to call the APIMAN REST service and supply the JSON string that you have in your Exchange In body. 
Rilhia Solutions
One Star

Re: Api Management and routes

the point is that it's APIMAN that should call talend (the route), not the opposite.
Yes apiman is a rest service, but it's used to expose other web services.  
The communication with APIMAN is done only using a URL, so is there anyway that the output of the route can be accessible/consumed using a "localhost:/....", if yes, that would solve my probleme. 
Fifteen Stars

Re: Api Management and routes

So you are not wanting the route to call APIMAN. You do realise that a route does not work in the same way as a service. You do not "call" a route. A route does a job. It is triggered by an action, but you do not "call" the result. The result is delivered. It is "pushed". What you can do is "push" that result into a queue (or something similar) and then create a web service that can be called by APIMAN to retrieve the message. But you cannot have a route triggered and for it to simply hold on to the result until it is a called by something. 
The best case I can think of for what I know now would be to use an ActiveMQ and simply dump the messages into the queue at the end of the route. With a route the messages have to go somewhere. For that use case, you need to push them to a queue or maybe to a database. If you are wanting to put them in a queue to be consumed by APIMAN then you will need to use a cJMS component. However you will need to have a mechanism for getting them from the queue to APIMAN if it doesn't already support that mechanism.
Saying that APIMAN consumes messages using "localhost:" means absolutely nothing I am afraid. You need to let us know what protocol is used, what is consumed, how often it is consumed, what is happening? 
Rilhia Solutions
One Star

Re: Api Management and routes

Okey, thank you 
I'll try to do some readings about apiman
One Star

Re: Api Management and routes

I reconsidered the problem, and I thought about a different manner to connect apiman and talend. 
1. create a job   :   tRouteInput-->tRestRequest-->tlog
2. create a route:                   cTimer-->chttp-->cTalendJob (assigned to the job bellow)
Apiman will call the job, that call will trigger the route (since the job is assigned to it), and the route will act on my service web. 
what do you think plz?
Thank you 
Fifteen Stars

Re: Api Management and routes

The cTalendJob is attached to the Route. They are used to process Route messages. Your job will need to receive the Route message with a tRouteInput and return the message with a tRouteOutput. But I don't believe your thinking will work here. The cTalendJob is called by the Route. It doesn't start the Route.
Can you get APIMAN to call a service of any kind? How can APIMAN communicate with other systems (API, REST, SOAP, Flat file, etc)?
Rilhia Solutions
One Star

Re: Api Management and routes

1. yes, I got Apiman to call a Rest job that I've created using TOS. 
2. Out of the box, apiman listens on HTTP and communicates with back-end services also on HTTP.
here's a simple view of the architecture of apiman:
**APIManager backend: It exposes a set of REST interfaces for managing the APIs. It is the one holding the API Management information (data model). Every time an API has to be published, it communicates via REST with the APIGAteway Config.
**APIGateway Config: It is the layer for managing an APIGateway. It exposes a REST interface for management, and stores the management/configuration state.
**APIGateway Runtime: The APIGateway Runtime will be primary runtime component of apiman, and will proxy requests from consumers to the services, applying a set of policies for delivering the service. This is the endpoint that will be known by applications. This will be the single source of requests to the services (APIs).
Fifteen Stars

Re: Api Management and routes

OK, here is my suggestion....
Create a Route where the first component is a cHttp component set up as "server". This can be callled by APIMAN and will act as the action to trigger the Route. This route will also call a cHttp component set up as a "client", used to call the service that you need to call.
cHttp(Server - Called by APIMAN)--> cProcessor (Do something, anything)-->cHttp(Client - Call your REST service)-->cProcessor(etc)
The cHttp (Server) is called by APIMAN
The cProcessor can do something with the message (not necessary, but may be useful)
The cHttp (Client) is used to call your REST service
The last cProcessor is used to process the response from the REST service call
After this you could have a cTalendJob to do something with the message like send it to a DB, whatever you want.
Take a look here for how to use the cHttp component
Rilhia Solutions
One Star

Re: Api Management and routes

Good morning, 
Thank you for your suggestion, I'll give it a try 
One Star

Re: Api Management and routes

it works like a charm 
thank you very much Smiley Very Happy
Fifteen Stars

Re: Api Management and routes

No problem. Hopefully the frustrations you have had will lead to a better understanding. I spent months wanting to throw my computer out of the window when I first started playing with Talend ESB :-)
Rilhia Solutions