[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xindice-dev
Subject:    some patches for large files support in xindice
From:       "David Viner" <dviner () yahoo-inc ! com>
Date:       2002-04-29 17:53:32
[Download RAW message or body]

hi all,
	here are a series of 3 patches to the core xindice engine that should help
fix some bugs.  mostly they deal with sending large files and occasional
nullpointerexception's.
i can't take credit for these discoveries, but David Ku can. (he's not yet
on xindice-dev, and asked me to forward them.)


thanks
dave viner



Change #1:
	File: org.apache.xindice.server.standard.StdFileManager
	Location: inside StdFileManager.setConfig(Configuration cfg)
	Problem: sending large HTTP messages to Xindice results in
NullPointerException
	Fix: need to check the existence of the "tempDir", create directory if
needed

	   public void setConfig(Configuration config) {
	      this.config = config;
	      minBytes = config.getIntAttribute(MINBYTES);
	      maxBytes = config.getIntAttribute(MAXBYTES);
	      chunkSize = config.getIntAttribute(CHUNKSIZE);
	      tempDir = new File(config.getAttribute(TMPDIR));

		// ADD BEGIN
	      tempDir.mkdirs();
		// ADD END
  	   }

	Reason: inside the HTTPServer, when accepting input stream from the
HTTPGateway, it checks whether the message size exceeds certain chunkSize
(currently 32K bytes).  If it exceeds, it uses a temporary file resource
from the FileManager.  Since the tempDir does not exist inside the
StdFileManager, it is unable to create the temporary file, and the
getOutputStream() returns null, thus the NullPointerException.

Change #2:
	File: org.apache.xindice.core.objects.Reflector
	Location: inside invoke(Reflectable,String,Variant[])
	Problem: invoking XMLObjects results in NullPointerException
	Fix: check for Variant.getObject() != null rather than rely on toString()

	   public Object invoke(Reflectable obj, String name, Variant[] args)
throws XMLObjectException {
      	MethodInfo info = (MethodInfo)methods.get(name);

      	if ( info != null ) {

         		Object[] params = new Object[info.params.length];
         		for ( int i = 0; i < info.params.length; i++ ) {
            	ParamInfo p = info.params[i];

            //************************************************
            // Added the check for getObject() != null because
            // the Variant implementation does NOT check for
            // value = null, which means it crashes with
            // NullPointerException
            //************************************************

	            if ( args[i] == null || args[i].getObject() == null )
      	         args[i] = new Variant(p.defValue);
		...

	Reason: within the remainder of the routine, it directly makes references
to the value of args[i] as if it is not null.  For example,
args[i].getString() or args[i].getInt().  However, if you look at the
Variant class, there is no checking for null pointer, and therefore result
in NullPointerException if the getObject() is null.  Putting this check
simply avoids the problem completely.  A safer solution would be to make
Variant safer by checking for null pointer content, or provide a routine
such as "isValid()" to ensure the caller satisfies its assumptions.

Change/Question #3:
	File: org.apache.xindice.tools.command.Commnad
	Location: inside normalizeXindiceURI(String)
	Problem (?): don't understand the reason why it uses "uri.substring(1)"
rather than the entire "uri" when composing the resulting URI.  I changed it
to use the entire URI and it still seems to work.  The problem occurs
whenever it calls with URI "///db/collection" (which is valid Xindice except
without the protocol), then it will actually return
"xindice://db/collection" instead of "xindice:///db/collection", resulting
in "db" being interpreted as the hostname rather than the collection name.

	   public String normalizeXindiceURI(String uri) throws XindiceException {

      	// Check to see if this uri starts with "xmldb:" , if so treat as
absolute
      	if ( uri.startsWith("xindice:") ) {
         		// URI is absolute, leave alone
         		return uri;
      	}
      	else {
         		return ( XINDICEURI + uri );
		}
	   }

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic