From ad08e0a6ac5fecf4b251204996b99e83a20343fc Mon Sep 17 00:00:00 2001 From: Mike Duff Date: Tue, 16 Apr 2013 14:21:28 -0500 Subject: [PATCH] Issue #1786 - fix null pointer Change-Id: Ie7bf3aa9afe6a8dcd9d288afc0e6dc537fdf043d Former-commit-id: 770190208335332c6bb889145f2fde705fbb4ae8 [formerly 6f14dfd04a696c71e2b2c9d12b86549287e7f0de] Former-commit-id: 6b909c7902a40d8db7a935c8b5c4732bbc40f6f9 --- .../raytheon/uf/common/comm/HttpClient.java | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.comm/src/com/raytheon/uf/common/comm/HttpClient.java b/edexOsgi/com.raytheon.uf.common.comm/src/com/raytheon/uf/common/comm/HttpClient.java index 02d4cfd4c4..cbb6d2d44f 100644 --- a/edexOsgi/com.raytheon.uf.common.comm/src/com/raytheon/uf/common/comm/HttpClient.java +++ b/edexOsgi/com.raytheon.uf.common.comm/src/com/raytheon/uf/common/comm/HttpClient.java @@ -201,10 +201,18 @@ public class HttpClient { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - if (request.getFirstHeader("Content-Length") != null) { - logBytes( - Long.valueOf(request.getFirstHeader( - "Content-Length").getValue()), 0); + try { + if (request != null + && request.getFirstHeader("Content-Length") != null) { + logBytes( + Long.valueOf(request.getFirstHeader( + "Content-Length").getValue()), + 0); + } + } catch (Throwable t) { + statusHandler.handle(Priority.DEBUG, + "Error in httpClient request interceptor", + t); } } }); @@ -214,7 +222,18 @@ public class HttpClient { public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { - logBytes(0, response.getEntity().getContentLength()); + try { + if (response != null + && response.getEntity() != null) { + logBytes(0, response.getEntity() + .getContentLength()); + } + } catch (Throwable t) { + statusHandler + .handle(Priority.DEBUG, + "Error in httpsClient response interceptor", + t); + } } }); @@ -280,10 +299,16 @@ public class HttpClient { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - if (request.getFirstHeader("Content-Length") != null) { - logBytes( - Long.valueOf(request.getFirstHeader( - "Content-Length").getValue()), 0); + try { + if (request != null + && request.getFirstHeader("Content-Length") != null) { + logBytes( + Long.valueOf(request.getFirstHeader( + "Content-Length").getValue()), 0); + } + } catch (Throwable t) { + statusHandler.handle(Priority.DEBUG, + "Error in httpClient request interceptor", t); } } }); @@ -293,7 +318,14 @@ public class HttpClient { public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { - logBytes(0, response.getEntity().getContentLength()); + try { + if (response != null && response.getEntity() != null) { + logBytes(0, response.getEntity().getContentLength()); + } + } catch (Throwable t) { + statusHandler.handle(Priority.DEBUG, + "Error in httpClient response interceptor", t); + } } });