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: 8 months 3 weeks ago

Hello, These may come late but hope someone finds it helpful. 

I am assuming you are calling jasper report from some application which consumes data from a REST service which has a token based security. So you have to send login details to get the access TOKEN. 

I am suggesting from your application before calling the jasper report,  you should send your login details and obtain your access token and probably store it for all subsequent requests. Then pass the TOKEN as a normal parameter to jasper report, and then use inject the parameter in Request header when creating the Webservice Adapter. so that way the REST server can respond with corresponding data to populate your report as long as the Token is valid.

tdavincci - 1 month 3 weeks ago

3 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: 8 months 1 week 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: 8 months 3 weeks ago
0

Hello, These may come late but hope someone finds it helpful. 

I am assuming you are calling jasper report from some application which consumes data from a REST service which has a token based security. So you have to send login details to get the access TOKEN. 

I am suggesting from your application before calling the jasper report,  you should send your login details and obtain your access token and probably store it for all subsequent requests. Then pass the TOKEN as a normal parameter to jasper report, and then inject the parameter in Request header when creating the Webservice Adapter. so that way the REST server can respond with corresponding data to populate your report as long as the Token is valid.

Attachments: 
tdavincci's picture
Joined: Jul 9 2016 - 9:16pm
Last seen: 1 month 3 weeks ago
Feedback