NullPointerException when using TconnectionFactory

New to Tamino. Not able to figure out. I am using the following java code.
i am making use of SUN One webserver(IPlanet) and Tamino 4.1.4.1

<%@ page import=“com.softwareag.tamino.db.API.accessor.TXMLObjectAccessor,
com.softwareag.tamino.db.API.accessor.TQuery,
com.softwareag.tamino.db.API.accessor.TQueryException,
com.softwareag.tamino.db.API.accessor.TXQuery,
com.softwareag.tamino.db.API.accessor.TXQueryException,
com.softwareag.tamino.db.API.accessor.TAccessorException,
com.softwareag.tamino.db.API.accessor.TSystemAccessor,
com.softwareag.tamino.db.API.accessor.TInsertException,
com.softwareag.tamino.db.API.accessor.TDeleteException,
com.softwareag.tamino.db.API.accessor.TAccessLocation,
com.softwareag.tamino.db.API.common.,
com.softwareag.tamino.db.API.connection.
,
com.softwareag.tamino.db.API.objectModel.,
com.softwareag.tamino.db.API.objectModel.jdom.
,
com.softwareag.tamino.db.API.response.,
java.io.
,
java.util.,
java.text.
,
org.w3c.dom.,
org.xml.sax.InputSource,
java.net.
,
javax.servlet.http.HttpServletRequest,
javax.xml.parsers.,
javax.xml.transform.
,
javax.xml.transform.stream.*”
%>
<%@ page import=“com.montana.util.LogManager” %>

<%
response.setHeader(“Pragma”, “no-cache”);
response.setHeader(“Cache-Control”, “no-store, no-cache”);
response.setDateHeader(“Expires”, 0);
%>

<%
String subject= “3D”;
//subject= request.getParameter(subject);
String DocRoot = “M1ADCNOKIA1/RDF/nokiaitem”;
String logModule = “Module”;
String xmlString = “Empty String”;
//String XSLFOLDER = (String)prop.get(“XSLFOLDER”);
String DATABASE_URI = “http://srcrsvr1/tamino/stgdb1”;
String COLLECTION = “collection1”;
String USER_ID = “user1”;
String PASSWORD = “user1”;

