Hello,
I am trying to run a servlet which uses BDB XML in two different
environments: MS Windows XP Professional and Ubuntu/Debian Linux, both
with BDB XML 2.1.8 installed (Windows: binaries from the Sleepycat
website, Linux: compiled) and using Tomcat 5.0.30 as the servlet
container. The Java Version is 1.4.2_09.
When I run the servlet on the Linux machine and try to call it, everything
works fine. But on Windows I get the following exception:
com.sleepycat.dbxml.XmlException: Uncaught exception from C++ API:
Unknown error, errcode = INTERNAL_ERROR at
com.sleepycat.dbxml.dbxml_javaJNI.XmlManager_query __SWIG_3(Native
Method)
at com.sleepycat.dbxml.XmlManager.query(XmlManager.ja va:478)
...
As I said, everything is the same except the operating system. The funny
thing is: when i convert the servlet to a standalone java program, it
works on both Windows and Linux! So I guess BDB XML has some problems with
the Windows version of Tomcat. Does anybody here know something about that
issue ?
Here is the code (the exception is caused by the line marked with >>>):
------------------------------------------------------------------------
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.sleepycat.dbxml.*;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
public class Servlet extends HttpServlet {
final static long serialVersionUID = 1;
private ServletContext context = null;
public void init() {
context = getServletConfig().getServletContext();
}
public synchronized void doPost(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
Environment myEnvironment = null;
XmlManager myManager = null;
Object responseObj = null;
String command = null;
context.log("||| initializing servlet |||");
String dbLocation = context.getRealPath("/databases");
String dbEnvLocation = context.getRealPath("/dbenv");
String dataLocation = context.getRealPath("/data");
String adminStr = new String("");
String aclStr = new String("");
String line = new String();
String dbName = dbLocation + "/users.dbxml";
try {
File inputFile = new File(dataLocation + "/administrator.xml");
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
while ((line = reader.readLine()) != null) {
adminStr += line.trim();
}
reader.close();
inputFile = new File(dataLocation + "/defaultACL.xml");
reader = new BufferedReader(new FileReader(inputFile));
while ((line = reader.readLine()) != null) {
aclStr += line.trim();
}
reader.close();
EnvironmentConfig ec = new EnvironmentConfig();
File dbEnvLocationFile = new File(dbEnvLocation);
ec.setAllowCreate(true);
ec.setInitializeCache(true);
ec.setInitializeLocking(true);
ec.setInitializeLogging(true);
ec.setTransactional(true);
myEnvironment = new Environment(dbEnvLocationFile, ec);
context.setAttribute("databaseEnvironment", myEnvironment);
context.log("xml database environment successfully initialized");
XmlManagerConfig mc = new XmlManagerConfig();
mc.setAdoptEnvironment(true);
myManager = new XmlManager(myEnvironment, mc);
context.setAttribute("databaseManager", myManager);
context.log("xml database manager successfully initialized");
XmlTransaction txn = myManager.createTransaction();
XmlContainerConfig cc = new XmlContainerConfig();
cc.setAllowCreate(true);
cc.setTransactional(true);
XmlContainer myContainer = myManager.openContainer(txn, dbName, cc);
XmlIndexSpecification is = myContainer.getIndexSpecification(txn);
is.addIndex("", "createdBy", "node-metadata-equality-string");
is.addIndex("", "username", "unique-node-element-equality-string");
is.addIndex("", "email", "unique-node-element-equality-string");
XmlUpdateContext uc = myManager.createUpdateContext();
myContainer.setIndexSpecification(txn, is, uc);
context.setAttribute("userDatabase", dbName);
context.log("user database created");
XmlDocumentConfig dc = new XmlDocumentConfig();
dc.setGenerateName(true);
uc = myManager.createUpdateContext();
XmlDocument myDoc = myManager.createDocument();
XmlValue myDate = new XmlValue(XmlValue.DATE_TIME, "2005-10-10T10:10:10");
myDoc.setContent(adminStr);
myDoc.setMetaData("", "creationDate", myDate);
myDoc.setMetaData("", "createdBy", new XmlValue(XmlValue.STRING, ""));
myDoc.setMetaData("", "lastModifiedDate", myDate);
myDoc.setMetaData("", "lastModifiedBy", new XmlValue(XmlValue.STRING, ""));
myDoc.setMetaData("", "acl", new XmlValue(XmlValue.STRING, aclStr));
myContainer.putDocument(txn, myDoc, uc, dc);
context.log("administrator added to user database");
command = req.getHeader("command");
String authUsername = req.getHeader("authUsername");
String storedPassword = new String();
String query = "/user[username=\"admin\"]/password/text()";
String completeQuery = "collection('" + dbName + "')" + query;
XmlQueryContext qc = myManager.createQueryContext();
Quote:
XmlResults results = myManager.query(txn, completeQuery, qc);
if (results.hasNext()) {
|
storedPassword = results.next().asString();
}
txn.commit();
myContainer.close();
myManager.close();
responseObj = new String(storedPassword);
ObjectOutputStream oos = new ObjectOutputStream(resp.getOutputStream());
oos.writeObject(responseObj);
oos.flush();
oos.close();
} catch (Exception e) {
log( "an error occured: " + e.getMessage(), e);
}
}
public synchronized void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
}
------------------------------------------------------------------------
thanks,
Robert