From 781ac5fd9f048c50a22d97e9cff2b68726404c92 Mon Sep 17 00:00:00 2001 From: Roberto E. Escobar Date: Mon, 22 Oct 2012 16:48:30 -0700 Subject: bug: Fix NPE when running HttpProcessor outside of OSGI --- .../osee/framework/core/util/HttpProcessor.java | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'plugins') diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HttpProcessor.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HttpProcessor.java index 3ba0ff61b56..65349632846 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HttpProcessor.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HttpProcessor.java @@ -84,25 +84,31 @@ public class HttpProcessor { if (!proxyBypass) { if (proxyService == null) { BundleContext context = Activator.getBundleContext(); - ServiceReference reference = context.getServiceReference(IProxyService.class.getName()); - proxyService = (IProxyService) context.getService(reference); - proxyService.addProxyChangeListener(new IProxyChangeListener() { - - @Override - public void proxyInfoChanged(IProxyChangeEvent event) { - proxiedData.clear(); - } - }); + if (context != null) { + ServiceReference reference = context.getServiceReference(IProxyService.class); + proxyService = context.getService(reference); + } + if (proxyService != null) { + proxyService.addProxyChangeListener(new IProxyChangeListener() { + + @Override + public void proxyInfoChanged(IProxyChangeEvent event) { + proxiedData.clear(); + } + }); + } } String key = String.format("%s_%s", uri.getScheme(), uri.getHost()); IProxyData[] datas = proxiedData.get(key); - if (datas == null) { + if (datas == null && proxyService != null) { datas = proxyService.select(uri); proxiedData.put(key, datas); } - for (IProxyData data : datas) { - config.setProxy(data.getHost(), data.getPort()); + if (datas != null) { + for (IProxyData data : datas) { + config.setProxy(data.getHost(), data.getPort()); + } } } OseeLog.logf(Activator.class, Level.INFO, "Http-Request: [%s] [%s]", requests++, uri.toASCIIString()); @@ -163,7 +169,7 @@ public class HttpProcessor { params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); method.setParams(params); int responseCode = executeMethod(url, method); - if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) { + if (responseCode == HttpURLConnection.HTTP_NOT_FOUND || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_OK) { isAlive = true; } } finally { -- cgit v1.2.3