X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Feclipse%2FEclipseProxyUtil.java;fp=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Feclipse%2FEclipseProxyUtil.java;h=601a82f7942c3899e1484f2a11faccd336282146;hb=e9f74f09e0cedb603c0b4de9e542de8dd64a5ce3;hp=0000000000000000000000000000000000000000;hpb=16ee01dc5a40981c58fd5b478b89552e5814e8bb;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.maps/src/org/simantics/maps/eclipse/EclipseProxyUtil.java b/org.simantics.district.maps/src/org/simantics/maps/eclipse/EclipseProxyUtil.java new file mode 100644 index 00000000..601a82f7 --- /dev/null +++ b/org.simantics.district.maps/src/org/simantics/maps/eclipse/EclipseProxyUtil.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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; + } + +}