Add ProxyUtils and use in TRK package installer
authordadubrow
Wed, 12 Aug 2009 09:26:04 -0500
changeset 421 7bf2b8a16445
parent 420 be59a4bc0747
child 424 9f38f9ad4716
child 426 07ffe912a5b1
child 430 147ef5f224c4
Add ProxyUtils and use in TRK package installer
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/installpackages/InstallPackages.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java
core/com.nokia.cpp.utils.core/META-INF/MANIFEST.MF
core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/ProxyUtils.java
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/installpackages/InstallPackages.java	Wed Aug 12 08:49:37 2009 -0500
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/installpackages/InstallPackages.java	Wed Aug 12 09:26:04 2009 -0500
@@ -24,14 +24,12 @@
 import com.nokia.carbide.remoteconnections.Messages;
 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider;
-import com.nokia.cpp.internal.api.utils.core.Check;
-import com.nokia.cpp.internal.api.utils.core.FileUtils;
+import com.nokia.cpp.internal.api.utils.core.*;
 
 import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.eclipse.core.net.proxy.IProxyData;
-import org.eclipse.core.net.proxy.IProxyService;
 import org.eclipse.core.runtime.*;
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.URI;
@@ -174,13 +172,24 @@
     	
        return null;
 	}
+	
+	private static java.net.URI getURI(GetMethod getMethod) {
+		try {
+			return new java.net.URI(getMethod.getURI().toString());
+		} catch (Exception e) {
+			RemoteConnectionsActivator.logError(e);
+		}
+		
+		return null;
+	}
 
 	public static void setProxyData(HttpClient client, GetMethod getMethod) {
-		IProxyService proxyService = RemoteConnectionsActivator.getDefault().getProxyService();
-		boolean proxiesEnabled = proxyService.isProxiesEnabled();
-		if (!proxiesEnabled)
+		java.net.URI uri = getURI(getMethod);
+		if (uri == null)
 			return;
-		IProxyData proxyData = proxyService.getProxyData(IProxyData.HTTP_PROXY_TYPE);
+		IProxyData proxyData = ProxyUtils.getProxyData(uri);
+		if (proxyData == null)
+			return;
 		String host = proxyData.getHost();
 		int port = proxyData.getPort();
 		client.getHostConfiguration().setProxy(host, port);
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java	Wed Aug 12 08:49:37 2009 -0500
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java	Wed Aug 12 09:26:04 2009 -0500
@@ -52,6 +52,7 @@
  
  	/**
 	 * Returns IProxyService.
+	 * @deprecated
 	 */
 	public IProxyService getProxyService() {
 		return (IProxyService) proxyServiceTracker.getService();
--- a/core/com.nokia.cpp.utils.core/META-INF/MANIFEST.MF	Wed Aug 12 08:49:37 2009 -0500
+++ b/core/com.nokia.cpp.utils.core/META-INF/MANIFEST.MF	Wed Aug 12 09:26:04 2009 -0500
@@ -8,7 +8,8 @@
  org.eclipse.core.resources;visibility:=reexport,
  org.eclipse.core.filebuffers,
  org.eclipse.jface,
- org.eclipse.core.filesystem;bundle-version="1.2.0"
+ org.eclipse.core.filesystem;bundle-version="1.2.0",
+ org.eclipse.core.net;bundle-version="1.1.0"
 Bundle-ActivationPolicy: lazy
 Export-Package: com.nokia.cpp.internal.api.utils.core
 Bundle-ManifestVersion: 2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/ProxyUtils.java	Wed Aug 12 09:26:04 2009 -0500
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+
+package com.nokia.cpp.internal.api.utils.core;
+
+import com.nokia.cpp.utils.core.noexport.UtilsCorePlugin;
+
+import org.eclipse.core.net.proxy.IProxyData;
+import org.eclipse.core.net.proxy.IProxyService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import java.net.URI;
+
+public class ProxyUtils {
+
+	/**
+	 * Get a reference to the proxy service
+	 * @return IProxyService
+	 */
+	public static IProxyService getProxyService() {
+		BundleContext bc = UtilsCorePlugin.getDefault().getBundle().getBundleContext();
+		ServiceReference ref = bc.getServiceReference(IProxyService.class.getName());
+		if (ref != null)
+			return (IProxyService) bc.getService(ref);
+			
+		return null;
+	}
+	
+	
+	/**
+	 * Get proxy data for this URI. Takes into consideration native vs manual proxy setting
+	 * as well as hosts for which no proxy is required.
+	 * Returns null if no proxy data is set or needed for this URI.
+	 * @param uri URI
+	 * @return IProxyData
+	 */
+	public static IProxyData getProxyData(URI uri) {
+		IProxyService proxyService = getProxyService();
+		if (proxyService != null) {
+			IProxyData[] proxyData = proxyService.select(uri);
+			if (proxyData.length > 0)
+				return proxyData[0];
+		}
+		
+		return  null;
+	}
+}