/******************************************************************************* * Copyright (c) 2012 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.maps.eclipse; import java.net.InetSocketAddress; import java.net.Proxy; import org.eclipse.core.net.proxy.IProxyData; import org.eclipse.core.net.proxy.IProxyService; import org.eclipse.core.runtime.Platform; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.simantics.maps.IProxyUtil; /** * @author Tuukka Lehtonen */ public class EclipseProxyUtil implements IProxyUtil { /** * @return IProxyService of the platform or null if the * service is not available. */ public Proxy getProxyService(final String url) { Bundle b = Platform.getBundle("org.eclipse.core.net"); if (b == null) return null; BundleContext bc = b.getBundleContext(); ServiceReference ref = bc.getServiceReference(IProxyService.class); if (ref == null) return null; IProxyService service = bc.getService(ref); if (service != null && service.isProxiesEnabled()) { IProxyData proxyData = service.getProxyData(IProxyData.HTTP_PROXY_TYPE); if (proxyData != null && proxyData.getHost() != null) { return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyData.getHost(), proxyData.getPort())); } } return null; } }