Defect report on Java HTTP Client VIM

3 views
Skip to first unread message

Mike A

unread,
Feb 3, 2010, 8:28:40 PM2/3/10
to XAM Developers Group
The Java HTTP Client VIM has a defect which breaks the XUID iterator.
To be more precise, the code path reading data from an XStream
(synchronous or asynchronous) fails when byte values are 128 or
larger. The values are interpreted as being negative. The javadoc for
the InputStream doesn't match the behavior I'm seeing. The following
fix uses a different code path which avoids the problem.

The following code would fail during the first iteration:

System.out.println("XUID result set found = " + inCount);
XStream results = null;
try
{
results = sXSet.openXStream(XSet.XAM_JOB_QUERY_RESULTS,
XSet.MODE_READ_ONLY);
System.out.println("Open Query Results XStream");
}
catch (FieldDoesNotExistException e)
{
System.out.println("\nQuery Results XStream Unavailable");
return;
}
System.out.println("\n --------------- <Start XUID
List>------------------");
List<XUID> xuids = new ArrayList<XUID>();
XUIDIterator iterator = new XUIDIterator(results);
int i = 1;

while( iterator.hasNext() )
{
XUID xuid = (XUID) iterator.next();
xuids.add(xuid);
System.out.println("[" + i++ + "]" + "xuid = [" + xuid +
"]");
}
System.out.println("---------------- <End XUID
List>---------------------- \n");
results.close();

Apply this patch to the specified file in the HTTP Protocol VIM
source.

This fixes the XUIDIterator, as well as reading synchronously from
XStreams.

==================================================================================================
--- src/org/snia/xam/vim/http/client/HTTPRequest.java (revision 499)
+++ src/org/snia/xam/vim/http/client/HTTPRequest.java (working copy)
@@ -87,6 +87,9 @@
{
static final boolean debug = false;

+ /** Max number of bytes attempting to read when getting data from
something like a stream read, etc. */
+ static int READ_BUFFER_SIZE = 65535;
+
/**
* Send a simple request with one argument and value.
* @param host The host with the remote HTTP VIM Server
@@ -514,15 +517,21 @@
{
URL remote = new URL(composedURL);
InputStream strm = remote.openStream();
- byte b ;
int count = 0;
- int index = offset;
- while( (b = (byte) strm.read()) > 0 )
+
+ byte tmpBuffer[] = new byte[READ_BUFFER_SIZE];
+ int totalRead = 0;
+ while( count >= 0 )
{
- buffer[index++] = b;
- count++;
+ count = strm.read(tmpBuffer);
+ if( count >= 0 )
+ {
+ System.arraycopy(tmpBuffer, 0, buffer, offset,
count );
+ offset = offset + count;
+ totalRead += count;
+ }
}
- return count;
+ return totalRead;
}
catch (Throwable t)
{


==================================================================================================

Reply all
Reply to author
Forward
0 new messages