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?
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!