How to pass custom arguments to a BIRT report via GET and POST

Birt reports can be invoked using both HTTP GET as well as HTTP POST. In dynamic reports, there may be a need to pass arguments to the report. These arguments can also be passed to the report easily over http.

Via HTTP GET
Using GET is simple and straightforward. Just append the arguments as you would to any other GET request, as a query string.

http://localhost:8080/birt/frameset?__report=test.rptdesign&mystring=Hello+World

Via HTTP POST
While GET provides a simple way to invoke the reports, the obvious pitfalls of GET request stand. This includes exposing the parameters, which could potentially be used to regenerate reports if the server is not well secured. There are other reasons why you would not want to use GET, like large payload size in arguments. In such cases, the requests can easily be sent via POST as well. If security is a concern, the entire payload could be encrypted or secured in any other standard way that you would secure your POST requests.

<HTML>
<BODY>
<SCRIPT>
function post(path, params, method) {
method = method || “post”;
var form = document.createElement(“form”);
form.setAttribute(“method”, method);
form.setAttribute(“action”, path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement(“input”);
hiddenField.setAttribute(“type”, “hidden”);
hiddenField.setAttribute(“name”, key);
hiddenField.setAttribute(“value”, params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
post(‘http://localhost:8080/birt/frameset?__report=test.rptdesign’, {sample: ‘Hello World});
</SCRIPT>
</BODY>
</HTML>

Leave a Reply

Your email address will not be published. Required fields are marked *