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?
3 Answers:
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!
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.
Attachment | Size |
---|---|
![]() | 65.46 KB |
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.