*******************************************************************************/
package eu.etaxonomy.taxeditor.handler.update;
+import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
+import java.net.Proxy;
+import java.net.SocketAddress;
import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.p2.operations.UpdateOperation;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
-
+import org.eclipse.core.internal.net.ProxyData;
+import org.eclipse.core.internal.net.ProxyManager;
import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.net.proxy.IProxyService;
import eu.etaxonomy.taxeditor.l10n.Messages;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.workbench.Activator;
/**
* UpdateHandler invokes the check for updates UI
private UpdateOperation operation;
private ServiceTracker proxyTracker;
+ Proxy proxy;
@Execute
public void execute(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
System.setProperty("socks.proxySet", "true");
System.setProperty("socks.proxyHost", "127.0.0.1");
System.setProperty("socks.proxyPort", "8090");
-
- proxyTracker = new ServiceTracker(FrameworkUtil.getBundle(
- this.getClass()).getBundleContext(), IProxyService.class
- .getName(), null);
- proxyTracker.open();
-
+//
+
+ SocketAddress addr = new InetSocketAddress("127.0.0.1", 8090);
+ proxy = new Proxy(Proxy.Type.SOCKS, addr);
+//
+//// System.setProperty("socks.proxyPort", "8090");
+// proxyTracker = new ServiceTracker(FrameworkUtil.getBundle(
+// this.getClass()).getBundleContext(), IProxyService.class
+// .getName(), null);
+// proxyTracker.open();
+//
Job checkUpdateJob = new Job(Messages.UpdateHandler_CHECK_UPDATE_JOB) {
@Override
});
}
- private IStatus checkForUpdates(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
+ @SuppressWarnings("restriction")
+ private IStatus checkForUpdates(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
IProgressMonitor monitor) {
// configure update operation
configureUpdate(operation);
- IProxyService proxyService = (IProxyService) proxyTracker.getService();
+ ProxyManager proxyService = getProxyService();
URI uri = P2Util.getP2UpdateRepository();
+ proxyService.setSystemProxiesEnabled(false);
+ proxyService.setProxiesEnabled(true);
+ String[] nonProxiedHosts = new String[1];
+ nonProxiedHosts[0] = "130.133.70.27";
+ proxyService.setNonProxiedHosts(nonProxiedHosts);
+ ProxyData dta = (ProxyData) proxyService.getProxyData("SOCKS");
+ dta.setDynamic(true);
+ IProxyData[] proxies = new IProxyData[1];
+ proxies[0] = dta;
+
+ proxyService.setProxyData(proxies);
+ IProxyData[] data = proxyService.getNativeProxyData();
+
MessagingUtils.info("proxy data: " + proxyService.getProxyData("SOCKS").toString());
MessagingUtils.info("proxy data: " + proxyService.getProxyData("HTTP").toString());
MessagingUtils.info("proxy data: " + proxyService.getProxyData("HTTPS").toString());
boolean isEnabled = proxyService.isProxiesEnabled();
+ URL url;
+ try {
+ url = uri.toURL();
+ URLConnection conn = url.openConnection(proxy);
+ boolean sysProxies = proxyService.hasSystemProxies();
+ IProxyData[] proxyDataForHost = proxyService.select(uri);
+ for (IProxyData proxyData : proxyDataForHost) {
+ if (proxyData.getHost() != null) {
+ MessagingUtils.info("http.proxyHost: " + proxyData.getHost());
+
+ MessagingUtils.info("http.proxyPort: " + String.valueOf(proxyData
+ .getPort()));
+ }
+
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
- IProxyData[] proxyDataForHost = proxyService.select(uri);
- for (IProxyData data : proxyDataForHost) {
- if (data.getHost() != null) {
- MessagingUtils.info("http.proxyHost: " + data.getHost());
-
- MessagingUtils.info("http.proxyPort: " + String.valueOf(data
- .getPort()));
- }
-
- }
+
// check for updates, this causes I/O
final IStatus status = operation.resolveModal(monitor);
+ ungetProxyService();
MessagingUtils.info("update resolved " + System.currentTimeMillis() + "Status: " + status.toString());
// failed to find updates (inform user and exit)
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
}
return Status.OK_STATUS;
}
+
+ public static ProxyManager getProxyService() {
+ BundleContext bc = Activator.getDefault().getBundle().getBundleContext();
+ ServiceReference serviceReference = bc.getServiceReference(IProxyService.class.getName());
+ ProxyManager service = (ProxyManager) bc.getService(serviceReference);
+ return service;
+ }
+
+ public static boolean ungetProxyService() {
+ BundleContext bc = Activator.getDefault().getBundle().getBundleContext();
+ ServiceReference serviceReference = bc.getServiceReference(IProxyService.class.getName());
+ return bc.ungetService(serviceReference);
+
+ }
private void configureProvisioningJob(ProvisioningJob provisioningJob, final Shell shell, final UISynchronize sync,
final IWorkbench workbench) {