fc-reporting Posted March 20, 2018 Share Posted March 20, 2018 Our JavaScript code uses Visualize.js to run, render and/or export reports. Internally Visualize.js sends requests to JasperReports to run these reports, check status, download CSS, JS and IMG files among other things. We would like to send a custom request header on each of these calls. Visualize.js documentation seem to suggest there is an option to send http "headers" on the 'auth' properties. Is this possible, are there some examples?thanks Link to comment Share on other sites More sharing options...
swood_1 Posted April 2, 2018 Share Posted April 2, 2018 What sort of header do you want to add and why?You can add headers into the loginFn of the authentication. Visualize does this itself for username/password authentication. Note the headers: in the request. var JrsAuthenticationExecutor = { login: function(properties, request){ var dfd = $.Deferred(); request({ url: properties.url + (properties.preAuth ? "" : "/j_spring_security_check") + "?" + getParametersString(properties), headers: { "Accept":"application/json" } }).done(function (response, a, b) { var result = response; if(typeof response === "string"){ try { result = JSON.parse(response); }catch (error){ dfd.reject(error); } } if(result.success === true){ dfd.resolve(result); } else { dfd.reject(b); } }).fail(function (xhr) { dfd.reject(xhr); }); return dfd; }, logout: function(properties, request){ return request({ url: properties.url + "/logout.html" }); } };[/code] This is only for the initial authentication request to the JasperReports Server, which establishes the user session on JRS.Do you need to add the headers for every request? Sherman Link to comment Share on other sites More sharing options...
kenildomadia Posted November 21, 2018 Share Posted November 21, 2018 Hello there, Even I'm looking for similar solution to add HTTP header for request sent via visualise.js library API to jaspersoft server. The solution mentioned in th answer section, only adds HTTP header for login request. I want to add it for custom validation purpose. So, all request sent to jasper server are validated via "auth_token' HTTP header by our custom validator. Requests with appropriate access right, reach jasper server and all other requests are rejected by our custom validator. Link to comment Share on other sites More sharing options...
swood_1 Posted January 2, 2019 Share Posted January 2, 2019 In order to set the headers on every visualize request, you can hook into the underlying xhr machinery like this:visualize(function(visualizeClient) { __visualize__.require(["jquery"], function(jq) { jq.ajaxSetup({ beforeSend: function(xhr) { xhr.setRequestHeader("A-Header", "headerValue"); } }); visualizeClient.report({ server: "<?= $restUrl ?>",....[/code] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now