Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
user19
Contributor
Contributor

How to Map the Endpoint

I am trying to create a Rest route in Talen ESB open studio. I have an endpoint which has multiple methods inside.I access my API from Metadata. how can I reroute each endpoint according to its method. lets say endpoint is http://Example/api/version/Method/operation. it has four methods Rawdata, balancing, customdata and final data. all these methods has multiple operations. http://Example/api/version/Rawdata/getRawdata

http://Example/api/version/Rawdata/getdatafromfields

http://Example/api/version/balancing/getfiltereddata

How can I tell talend that when I call Rawdata in Soapui send this endpoint. which components i can use or can Java code can do it? Any help would be appreciated.

0695b00000PNHk2AAH.png

0695b00000PNHk7AAH.png

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Sorry about the delay in getting back to you here. I had to play around to figure this out. You may need to calculate your endpoint (in vs out) using some code in the cProcessor, but this is how you can switch them in the cREST_2.

 

Use the Relative Path to set the endpoint using a header. The way I tested this was as follows...

 

  1. My cREST_1 has 2 methods. They are "/employees" and "/employee/{number}". These methods are included in the "CamelHttpPath" header of the Exchange. When the "/employees" method is called, that is set to the header, when the "/employee/{number}" is called, that is set to the header. This is where you may need to manipulate yours if your input methods are not the same as the methods you are wanting to call.
  2. Then in my cREST_2 component, I simply set the Relative Path value to be simple("${header.CamelHttpPath}")

 

Give that a go and see what you think.

View solution in original post

15 Replies
Anonymous
Not applicable

Sorry about the delay in getting back to you here. I had to play around to figure this out. You may need to calculate your endpoint (in vs out) using some code in the cProcessor, but this is how you can switch them in the cREST_2.

 

Use the Relative Path to set the endpoint using a header. The way I tested this was as follows...

 

  1. My cREST_1 has 2 methods. They are "/employees" and "/employee/{number}". These methods are included in the "CamelHttpPath" header of the Exchange. When the "/employees" method is called, that is set to the header, when the "/employee/{number}" is called, that is set to the header. This is where you may need to manipulate yours if your input methods are not the same as the methods you are wanting to call.
  2. Then in my cREST_2 component, I simply set the Relative Path value to be simple("${header.CamelHttpPath}")

 

Give that a go and see what you think.

user19
Contributor
Contributor
Author

@Richard Hall​  how you added these methods in "CamelHttpPath"?

user19
Contributor
Contributor
Author

I was trying to get the query parameter from the header.

0695b00000QC3QFAA1.png

Anonymous
Not applicable

The CamelHttpPath header is automatically set with the path you are calling which you've specified for the method. In the code above you appear to be looking for the CamelHttpQuery header.

 

 

user19
Contributor
Contributor
Author

@rhall it is throwing HTTP/1.1404 Not found

Probably it can't identify the method. can you please guide me how can  to calculate endpoint (in vs out) using some code in the cProcessor. I mean any example?

Anonymous
Not applicable

I made sure that my methods were structured in exactly the same way as the methods of the API I am calling (just to keep it simple). So my methods look like this in my config......

 

0695b00000QC4QuAAL.png 

The code in my cProcessor is just this.....

 

System.out.println(exchange.getIn().getHeader("CamelHttpPath"));

 

I am just using it to check the value of the header.

 

It produces the following. See that they match the methods I set up (apart from there being an actual number instead of the "{number}"....

 

/employees

/employee/1

/employee/2

 

In your cProcessor, you will need to get this value, compute the String you need for the API you care calling and set it to a new header value. Then use that header in the Relative Path of the cREST_2, as I showed the post above.

user19
Contributor
Contributor
Author

@Richard Hall​  I am able to deploy the route and call the methods. I have swagger specification in this route. I can see list of operations in my http://localhost:9001/services/api/swagger.json if I try to get some data then I get response code 404 no content. Since I used simple("${header.CamelHttpPath}") for my route and now swagger is not getting any parameters. Is there any way to pass the parameters to swagger?

Anonymous
Not applicable

If you're talking about query parameters (parameters provided in the URL with ? and &, etc), you can see these in the CamelHttpQuery header. If you need to use these, I suspect that there will be some String manipulation required.

user19
Contributor
Contributor
Author

@Richard Hall​ thank you for the response. yes I am talking about query parameter. but now where can I specify query parameter for swagger? in my CREST2 in Relative path I am already using simple("${header.CamelHttpPath}" + context.relativePath)