Get parameter from HTTP response header?

0

Is it possible to read a parameter from a response header of a web request? 

I need to retrieve JSON data from a REST API that requires token based authentication. So before I pull the actual JSON data, I will need to retreive an authentication token with a separate REST call. Unfortunately, the response to this call delivers the token not in the body of message, but in the Authorization header. Is there any way retrieve this info from a Jasper report and store it as a parameter so that the second REST call can use it?

Or, alternatively, can JasperReports Server somehow make such a request and use it as an input control?

matthias.budde's picture
Joined: Jul 14 2020 - 4:28am
Last seen: 1 month 1 day ago

2 Answers:

0

I have a similar problem. The token you're talking about is called with a POST request I suppose? (Bearer token?)
The token should be in the body of the message.

My problem is to pass the token in a second call (GET) to retrieve the JSON. 

adrian_32's picture
Joined: Sep 2 2019 - 1:40am
Last seen: 2 weeks 4 days ago
0

Unfortunately, the bearer token is in the header, not the body in my case. I don't see a way to read it from there at the moment...

Once I have it, passing the token to retrieve the JSON is relatively straight forward: You create a parameter, let's call it "auth_token" and then you open the report's "Dataset and Query Dialog". There, you switch to the "Data Adapter" tab, in which you select the "Headers" tab. There, you create a parameter named "Authorization" and assign the auth_token parameter as value. If you assign a valid bearer token als value for the auth_token parameter, the GET request is properly authenticated. This part works perfectly for me. Hope that helps!

matthias.budde's picture
Joined: Jul 14 2020 - 4:28am
Last seen: 1 month 1 day ago
Feedback