Table of contents
No headings in the article.
we will write some code to use in any Jasper report report
first, create a procedure
create or replace PROCEDURE GET_REPORT (p_file_name VARCHAR2 ,p_file_type VARCHAR2 ,p_paramter_name VARCHAR2 ,p_paramter_value VARCHAR2 )
IS
v_blob BLOB;
v_file_name VARCHAR2 (25) := p_file_name||'.'||p_file_type;
v_vcContentDisposition VARCHAR2 (25) := 'inline';
v_hostname VARCHAR2(30) := 'localhost'; -- your hostname, eg: localhost
v_port NUMBER := '8081'; -- port for your JasperReports Server, eg: 8081
v_username VARCHAR2(50) := 'jasperadmin'; -- jasperreports server username
v_password VARCHAR2(50) := 'jasperadmin'; -- jaspereports server password
v_jasper_string VARCHAR2(30) := v_username || ';' || v_password;
v_login_url VARCHAR2(100) :=
'http://' || v_hostname || ':' || v_port || '/jasperserver/rest/login';
-- modify below URL before use!
-- you should modify the line below; change /Pretius/ to your own name
-- before you add a line try your URL in a web browser
v_report_url VARCHAR2(100) :=
'http://' || v_hostname || ':' || v_port || '/jasperserver/rest_v2/reports/reports/ALI/' || v_file_name;
BEGIN
-- log into jasper server
v_blob := apex_web_service.make_rest_request_b(
p_url => v_login_url,
p_http_method => 'GET',
p_parm_name => apex_util.string_to_table('j_username;j_password',';'),
p_parm_value => apex_util.string_to_table(v_jasper_string,';')
);
-- download file
v_blob := apex_web_service.make_rest_request_b(
p_url => v_report_url,
p_http_method => 'GET',
p_parm_name => apex_util.string_to_table(p_paramter_name,';'),
p_parm_value => apex_util.string_to_table(p_paramter_value,';')
);
--OWA_UTIL.mime_header ('application/pdf', FALSE); -- view your pdf file
OWA_UTIL.MIME_HEADER( 'application/octet', FALSE ); -- download your pdf file
HTP.p('Content-Length: ' || DBMS_LOB.GETLENGTH(v_blob));
HTP.p('Content-Disposition: ' || v_vcContentDisposition ||'; filename="' || v_file_name || '"');
OWA_UTIL.http_header_close;
WPG_DOCLOAD.DOWNLOAD_FILE(v_blob);
APEX_APPLICATION.STOP_APEX_ENGINE;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
second, Create 4 Application Item
third, call your procedures
-- assign value for Application Item
:APP_FILE_NAME := 'EMPLOYEE' ;
:APP_FILE_TYPE := 'RTF' ;
:APP_PARM_NAME := 'P_EMPNO;P_DEPTNO' ;
:APP_PARM_VALUE := :P1_EMPNO||';'||:P1_DEPTNO ;
-- call GET_REPORT procedure
GET_REPORT ( p_file_name => :APP_FILE_NAME ,
p_file_type => :APP_FILE_TYPE ,
p_paramter_name => :APP_PARM_NAME ,
p_paramter_value => :APP_PARM_VALUE ) ;
thanks