-----Original Message-----Jim,
From: John Gentilin [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 27, 2001 6:12 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: FW: NullPointerException when using Xalan SQL extensions in aservletI have good news and bad news. I will assume that you are using D13 or less because it
is failing miserably with D14. D13 has a problem when using the internal connection pool
when calling init. The problem is in XConnection#init, the variable m_connectionPool is only
set if a default connection pool is actually created. We could patch D13 but it is probably not
worth it. The workaround for D13 is to incorporate the ConnectionPool example in you code
since the Connect method does not call init(). It should actual help your performance too.Here are the code changes, Hope this helps
Regards
JohnG<----------------------- Servlet Code ---------------------------------->
import org.apache.xalan.lib.sql.ConnectionPoolManager;
import org.apache.xalan.lib.sql.DefaultConnectionPool;
public class DBBrowse extends HttpServlet
{
ConnectionPoolManager m_cpoolMgr = null;
DefaultConnectionPool m_cpool = null;public void init(ServletConfig config) throws ServletException
{
super.init(config);
// Create a connection to the database server
// Up the connection pool count for testing
m_cpool = new DefaultConnectionPool();
m_cpool.setDriver("com.lutris.instantdb.jdbc.idbDriver");
m_cpool.setURL("jdbc:idb:c:/TEMP/instantdb/sample.prp");
//cp.setUser("sa");
//cp.setPassword("");
m_cpool.setMinConnections(1);
m_cpool.setPoolEnabled(true);// Now let's register our connection pool so we can use
// in a stylesheet
m_cpoolMgr = new ConnectionPoolManager();
m_cpoolMgr.registerPool("extpool", m_cpool);}
<-------------- XSL Code Chamges -------------------------->
<xsl:variable name="db" select="sql:new()"/>
<!-- Connect to the database with minimal error detection -->
<!--xsl:if test="not(sql:connect($db, $driver, $datasource))" -->
<xsl:if test="not(sql:connect($db, 'extpool'))">
<xsl:message>Error Connecting to the Database</xsl:message>
<xsl:copy-of select="sql:getError($db)/ext-error"/>
</xsl:if>
Jim Bugwadia wrote:
John,This is on Windows NT. I am using a relational database called TimesTenwhich has JDBC/ODBC interfaces.We are using Xalan for various other stylesheets in the same environment (including extensions for nodesets and re-direction), and have not experienced problems.Please let me know if there is any way I can assist your investigation.Regards,Jim-------Original Message-----Jim,
From: John Gentilin [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 26, 2001 9:33 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: FW: NullPointerException when using Xalan SQL extensions in a servletI took a look at your code and all seems fine. I am using basically the same method
except I am caching transformers for speed and have not had a problem. Is this on
Windows or Unix ?. I have heard of problems using the ODBC bridge code under
Windows but have not been able to replicate it. Also have you tried to use a stylesheet
that does not use any of the SQL code in your environment ?? I need to get something out
the door this week, but should be able to dive in and take a look by the end of the week.Regards
JohnGPS, can you try the same code using the InstantDB as an example. I will use InstantDB
as the test platform.
Jim Bugwadia wrote:
Hello,I've been trying to use Xalan's SQL extensions from a servlet. I'm
able to run everything successfully only once - immediately after
starting Tomcat, the servlet container.On any attempt to re-invoke the servlet I get an NullPointerException
exception. This happens either on doing a "refresh" or even after re-
starting the webapp. The exception is reported on the "transform"
method call.Here is the servlet code:
public class DBBrowse extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();try
{
TransformerFactory tFactory = TransformerFactory.newInstance();// Get the XML input document and the stylesheet.
Source xmlSource = new StreamSource(
new
URL("http://localhost:8080/dbbrowse/servlets/test.xml").openStream());Source xslSource = new StreamSource(
new
URL("http://localhost:8080/dbbrowse/servlets/test.xslt").openStream());// Generate the transformer.
Transformer transformer = tFactory.newTransformer(xslSource);// Perform the transformation, sending the output to the
response.
transformer.transform(xmlSource, new StreamResult(out));
}
catch (Exception e)
{
out.write(e.getMessage());
e.printStackTrace(out);
}out.close();
}
}And here is the stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:sql="org.apache.xalan.lib.sql.XConnection"
extension-element-prefixes="sql"><xsl:output method="html" indent="yes"/>
<xsl:param name="query" select="'SELECT * FROM SYS.TABLES'"/><xsl:template match="/">
<!-- 1. Make the connection -->
<xsl:variable name="products"
select="sql:new('com.timesten.jdbc.TimesTenDriver',
'jdbc:timesten:direct:JetCmeData')"/>
<HTML>
<HEAD>
</HEAD>
<BODY>
<TABLE border="1"><xsl:variable name="table" select='sql:query($products, $query)'/>
<TR>
<!-- Get column-label attribute from each column-header-->
<xsl:for-each select="$table/sql/metadata/column-header">
<TH><xsl:value-of select="@column-label"/></TH>
</xsl:for-each>
</TR><xsl:apply-templates select="$table/sql/row-set/row"/>
<xsl:text> </xsl:text></TABLE>
</BODY>
</HTML>
<!-- 3. Close the connection -->
<xsl:value-of select="sql:close($products)"/>
</xsl:template><xsl:template match="row">
<TR>
<xsl:apply-templates select="col"/>
</TR>
</xsl:template><xsl:template match="col">
<TD>
<!-- Here is the column data -->
<xsl:value-of select="text()"/>
</TD>
</xsl:template></xsl:stylesheet>
Any ideas on what could be the problem?
Btw, I can sucessfully invoke this styleheet multiple times from the
command line.Thanks,
Jim
PS: Here is the exception stack:
java.lang.NullPointerExceptionjavax.xml.transform.TransformerException:
java.lang.NullPointerException at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava:1226) at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
638) at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1088) at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1066) at DBBrowse.doGet(DBBrowse.java:45) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:247) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:243) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:201) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164
) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66) at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java:170) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170
) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64) at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:163) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at
org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:
1011) at
org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106
) at java.lang.Thread.run(Unknown Source) ---------
java.lang.NullPointerException at
org.apache.xpath.axes.FilterExprWalker.getAxis(FilterExprWalker.java:301) at
org.apache.xpath.axes.WalkingIteratorSorted.canBeWalkedInNaturalDocOrder(Wal
kingIteratorSorted.java:128) at
org.apache.xpath.axes.WalkingIteratorSorted.setRoot(WalkingIteratorSorted.ja
va:172) at
org.apache.xpath.axes.LocPathIterator.asIterator(LocPathIterator.java:267)
at
org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.ja
va:357) at
org.apache.xalan.templates.ElemForEach.execute(ElemForEach.java:287) at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2182) at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
678) at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2182) at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
678) at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2182) at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
678) at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2182) at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
678) at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2182) at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Transformer
Impl.java:2008) at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava:1171) at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
638) at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1088) at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1066) at DBBrowse.doGet(DBBrowse.java:45) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:247) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:243) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:201) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164
) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66) at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java:170) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170
) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64) at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
64) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:163) at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5
66) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at
org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:
1011) at
org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106
) at java.lang.Thread.run(Unknown Source)
--------------------------------------
John Gentilin
Eye Catching Solutions Inc.
18314 Carlwyn Drive
Castro Valley CA 94546Contact Info
[EMAIL PROTECTED]
Ca Office 1-510-881-4821
NJ Office 1-732-422-4917
John,
I
tried out the code changes, and they work great with D11!
Thanks
for all your help. Regards,
Jim
- RE: FW: NullPointerException when using Xalan SQL extensions ... Jim Bugwadia
- Jim Bugwadia
