Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Use url to access report
loume
Hi,
I want to try use url and add parameter in url to access birt report that report will get this parameters and will not show report parameter control panel and run report, is any way can do this?
thx
Find more posts tagged with
Comments
cjmaloof
You can do it with a servlet; this is how I have things set up. I can't totally vouch for the following code, since I'm not actually using it at the moment, but I'm pretty sure it used to work. (It sets the report engine to read request parameters, and outputs an HTML version of the report to the response.)<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
public class DisplayReportServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@SuppressWarnings("
;unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
//BirtEngine.initBirtConfig();
try {
// Create the engine
ServletContext context = request.getSession().getServletContext();
IReportEngine engine = BirtEngine.getBirtEngine(context);
//Open report design
IReportRunnable design = engine.openReportDesign(context.getRealPath("/myreport.rptdesign"));
//create task to run and render report
IRunAndRenderTask task = engine.createRunAndRenderTask( design );
String firstDate = request.getParameter("firstDate");
String lastDate = request.getParameter("lastDate");
task.setParameterValue("first_date", java.sql.Date.valueOf(firstDate));
task.setParameterValue("last_date", java.sql.Date.valueOf(lastDate));
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
options.setOutputStream(response.getOutputStream());
//options.setOption(IRenderOption.CLOSE_OUTPUTSTREAM_ON_EXIT, Boolean.FALSE);
//setup image directory
options.setImageHandler(new HTMLServerImageHandler());
options.setBaseImageURL(request.getContextPath()+"/images");
options.setImageDirectory(context.getRealPath("/images"));
String browser = request.getHeader("User-Agent");
if (browser.contains("Firefox")) {
options.setSupportedImageFormats("SVG");
}
task.setRenderOption(options);
task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, DisplayReportServlet.class.getClassLoader());
task.run();
task.close();
} catch (Exception e){
e.printStackTrace();
throw new ServletException( e );
}
}
}
</pre>
<br />
I believe I got much of the engine setup code from <a class='bbc_url' href='
http://opensource.sys-con.com/node/336872/print'>this
page</a>. (Careful, the non-printing version of the page has noisy ads.)
cjmaloof
Also, if you don't want your report to be the only thing on the page, you can do something like:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
// Set output to embeddable HTML
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
options.setEmbeddable(true);
if (config.isPrintableHTML()) {
options.setHtmlPagination(true);
}
// Send output to a string
ByteArrayOutputStream stringOutput = new ByteArrayOutputStream();
options.setOutputStream(stringOutput);
<snip similar configuration and task running as above>
String reportHTML = stringOutput.toString();
stringOutput.close();
</pre>
<br />
This gives you a reportHTML string which the server can insert into a larger page before sending the page to the client browser.
loume
Hi cjmaloof,
How to use this code with servlet?
I make to jar and put file in $TOMCAT/webapps/birt/WEB-INF/lib folder, than run report but it's still no show any words.
Could you teach me how to deploy this servlet?
thx
cjmaloof
I don't think I can help you with this one... it's a little too vague and I'm really not a servlet expert anyway.<br />
<br />
I did realize that I forgot to put in the getBirtEngine code.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
private static IReportEngine birtEngine = null;
public static synchronized IReportEngine getBirtEngine(ServletContext sc)
throws IOException {
if (birtEngine == null) {
EngineConfig config = new EngineConfig();
config.setEngineHome("");
IPlatformContext context = new PlatformServletContext( sc );
config.setPlatformContext( context );
config.setResourcePath(sc.getRealPath("directory_with_report_files"));
try {
Platform.startup( config );
} catch ( BirtException e) {
e.printStackTrace( );
}
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
birtEngine = factory.createReportEngine( config );
}
return birtEngine;
}</pre>
loume
Hi, I think it could when I run BIRT report use URL this BIRT Runtime havd not got access session, so the BIRT report can't display anything.
Is there have any way to get access session by myself?
thx
loume
Hi, I got the way to use.
If BIRT report parameter all set not require and all report parameter value set in URL, and run the report will access success.
thx