diff options
author | slewis | 2010-05-16 17:16:14 +0000 |
---|---|---|
committer | slewis | 2010-05-16 17:16:14 +0000 |
commit | b9a1553dd9deef3975f42350a25971f05d9c7d0e (patch) | |
tree | 59fd9523e77e958c037601589e901de083cd3bd9 | |
parent | 8727ef8499ad095b19cdd63fc99a711037d3e2cb (diff) | |
download | org.eclipse.ecf-b9a1553dd9deef3975f42350a25971f05d9c7d0e.tar.gz org.eclipse.ecf-b9a1553dd9deef3975f42350a25971f05d9c7d0e.tar.xz org.eclipse.ecf-b9a1553dd9deef3975f42350a25971f05d9c7d0e.zip |
Added logging for RestClientService exceptions
3 files changed, 59 insertions, 9 deletions
diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF index 8456e3a83..a4fde9aea 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF @@ -24,9 +24,11 @@ Import-Package: org.apache.commons.httpclient;version="3.0.1", org.eclipse.ecf.remoteservice.events, org.eclipse.ecf.remoteservice.util, org.eclipse.equinox.concurrent.future;version="1.0.0", - org.eclipse.osgi.util;version="1.1.0", - org.osgi.framework;version="1.5.0" + org.eclipse.osgi.util, + org.osgi.framework, + org.osgi.service.log, + org.osgi.util.tracker Require-Bundle: org.eclipse.equinox.common, - org.eclipse.ecf;bundle-version="3.1.0" + org.eclipse.ecf Service-Component: META-INF/dspresent.xml Bundle-Localization: plugin diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/internal/remoteservice/rest/Activator.java b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/internal/remoteservice/rest/Activator.java index 3fec58bc9..74dd34879 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/internal/remoteservice/rest/Activator.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/internal/remoteservice/rest/Activator.java @@ -9,8 +9,13 @@ *******************************************************************************/ package org.eclipse.ecf.internal.remoteservice.rest; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.ecf.core.util.LogHelper; +import org.eclipse.ecf.core.util.SystemLogService; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; +import org.osgi.util.tracker.ServiceTracker; /** * The activator class controls the plug-in life cycle @@ -25,6 +30,10 @@ public class Activator implements BundleActivator { private BundleContext context; + private ServiceTracker logServiceTracker = null; + + private LogService logService = null; + /* * (non-Javadoc) * @@ -43,9 +52,13 @@ public class Activator implements BundleActivator { * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context1) throws Exception { + if (logServiceTracker != null) { + logServiceTracker.close(); + logServiceTracker = null; + logService = null; + } plugin = null; this.context = null; - } /** @@ -64,4 +77,22 @@ public class Activator implements BundleActivator { return context; } + protected LogService getLogService() { + if (logServiceTracker == null) { + logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null); + logServiceTracker.open(); + } + logService = (LogService) logServiceTracker.getService(); + if (logService == null) + logService = new SystemLogService(PLUGIN_ID); + return logService; + } + + public void log(IStatus status) { + if (logService == null) + logService = getLogService(); + if (logService != null) + logService.log(LogHelper.getLogCode(status), LogHelper.getLogMessage(status), status.getException()); + } + } diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java index aac306af7..334a29013 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java @@ -18,8 +18,11 @@ import org.apache.commons.httpclient.methods.*; import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.util.EncodingUtil; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.ecf.core.security.*; import org.eclipse.ecf.core.util.ECFException; +import org.eclipse.ecf.internal.remoteservice.rest.Activator; import org.eclipse.ecf.remoteservice.IRemoteCall; import org.eclipse.ecf.remoteservice.IRemoteService; import org.eclipse.ecf.remoteservice.client.*; @@ -98,6 +101,7 @@ public class RestClientService extends AbstractClientService { } protected void handleException(String message, Throwable e, int responseCode) throws RestException { + logException(message, e); throw new RestException(message, e, responseCode); } @@ -164,8 +168,9 @@ public class RestClientService extends AbstractClientService { throw new RestException(NLS.bind("HTTP method {0} not supported", requestType)); //$NON-NLS-1$ } } catch (NotSerializableException e) { - // XXX log - throw new RestException("Could not serialize parameters for uri=" + uri + " call=" + call + " callable=" + callable); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String message = "Could not serialize parameters for uri=" + uri + " call=" + call + " callable=" + callable; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + logException(message, e); + throw new RestException(message); } // add additional request headers addRequestHeaders(httpMethod, call, callable); @@ -258,7 +263,7 @@ public class RestClientService extends AbstractClientService { } } catch (UnsupportedEncodingException e) { // should not happen - e.printStackTrace(); + logException("UnsupportedEncodingException for rest parameter", e); //$NON-NLS-1$ } } } @@ -283,12 +288,24 @@ public class RestClientService extends AbstractClientService { httpClient.getState().setCredentials(authscope, credentials); method.setDoAuthentication(true); } catch (IOException e) { - e.printStackTrace(); + logException("IOException setting credentials for rest httpclient", e); //$NON-NLS-1$ } catch (UnsupportedCallbackException e) { - e.printStackTrace(); + logException("UnsupportedCallbackException setting credentials for rest httpclient", e); //$NON-NLS-1$ } } } + protected void logException(String string, Throwable e) { + Activator a = Activator.getDefault(); + if (a != null) + a.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, string, e)); + } + + protected void logWarning(String string, Throwable e) { + Activator a = Activator.getDefault(); + if (a != null) + a.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, string)); + } + } |