Four Stars

Consume REST API with 1 header

Hi,

 

I'm trying to call a simple 'Hello World' REST API via the GET verb. The API is only expecting one HTTP Header, Accept application/json which i've set in the advanced settings of my tRestClient component. However, Talend seems to automatically create another entry for the contents of the Accept Type dropdown. When i run I’m getting HTTP 406 Not Acceptable back because the API is not expecting 2 headers. 

 

I've tested this API with other software and it responds correctly so it must be down to Talend configuration. Anybody know a way around this or had a similar issue they've resolved?

 

I have screenshots but unfortunately they're being blocked by my firewall at work. Sorry

 

Thanks

Matt

 

 

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Thirteen Stars

Re: Consume REST API with 1 header

OK, I would recommend just reinstalling Studio. I have seen this sort of problem happen quite a few times. It is probably quicker to reinstall than try to hunt through the broken install. Ensure you have backed up your project if you are not using the Enterprise Edition.

Rilhia Solutions
19 REPLIES
Thirteen Stars

Re: Consume REST API with 1 header

I may be missing something here (I'm having a quick look on my phone while on the train), but why doesn't just setting the accept type to JSON not work? You should not need the other header you are setting? Have you tried this? The number of headers set shouldn't really cause you a problem unless you are not setting enough or possibly if you are setting one twice with different values.
Rilhia Solutions
Seven Stars

Re: Consume REST API with 1 header

It may hep to post the whole RAW transaction for the GET. This seems odd that something would be added automagically.
Four Stars

Re: Consume REST API with 1 header

Thanks, I did try just setting the accept type to JSON but the API i'm calling is expecting something like application/sofwarename1.0json rather than just JSON so i get a 406 error again.

 

I'm currently trying to use t_Rest as this doesn't set the accept type for you but i'm getting errors with the Jersey files

 

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
com.sun.jersey cannot be resolved to a type
com.sun.jersey cannot be resolved to a type
com.sun.jersey.client cannot be resolved to a variable
com.sun.jersey cannot be resolved to a type
com.sun.jersey cannot be resolved to a type
com.sun.jersey.api.client.Client cannot be resolved to a type
com.sun.jersey cannot be resolved to a type
com.sun.jersey cannot be resolved to a type
com.sun.jersey cannot be resolved to a type
com.sun.jersey cannot be resolved to a type

Four Stars

Re: Consume REST API with 1 header

when i run fiddler to intercept what Talend is sending i can see that the tRestClient component is indeed sending 2 accept headers (ignore the application/xml in the screenshot, i forgot to take a screenshot when i tried json, the result is the same, 2 headers). 

Thirteen Stars

Re: Consume REST API with 1 header

Accept-Type JSON in the drop down is actually "application/json". It looks like you may have selected XML there. Have you tried setting this to JSON and not adding your own header in the Advanced settings tab?

Rilhia Solutions
Four Stars

Re: Consume REST API with 1 header

Sorry that was the wrong screenshot. I did set it to JSON and get the same (Accept: application/JSON, application/*****+json. I have also tried removing what i've set in Advanced settings but still get the 406 error. I can get a response in Postman which is leading me to believe it is something with the component config in Talend.postman.JPG

Thirteen Stars

Re: Consume REST API with 1 header

What file were you sending there? I think we are going around in circles. I thought you wanted to send a file somewhere, but that does not look like you are sending anything other than a JSON String in the body of the message. What exactly needs to be sent? 

Rilhia Solutions
Four Stars

Re: Consume REST API with 1 header

Sorry for the confusion, i'm new to web services and may not be using the correct terminology. I've taken a screenshot of the API i'm trying to call and how i've configured tRestClient.

 

advanced settings.jpg

settings.jpg 

API definition1.jpg

Thirteen Stars

Re: Consume REST API with 1 header

Sorry, my mistake. I am trying to help two people with web service issues and I got confused as to who I was talking to

Rilhia Solutions
Thirteen Stars

Re: Consume REST API with 1 header

The top image is not very clear (Advanced Settings). I assume you are setting your bespoke Accept type there. Can you show us what this is? Why have you starred out part of the value? It shouldn't need to be secret and might help knowing what this is

Rilhia Solutions
Four Stars

Re: Consume REST API with 1 header

This is the API spec

 

Request headers

Name           Value

Accept      application/vnd.hmrc.1.0+json

 

Authorisation
This resource is open access - no Authorization header is required.

 

Response
HTTP status: 200 (OK)

{
"message" : "Hello World"
}

 

Thirteen Stars

Re: Consume REST API with 1 header

OK, this is strange behaviour from the web service. I've figured it out (I guessed the service you were trying to use). It appears that it is rejecting multiple Accept types.....which I don't believe it should. The best way to get around this is to use the tRest component. I have just tested it and it worked straight away if you follow the screenshot I have added.....HMRC service.png

 

By the way, for a public service like HMRC there is no need to be secretive about the host of the service. Obviously don't give away personal login credentials, but when there is a public test service, feel free to give that information. With access to the service I was able to try out a few things very quickly.

Rilhia Solutions
Four Stars

Re: Consume REST API with 1 header

Ok thanks really appreciate your help and advice.

 

I'm trying tRest and now i get a different error (maybe this should be a new post). When i configure tRest the same as you i get 

 

 

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
com.sun.jersey cannot be resolved to a type
com.sun.jersey.client cannot be resolved to a variable
com.sun.jersey.api.client.Client cannot be resolved to a type


I've checked and i have both jersey-client-1.4.jar and jersey-core-1.4.jar installed. I've tried using a tLibraryLoad to make sure these are loaded but still get the error. Any ideas?

 

 

 

Thirteen Stars

Re: Consume REST API with 1 header

What version of Talend are you using? I'm using 6.2.1 at the moment and have not had to do anything special to use this component with no problems.

 

Can you check your ../workspace/Java/lib folder for the jerset-core-1.4.jar and jersey-client-1.4.jar?

Rilhia Solutions
Four Stars

Re: Consume REST API with 1 header

I'm on 6.4.1 and the two jar files are in both Workspace\.Java\lib and Talend\6.4.1\studio\configuration\.m2\repository\org\talend\libraries

 

I've asked a colleague on the same version to test and they can compile the same job on their machine. Going to check my java paths are set up correctly. 

Thirteen Stars

Re: Consume REST API with 1 header

OK, I would recommend just reinstalling Studio. I have seen this sort of problem happen quite a few times. It is probably quicker to reinstall than try to hunt through the broken install. Ensure you have backed up your project if you are not using the Enterprise Edition.

Rilhia Solutions
Four Stars

Re: Consume REST API with 1 header

Ok thanks. I've sent the job to a colleague and they can run it ok so it's definietly something wrong with Studio on my machine. Will try reinstalling. Thanks for all your help. 

Four Stars

Re: Consume REST API with 1 header

This issue was solved by overwriting both jersey-client-1.4-6.0.0.jar and jersey-client-1.4-6.0.0.jar with the version from a colleague's PC.

Thirteen Stars

Re: Consume REST API with 1 header

That's weird. I guess they got corrupted somehow. Did you try to replace them prior to having the issue?

Rilhia Solutions