1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.maps.eclipse;
14 import java.net.InetSocketAddress;
15 import java.net.Proxy;
17 import org.eclipse.core.net.proxy.IProxyData;
18 import org.eclipse.core.net.proxy.IProxyService;
19 import org.eclipse.core.runtime.Platform;
20 import org.osgi.framework.Bundle;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.ServiceReference;
23 import org.simantics.maps.IProxyUtil;
26 * @author Tuukka Lehtonen
28 public class EclipseProxyUtil implements IProxyUtil {
31 * @return IProxyService of the platform or <code>null</code> if the
32 * service is not available.
34 public Proxy getProxyService(final String url) {
35 Bundle b = Platform.getBundle("org.eclipse.core.net");
39 BundleContext bc = b.getBundleContext();
40 ServiceReference<IProxyService> ref = bc.getServiceReference(IProxyService.class);
44 IProxyService service = bc.getService(ref);
46 if (service != null && service.isProxiesEnabled()) {
47 IProxyData proxyData = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
48 if (proxyData != null && proxyData.getHost() != null) {
49 return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyData.getHost(), proxyData.getPort()));