avoid NPE is inputstream of a http request is empty
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/7da9d6f0 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/7da9d6f0 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/7da9d6f0 Branch: refs/heads/develop Commit: 7da9d6f0882d20c6e41b1481ae62560186c3d771 Parents: a0c37da Author: Romain Manni-Bucau <[email protected]> Authored: Fri Feb 6 10:02:55 2015 +0100 Committer: Romain Manni-Bucau <[email protected]> Committed: Fri Feb 6 10:02:55 2015 +0100 ---------------------------------------------------------------------- .../apache/openejb/server/httpd/HttpRequestImpl.java | 13 ++++++++++--- .../apache/openejb/server/httpd/OpenEJBHttpServer.java | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/7da9d6f0/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java ---------------------------------------------------------------------- diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java index d285109..4cd69ec 100644 --- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java +++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java @@ -405,10 +405,12 @@ public class HttpRequestImpl implements HttpRequest { * @param input the data input for this page * @throws java.io.IOException if an exception is thrown */ - protected void readMessage(InputStream input) throws IOException { + protected boolean readMessage(InputStream input) throws IOException { final DataInput di = new DataInputStream(input); - readRequestLine(di); + if (!readRequestLine(di)) { + return false; + } readHeaders(di); readBody(di); @@ -431,6 +433,7 @@ public class HttpRequestImpl implements HttpRequest { } } } + return true; } public void print(final Logger log, boolean formatXml) { @@ -460,7 +463,7 @@ public class HttpRequestImpl implements HttpRequest { * @param in the input to be read * @throws java.io.IOException if an exception is thrown */ - private void readRequestLine(DataInput in) throws IOException { + private boolean readRequestLine(DataInput in) throws IOException { String line; try { line = in.readLine(); @@ -471,12 +474,16 @@ public class HttpRequestImpl implements HttpRequest { + " : " + e.getMessage()); } + if (line == null) { + return false; + } StringTokenizer lineParts = new StringTokenizer(line, " "); /* [1] Parse the method */ parseMethod(lineParts); /* [2] Parse the URI */ parseURI(lineParts); + return true; } /** http://git-wip-us.apache.org/repos/asf/tomee/blob/7da9d6f0/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java ---------------------------------------------------------------------- diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java index 2e52627..33f358c 100644 --- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java +++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java @@ -230,7 +230,9 @@ public class OpenEJBHttpServer implements HttpServer { final HttpResponseImpl res = new HttpResponseImpl(); try { - req.readMessage(in); + if (!req.readMessage(in)) { + return res; + } if (print.size() > 0 && print.contains(Output.REQUEST)) { req.print(log, indent);
