本文整理汇总了Java中org.eclipse.core.net.proxy.IProxyService类的典型用法代码示例。如果您正苦于以下问题:Java IProxyService类的具体用法?Java IProxyService怎么用?Java IProxyService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IProxyService类属于org.eclipse.core.net.proxy包,在下文中一共展示了IProxyService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProxy
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
@VisibleForTesting
public Proxy createProxy(URI uri) {
Preconditions.checkNotNull(uri, "uri is null");
Preconditions.checkArgument(!"http".equals(uri.getScheme()), "http is not a supported schema");
IProxyService proxyServiceCopy = proxyService;
if (proxyServiceCopy == null) {
return Proxy.NO_PROXY;
}
IProxyData[] proxyDataForUri = proxyServiceCopy.select(uri);
for (final IProxyData iProxyData : proxyDataForUri) {
switch (iProxyData.getType()) {
case IProxyData.HTTPS_PROXY_TYPE:
return new Proxy(Type.HTTP, new InetSocketAddress(iProxyData.getHost(),
iProxyData.getPort()));
case IProxyData.SOCKS_PROXY_TYPE:
return new Proxy(Type.SOCKS, new InetSocketAddress(iProxyData.getHost(),
iProxyData.getPort()));
default:
logger.warning("Unsupported proxy type: " + iProxyData.getType());
break;
}
}
return Proxy.NO_PROXY;
}
示例2: prepareProxySettings
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
public void prepareProxySettings(String uriString) {
URI uri;
try {
uri = new URI(uriString);
IProxyService proxyService = Activator.getDefault()
.getProxyService();
IProxyData[] proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if (data.getHost() != null) {
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", data.getHost());
}
if (data.getHost() != null) {
System.setProperty("http.proxyPort",
String.valueOf(data.getPort()));
}
}
// Close the service and close the service tracker
proxyService = null;
} catch (URISyntaxException e) {
getLog().log(
new Status(IStatus.WARNING, PLUGIN_ID, e.getMessage(), e));
}
}
示例3: configureClientProxy
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
@Override
public void configureClientProxy(
final HttpClient httpClient,
final HostConfiguration hostConfiguration,
final HttpState httpState,
final ConnectionInstanceData connectionInstanceData) {
final IProxyService proxyService = (IProxyService) serviceTracker.getService();
if (proxyService == null) {
return;
}
final String host = connectionInstanceData.getServerURI().getHost();
final String type = connectionInstanceData.getServerURI().getScheme().equals("http") //$NON-NLS-1$
? IProxyData.HTTP_PROXY_TYPE : IProxyData.HTTPS_PROXY_TYPE;
final IProxyChangeListener changeListener = new ProxyChangeListener(httpClient, host, type);
proxyService.addProxyChangeListener(changeListener);
httpClient.getParams().setParameter(PROXY_CHANGE_LISTENER_KEY, changeListener);
configureProxy(httpClient, host, type);
}
示例4: activateProxyService
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
/**
* Activate the proxy service by obtaining it.
*/
@SuppressWarnings(
{"rawtypes", "unchecked"})
private void activateProxyService()
{
Bundle bundle = Platform.getBundle("org.eclipse.ui.ide"); //$NON-NLS-1$
Object proxyService = null;
if (bundle != null)
{
ServiceReference ref =
bundle.getBundleContext().getServiceReference(
IProxyService.class.getName());
if (ref != null)
{
proxyService = bundle.getBundleContext().getService(ref);
}
}
if (proxyService == null)
{
IDEWorkbenchPlugin.log("Proxy service could not be found."); //$NON-NLS-1$
}
}
示例5: proxySettings
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
/**
* This will return a list of arguments for proxy settings (if we have any, otherwise an empty list).
*
* @param env
* The environment map. Passed in so we can flag passwords to obfuscate (in other words, we may modify
* the map)
*/
private List<String> proxySettings(Map<String, String> env)
{
IProxyService service = JSCorePlugin.getDefault().getProxyService();
if (service == null || !service.isProxiesEnabled())
{
return Collections.emptyList();
}
List<String> proxyArgs = new ArrayList<String>(4);
IProxyData httpData = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
if (httpData != null && httpData.getHost() != null)
{
CollectionsUtil.addToList(proxyArgs, "--proxy", buildProxyURL(httpData, env)); //$NON-NLS-1$
}
IProxyData httpsData = service.getProxyData(IProxyData.HTTPS_PROXY_TYPE);
if (httpsData != null && httpsData.getHost() != null)
{
CollectionsUtil.addToList(proxyArgs, "--https-proxy", buildProxyURL(httpsData, env)); //$NON-NLS-1$
}
return proxyArgs;
}
示例6: setupProxy
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
@SuppressWarnings("restriction")
private static CachingHttpClientBuilder setupProxy(CachingHttpClientBuilder builder, URI url){
final IProxyService proxyService = HybridCore.getDefault().getProxyService();
if(proxyService != null ){
IProxyData[] proxies = proxyService.select(url);
if(proxies != null && proxies.length > 0){
IProxyData proxy = proxies[0];
CredentialsProvider credsProvider = new BasicCredentialsProvider();
if(proxy.isRequiresAuthentication()){
credsProvider.setCredentials(new AuthScope(proxy.getHost(), proxy.getPort()),
new UsernamePasswordCredentials(proxy.getUserId(), proxy.getPassword()));
}
builder.setDefaultCredentialsProvider(credsProvider);
builder.setProxy(new HttpHost(proxy.getHost(), proxy.getPort()));
}
}
return builder;
}
示例7: Activator
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
/**
* The constructor
*/
public Activator() {
proxyTracker = new ServiceTracker(FrameworkUtil.getBundle(
this.getClass()).getBundleContext(),
IProxyService.class.getName(), null);
proxyTracker.open();
}
示例8: testUnsetDifferentProxyService
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
@Test
public void testUnsetDifferentProxyService() {
googleApiFactory.setProxyService(proxyService);
googleApiFactory.unsetProxyService(mock(IProxyService.class));
verify(proxyService, never()).removeProxyChangeListener(any(IProxyChangeListener.class));
verify(proxyFactory, never()).setProxyService(null);
// called once when setProxyService() is called
verify(transportCache).invalidateAll();
}
示例9: setProxyService
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL)
public void setProxyService(IProxyService proxyService) {
this.proxyService = proxyService;
this.proxyService.addProxyChangeListener(proxyChangeListener);
proxyFactory.setProxyService(this.proxyService);
if (transportCache != null) {
transportCache.invalidateAll();
}
}
示例10: unsetProxyService
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
public void unsetProxyService(IProxyService proxyService) {
if (this.proxyService == proxyService) {
proxyService.removeProxyChangeListener(proxyChangeListener);
this.proxyService = null;
proxyFactory.setProxyService(null);
if (transportCache != null) {
transportCache.invalidateAll();
}
}
}
示例11: getProxyService
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
public IProxyService getProxyService() {
try {
if (proxyServiceTracker == null) {
proxyServiceTracker = new ServiceTracker<>(context, IProxyService.class.getName(), null);
proxyServiceTracker.open();
}
return proxyServiceTracker.getService();
} catch (Exception e) {
logException(e.getMessage(), e);
}
return null;
}
示例12: run
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
public void run() throws CoreException {
IProxyService proxyService = getProxyService();
originalSystemProxiesEnabled = proxyService.isSystemProxiesEnabled();
originalProxiesEnabled = proxyService.isProxiesEnabled();
originalData = proxyService.getProxyData();
try {
// set new proxy
proxyService.setSystemProxiesEnabled(false);
proxyService.setProxiesEnabled(enableProxies);
IProxyData[] data = proxyService.getProxyData();
IProxyData matchedData = null;
for (IProxyData singleData : data) {
if (singleData.getType().equals(proxyDataType)) {
matchedData = singleData;
break;
}
}
if (matchedData == null) {
throw new CoreException(CloudFoundryPlugin.getErrorStatus("No matched proxy data type found for: "
+ proxyDataType));
}
matchedData.setHost(host);
matchedData.setPort(port);
proxyService.setProxyData(data);
handleProxyChange();
}
finally {
// restore proxy settings
proxyService.setSystemProxiesEnabled(originalSystemProxiesEnabled);
proxyService.setProxiesEnabled(originalProxiesEnabled);
proxyService.setProxyData(originalData);
}
}
示例13: getProxy
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
public static HttpProxyConfiguration getProxy(URL url) {
if (url == null) {
return null;
}
// In certain cases, the activator would have stopped and the plugin may
// no longer be available. Usually onl happens on shutdown.
CloudFoundryPlugin plugin = CloudFoundryPlugin.getDefault();
if (plugin != null) {
IProxyService proxyService = plugin.getProxyService();
if (proxyService != null) {
try {
IProxyData[] selectedProxies = proxyService.select(url.toURI());
// No proxy configured or not found
if (selectedProxies == null || selectedProxies.length == 0) {
return null;
}
IProxyData data = selectedProxies[0];
int proxyPort = data.getPort();
String proxyHost = data.getHost();
String user = data.getUserId();
String password = data.getPassword();
return proxyHost != null ? new HttpProxyConfiguration(proxyHost, proxyPort,
data.isRequiresAuthentication(), user, password) : null;
}
catch (URISyntaxException e) {
// invalid url (protocol, ...) => proxy will be null
}
}
}
return null;
}
示例14: getProxy
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
public static IProxyData getProxy(URL url) {
if (url == null) {
return null;
}
// In certain cases, the activator would have stopped and the plugin may
// no longer be available. Usually onl happens on shutdown.
CloudFoundryPlugin plugin = CloudFoundryPlugin.getDefault();
if (plugin != null) {
IProxyService proxyService = plugin.getProxyService();
if (proxyService != null) {
try {
IProxyData[] selectedProxies = proxyService.select(url.toURI());
// No proxy configured or not found
if (selectedProxies == null || selectedProxies.length == 0) {
return null;
}
return selectedProxies[0];
}
catch (URISyntaxException e) {
// invalid url (protocol, ...) => proxy will be null
}
}
}
return null;
}
示例15: getProxyData
import org.eclipse.core.net.proxy.IProxyService; //导入依赖的package包/类
private IProxyData getProxyData(URI uri) {
IProxyService proxyService = getProxyService();
if (proxyService != null && proxyService.isProxiesEnabled()) {
if (!proxyService.isSystemProxiesEnabled()) {
IProxyData[] proxies = proxyService.select(uri);
if (proxies.length > 0) {
return proxies[0];
}
}
}
return null;
}