| How to pass a connection to viewerServlet [message #362094] |
Tue, 29 April 2008 23:11  |
Eclipse User |
|
|
|
Originally posted by: arunpjohny.aol.com
Hi,
I'm using org.eclipse.birt.report.servlet.ViewerServlet to generate my
reports.
My problem is I've to pass a connection object to the BIRT Engine at
runtime.
I've written a extension point to set the connection object. But it
seems that the new connection is working, instead the birt report is
using the default connection object for fetching parameter values.
Here is my code.
web.xml
------
<servlet>
<servlet-name>ViewerServlet</servlet-name>
<servlet-class>org.eclipse.birt.report.servlet.ViewerServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewerServlet</servlet-name>
<url-pattern>/frameset</url-pattern>
</servlet-mapping>
Redirecting to /frameset
------------------------
private void doReport(ServletRequest request, ServletResponse response,
String reportName)throws ServletException, IOException {
Connection conn = DataSourceUtils.getConnection(dataSource);
String paramString = getParameterString(request);
try {
request.setAttribute("AppContextKey",
"org.eclipse.birt.report.data.oda.subjdbc.SubOdaJdbcDriver");
request.setAttribute("AppContextValue", conn);
request.getRequestDispatcher("/frameset?__report=" + reportName +
paramString).forward(request, response);
} finally {
try {
DataSourceUtils.doReleaseConnection(conn, dataSource);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
My extension
-----------
public class SpringOdaJdbcDriver extends OdaJdbcDriver {
private Connection passedInConnection;
public void setAppContext(Object context) throws OdaException {
HashMap ctx = (HashMap) context;
passedInConnection = (java.sql.Connection) ctx
.get("org.eclipse.birt.report.data.oda.subjdbc.SubOdaJdbcDriver ");
}
public IConnection getConnection(String connectionClassName)
throws OdaException {
if (passedInConnection != null) {
return new appContextDBConnection();
} else {
return new org.eclipse.birt.report.data.oda.jdbc.Connection();
}
}
private class appContextDBConnection extends
org.eclipse.birt.report.data.oda.jdbc.Connection {
public void open(Properties connProperties) throws OdaException {
super.jdbcConn = passedInConnection;
}
public void close() throws OdaException {
if (jdbcConn == null) {
return;
}
jdbcConn = null;
}
}
}
plugin.xml
----------
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension
id="org.eclipse.birt.report.data.springjdbc"
point=" org.eclipse.datatools.connectivity.oda.consumer.driverBridge ">
<bridge
driverType="org.eclipse.birt.report.data.oda.jdbc.OdaJdbcDriver "
bridgeId="org.eclipse.birt.report.data.springjdbc">
</bridge>
</extension>
<extension
point="org.eclipse.datatools.connectivity.oda.dataSource">
<dataSource
odaVersion="3.0"
driverClass="org.eclipse.birt.report.data.springjdbc.SpringOdaJdbcDriver "
defaultDisplayName="Spring Jdbc Driver Bridge"
setThreadContextClassLoader="false"
id="org.eclipse.birt.report.data.springjdbc"/>
</extension>
</plugin>
Can anyone tell me what is wrong in my configuration.
I'm using BIRT 2.3M6
Thank you
|
|
|
| Re: How to pass a connection to viewerServlet [message #362112 is a reply to message #362094] |
Wed, 30 April 2008 11:43  |
Eclipse User |
|
|
|
Originally posted by: jasonweathersby.alltel.net
Arun,
I just logged a bug for this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=229649
It appears the appcontext is not being pushed prior to getting parameter
information. Take a look at the last couple of comments on this page:
http://birtworld.blogspot.com/2005/10/birt-examples.html
for a modification you can make to the viewer code to get it working.
Also can you verify that your connection is working for a report that
contains no parameters?
Jason
Arun P Johny wrote:
> Hi,
>
> I'm using org.eclipse.birt.report.servlet.ViewerServlet to generate my
> reports.
>
> My problem is I've to pass a connection object to the BIRT Engine at
> runtime.
>
> I've written a extension point to set the connection object. But it
> seems that the new connection is working, instead the birt report is
> using the default connection object for fetching parameter values.
>
> Here is my code.
>
> web.xml
> ------
> <servlet>
> <servlet-name>ViewerServlet</servlet-name>
> <servlet-class>org.eclipse.birt.report.servlet.ViewerServlet </servlet-class>
>
> </servlet>
> <servlet-mapping>
> <servlet-name>ViewerServlet</servlet-name>
> <url-pattern>/frameset</url-pattern>
> </servlet-mapping>
>
> Redirecting to /frameset
> ------------------------
> private void doReport(ServletRequest request, ServletResponse response,
> String reportName)throws ServletException, IOException {
> Connection conn = DataSourceUtils.getConnection(dataSource);
> String paramString = getParameterString(request);
> try {
> request.setAttribute("AppContextKey",
> "org.eclipse.birt.report.data.oda.subjdbc.SubOdaJdbcDriver");
> request.setAttribute("AppContextValue", conn);
> request.getRequestDispatcher("/frameset?__report=" + reportName +
> paramString).forward(request, response);
> } finally {
> try {
> DataSourceUtils.doReleaseConnection(conn, dataSource);
> } catch (SQLException e) {
> e.printStackTrace();
> }
> }
> }
>
> My extension
> -----------
> public class SpringOdaJdbcDriver extends OdaJdbcDriver {
>
> private Connection passedInConnection;
>
> public void setAppContext(Object context) throws OdaException {
> HashMap ctx = (HashMap) context;
> passedInConnection = (java.sql.Connection) ctx
>
> .get("org.eclipse.birt.report.data.oda.subjdbc.SubOdaJdbcDriver ");
> }
>
> public IConnection getConnection(String connectionClassName)
> throws OdaException {
> if (passedInConnection != null) {
> return new appContextDBConnection();
> } else {
> return new org.eclipse.birt.report.data.oda.jdbc.Connection();
> }
> }
>
> private class appContextDBConnection extends
> org.eclipse.birt.report.data.oda.jdbc.Connection {
>
> public void open(Properties connProperties) throws OdaException {
> super.jdbcConn = passedInConnection;
> }
>
> public void close() throws OdaException {
> if (jdbcConn == null) {
> return;
> }
> jdbcConn = null;
> }
>
> }
> }
>
> plugin.xml
> ----------
> <?xml version="1.0" encoding="UTF-8"?>
> <?eclipse version="3.2"?>
> <plugin>
> <extension
> id="org.eclipse.birt.report.data.springjdbc"
>
> point=" org.eclipse.datatools.connectivity.oda.consumer.driverBridge ">
>
> <bridge
>
> driverType="org.eclipse.birt.report.data.oda.jdbc.OdaJdbcDriver "
> bridgeId="org.eclipse.birt.report.data.springjdbc">
> </bridge>
> </extension>
> <extension
> point="org.eclipse.datatools.connectivity.oda.dataSource">
> <dataSource
> odaVersion="3.0"
>
> driverClass="org.eclipse.birt.report.data.springjdbc.SpringOdaJdbcDriver "
> defaultDisplayName="Spring Jdbc Driver Bridge"
> setThreadContextClassLoader="false"
> id="org.eclipse.birt.report.data.springjdbc"/>
> </extension>
>
> </plugin>
>
> Can anyone tell me what is wrong in my configuration.
> I'm using BIRT 2.3M6
>
>
> Thank you
|
|
|
Powered by
FUDForum. Page generated in 0.03104 seconds