NullPointerException in SOAPHttpConnector

28 views
Skip to first unread message

phil.owen

unread,
Dec 11, 2007, 5:47:53 AM12/11/07
to Hermes 2.0 Discussion List
Hi,

I am connecting Hermes2 to a supplier's system and am getting a
NullPointerException in the log when sending the message. The root
cause is that the remote server is returning a 404 with no content at
all. I am taking that up with them but thought I'd post here about the
issue being masked.

The bottom of the stack trace is as follows:
Caused by: java.lang.NullPointerException
at
hk.hku.cecid.piazza.commons.io.IOHandler.readBytes(IOHandler.java:97)
at
hk.hku.cecid.piazza.commons.soap.SOAPHttpConnector.send(SOAPHttpConnector.java:
98)

The "problem" lies in SOAPHttpConnector.send() around the section:

try {
connection.setDoOutput(true);
outstream = connection.getOutputStream();
IOHandler.writeBytes(soapBytes, outstream);
connection.connect();
instream = connection.getInputStream();
}
catch (Exception e) {
if (connection.getResponseCode() >= 400) {
instream = connection.getErrorStream();
}
else throw e;
}

MimeHeaders responseHeaders = headers.getMimeHeaders();
MessageFactory msgFactory = MessageFactory.newInstance();
byte[] responseBytes = IOHandler.readBytes(instream);

connection.getInputStream() is throwing a FileNotFoundException, so
the catch block is being entered, getResponseCode() returns 404 so the
instream is being set to connection.getErrorStream(). However, that is
null which looking at the API is valid if there is no content to speak
of. Further down, IOHandler.readBytes() gets invoked with null as the
parameter which it really doesn't like, hence the
NullPointerException.

Unfortunately, as the code stands, the FileNotFoundException gets lost
without being logged. It was only by attaching a debugger that I found
out what was causing the NPE. I'm new to Hermes2 so I don't know how
valid a suggestion this is, but I would have thought that logging or
re-throwing the FileNotFoundException would be helpful for users if
connection.getErrorStream() returns null.

Any thoughts anyone?

hoc...@gmail.com

unread,
Dec 13, 2007, 10:17:48 PM12/13/07
to Hermes 2.0 Discussion List
Hi Phil,

I agree with you. If the error stream is null, it should keep throwing
the original exception.
So when where is connection failure, it should be able to tell the
exception causing the problem,
like FileNotFoundException or IOException, instead of
NullPointException currently.
Hopefully this change will be included in next release.

Thank you for your comment!

Philip
Reply all
Reply to author
Forward
0 new messages