TConnection connection = null;
LogManager.setErrorLogFile( “/logs/taminotest.log”);
try {
LogManager.logError(“Connecting tamino…”);

// OBTAIN THE CONNECTION FACTORY
TConnectionFactory connectionFactory = TConnectionFactory.getInstance();
LogManager.logError(“1 Connecting tamino…”);
// connection = TConnectionFactory.getInstance().newConnection (DATABASE_URI);
connection = connectionFactory.newConnection( DATABASE_URI, USER_ID, PASSWORD );
// OBTAIN A TXMLObjectAccessor WITH A JDOM OBJECT MODEL
LogManager.logError(“2 Connecting tamino…”);
TXMLObjectAccessor accessor = connection.newXMLObjectAccessor( TAccessLocation.newInstance( COLLECTION ) ,TJDOMObjectModel.getInstance() );
LogManager.logError(“3 Connecting tamino…”);
StringBuffer sb = new StringBuffer();
String WhereCond=“where $b/subject='”+subject+“'”;
sb.append(“for $b in (input()/”);
sb.append(DocRoot);
sb.append(WhereCond);
sb.append(" ) return $b");

LogManager.logError(sb.toString());
TXQuery xquery = TXQuery.newInstance(sb.toString());

// PERFORM XQuery
TResponse tresponse = accessor.xquery( xquery );


// PROMPT ERROR IF RECORD NOT FOUND
if (tresponse.getFirstXMLObject()==null) {
LogManager.logError(logModule+“: Tamino: Can’t get xml data”);
return;
}
// GET XML DATA
TXMLObject xmlObject = tresponse.getFirstXMLObject();
StringWriter stringWriter = new StringWriter();
xmlObject.writeTo( stringWriter );

// Original XML file, need to be transformed into mobile phone format
xmlString = stringWriter.toString();
}
// Obtain an access failure message with the exact reason if Tamino request failed.
catch (TAccessorException accessorException) {
TAccessFailureMessage accessFailure = accessorException.getAccessFailureMessage();
if ( accessFailure != null ){
//Log.message(Log.kError, logModule+“: Tamino: " +accessFailure);
}else{
//Log.message(Log.kError, logModule+”: Tamino Access failed:: " +accessorException.getMessage());
//Log.message(Log.kError, logModule+": " +accessorException);
}

} finally {
// CLOSE THE CONNECTION
connection.close();
}

// PREPARE XQuery
%>

Thanks,

Mahesh

Hello Mahesh,

could you please post the stack trace for the error as well?

It might also be helpful if you could post the contents of the log file from “Connecting tamino…” to the error.

Thanks in advance,
Trevor.

The error keeps changing, I encountered the following error

[19/Oct/2004:12:55:53] failure (10020): Internal error: Unexpected error conditi
on thrown (unknown exception,no description), stack: java.lang.NoClassDefFoundEr
ror: org/apache/log4j/Layout
at com.softwareag.common.instrumentation.logging.LoggerFactory.getLogger
(Unknown Source)
at com.softwareag.common.instrumentation.contract.Contract.(Unkn
own Source)
at com.softwareag.common.instrumentation.contract.Precondition.isEnabled
(Unknown Source)
at com.softwareag.tamino.db.API.objectModel.TXMLObjectFactory.(U
nknown Source)
at com.softwareag.tamino.db.API.objectModel.TXMLObject.(Unknown
Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:115)
at com.softwareag.tamino.db.API.objectModel.dom.TDOMObjectModel.class$(U
nknown Source)
at com.softwareag.tamino.db.API.objectModel.dom.TDOMObjectModel.(U
nknown Source)
at com.softwareag.tamino.db.API.objectModel.dom.TDOMObjectModel.getInsta
nce(Unknown Source)
________________________________________________

BASED on the above i included the log4j jar file, after that i have the following error in the Iplanet logs.



[19/Oct/2004:13:44:41] failure (13214): Internal error: Unexpected error condition thrown (unknown
exception,no description), stack: java.lang.NoClassDefFoundError
at com.softwareag.tamino.db.API.invocation.http.THTTPInvocation.verifyAuthorizationResult(
Unknown Source)
at com.softwareag.tamino.db.API.invocation.http.THTTPInvocation.doGetInvoke(Unknown Source
)
at com.softwareag.tamino.db.API.invocation.http.THTTPInvocation.doInvoke(Unknown Source)
at com.softwareag.tamino.db.API.invocation.TAbstractInvocation.doTemplateInvoke(Unknown So
urce)
at com.softwareag.tamino.db.API.invocation.TAbstractInvocation.invoke(Unknown Source)
at com.softwareag.tamino.db.API.invocation.TAbstractInvocation.checkServerAvailabilityAndV
ersion(Unknown Source)
at com.softwareag.tamino.db.API.invocation.TInvocationFactory.initialize(Unknown Source)
at com.softwareag.tamino.db.API.invocation.TInvocationFactory.newInvocation(Unknown Source
)
at com.softwareag.tamino.db.API.connection.TConnectionFactory.newConnection(Unknown Source
)
at _jsps._ZPlayground._ttest_jsp._jspService(_ttest_jsp.java:170)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.ja
va:897)
at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:464)


Thanks

I managed to remove the NullPoinetrException by including the Log4j. The problem that i am facing now is with the following code. There is no error in the logs. But there is no outpput after ‘TReponse’ is invoked. I am not able to figure out. Please help.

String xmlString=“Empty”;
TXQuery xquery = TXQuery.newInstance(“/docroot/myitem”);
LogManager.logError("0 IN XML: "+xmlString);
// PERFORM XQuery
TResponse tresponse = accessor.xquery( xquery );
out.println(“1”+xmlString);
LogManager.logError("1 IN XML: "+xmlString);
out.println(“2”+xmlString);

Hello Mahesh,

this one is a little bit easier to explain: the query you are trying to execute is not a valid XQuery expression that Tamino will accept.

To give some background on this, versions of Tamino predating the XQuery specification used a query language that augmented XPath. In Tamino the langauge was called “X-Query”, and added some things like sorting and full-text searching.

Tamino’s primary query language since version 4.1 has been XQuery (W3C XML Query), although the older X-Query language is in there too.

As there are two query languages, there are two classes for encapsulating queries in the Java API: TQuery and TXQuery.
The expression that you are trying to execute will probably work if you use the TQuery class instead of TXQuery.
An alternative would be to change the query into an XQuery expression:

   for $item in input()/docroot/myitem
   return $item


Without seeing the schema/data I can’t guarantee that this will work, but hopefully it will guide you in the right direction. You can test queries (both X-Query and XQuery) using the Tamino Interactive Interface tool.

I hope that helps,
Trevor.