本文整理汇总了Java中org.eclipse.core.net.proxy.IProxyData类的典型用法代码示例。如果您正苦于以下问题:Java IProxyData类的具体用法?Java IProxyData怎么用?Java IProxyData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IProxyData类属于org.eclipse.core.net.proxy包,在下文中一共展示了IProxyData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProxy
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的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.IProxyData; //导入依赖的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.IProxyData; //导入依赖的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: getProxyConfiguration
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
protected ProxyConfiguration getProxyConfiguration() {
try {
IProxyData proxyData = CloudServerUtil.getProxy(new URL(cloudServer.getUrl()));
if (proxyData != null) {
String proxyHost = proxyData.getHost();
int proxyPort = proxyData.getPort();
String user = proxyData.getUserId();
String password = proxyData.getPassword();
return ProxyConfiguration.builder().host(proxyHost)
.port(proxyPort == -1 ? Optional.empty() : Optional.of(proxyPort))
.username(Optional.ofNullable(user)).password(Optional.ofNullable(password)).build();
}
} catch (MalformedURLException e) {
CloudFoundryPlugin.logError(e);
}
return null;
}
示例5: testNoProxySetHTTP
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
public void testNoProxySetHTTP() throws Exception {
new ProxyHandler(null, -1, false, IProxyData.HTTP_PROXY_TYPE) {
@Override
protected void handleProxyChange() throws CoreException {
try {
HttpProxyConfiguration configuration = CloudFoundryClientFactory
.getProxy(new URL(VALID_V1_HTTP_URL));
assertNull(configuration);
// verify it is null for https as well
configuration = CloudFoundryClientFactory.getProxy(new URL(VALID_V1_HTTPS_URL));
assertNull(configuration);
}
catch (MalformedURLException e) {
throw CloudErrorUtil.toCoreException(e);
}
}
};
}
示例6: testNoProxySetHTTPS
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
public void testNoProxySetHTTPS() throws Exception {
new ProxyHandler(null, -1, false, IProxyData.HTTPS_PROXY_TYPE) {
@Override
protected void handleProxyChange() throws CoreException {
try {
HttpProxyConfiguration configuration = CloudFoundryClientFactory
.getProxy(new URL(VALID_V1_HTTPS_URL));
assertNull(configuration);
// verify it is null for https as well
configuration = CloudFoundryClientFactory.getProxy(new URL(VALID_V1_HTTP_URL));
assertNull(configuration);
}
catch (MalformedURLException e) {
throw CloudErrorUtil.toCoreException(e);
}
}
}.run();
}
示例7: testProxySetDirectHTTPS
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
public void testProxySetDirectHTTPS() throws Exception {
// Direct provider means not using proxy settings even if they are set.
// To set direct provider, disable proxies even when set
boolean enableProxies = false;
new ProxyHandler("invalid.proxy.test", 8080, enableProxies, IProxyData.HTTPS_PROXY_TYPE) {
@Override
protected void handleProxyChange() throws CoreException {
try {
HttpProxyConfiguration configuration = CloudFoundryClientFactory
.getProxy(new URL(VALID_V1_HTTPS_URL));
assertNull(configuration);
// verify it is null for https as well
configuration = CloudFoundryClientFactory.getProxy(new URL(VALID_V1_HTTP_URL));
assertNull(configuration);
}
catch (MalformedURLException e) {
throw CloudErrorUtil.toCoreException(e);
}
}
}.run();
}
示例8: testProxyDirectSetHTTP
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
public void testProxyDirectSetHTTP() throws Exception {
// Direct provider means not using proxy settings even if they are set.
// To set direct provider, disable proxies even when set
boolean enableProxies = false;
new ProxyHandler("invalid.proxy.test", 8080, enableProxies, IProxyData.HTTP_PROXY_TYPE) {
@Override
protected void handleProxyChange() throws CoreException {
try {
HttpProxyConfiguration configuration = CloudFoundryClientFactory
.getProxy(new URL(VALID_V1_HTTP_URL));
assertNull(configuration);
// verify it is null for https as well
configuration = CloudFoundryClientFactory.getProxy(new URL(VALID_V1_HTTPS_URL));
assertNull(configuration);
}
catch (MalformedURLException e) {
throw CloudErrorUtil.toCoreException(e);
}
}
}.run();
}
示例9: getProxyFromProxyData
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
private Proxy getProxyFromProxyData(IProxyData proxyData) throws UnknownHostException {
Type proxyType;
if (IProxyData.HTTP_PROXY_TYPE.equals(proxyData.getType())) {
proxyType = Type.HTTP;
} else if (IProxyData.SOCKS_PROXY_TYPE.equals(proxyData.getType())) {
proxyType = Type.SOCKS;
} else if (IProxyData.HTTPS_PROXY_TYPE.equals(proxyData.getType())) {
proxyType = Type.HTTP;
} else {
throw new IllegalArgumentException("Invalid proxy type " + proxyData.getType());
}
InetSocketAddress sockAddr = new InetSocketAddress(InetAddress.getByName(proxyData.getHost()), proxyData.getPort());
Proxy proxy = new Proxy(proxyType, sockAddr);
if (!Strings.isNullOrEmpty(proxyData.getUserId())) {
Authenticator.setDefault(new ProxyAuthenticator(proxyData.getUserId(), proxyData.getPassword()));
}
return proxy;
}
示例10: proxySettings
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的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;
}
示例11: buildProxyURL
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
/**
* Given proxy data, we try to convert that back into a full URL
*
* @param data
* The {@link IProxyData} we're converting into a URL string.
* @param env
* The environment map. Passed in so we can flag passwords to obfuscate (in other words, we may modify
* the map)
* @return
*/
private String buildProxyURL(IProxyData data, Map<String, String> env)
{
StringBuilder builder = new StringBuilder();
builder.append("http://"); //$NON-NLS-1$
if (!StringUtil.isEmpty(data.getUserId()))
{
builder.append(data.getUserId());
builder.append(':');
String password = data.getPassword();
builder.append(password);
builder.append('@');
env.put(IProcessRunner.TEXT_TO_OBFUSCATE, password);
}
builder.append(data.getHost());
if (data.getPort() != -1)
{
builder.append(':');
builder.append(data.getPort());
}
return builder.toString();
}
示例12: setupProxy
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的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;
}
示例13: getProxyHost
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
@Override
public String getProxyHost() {
if (!isProxiesEnabled()) {
return Constants.EMPTY_STRING;
}
IProxyData httpProxyData = getHttpProxyData();
if (httpProxyData != null && Utils.isNotEmpty(httpProxyData.getHost())) {
if (logger.isDebugEnabled()) {
logger.debug("Returning '" + httpProxyData.getHost() + "' as proxy host ");
}
return httpProxyData.getHost();
} else {
return Constants.EMPTY_STRING;
}
}
示例14: getProxyPort
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
@Override
public String getProxyPort() {
if (!isProxiesEnabled()) {
return Constants.EMPTY_STRING;
}
IProxyData httpProxyData = getHttpProxyData();
if (httpProxyData != null && Utils.isNotEmpty(httpProxyData.getPort())) {
if (logger.isDebugEnabled()) {
logger.debug("Returning '" + httpProxyData.getPort() + "' as proxy port ");
}
return String.valueOf(httpProxyData.getPort());
} else {
return Constants.EMPTY_STRING;
}
}
示例15: testInit_ProxyChangeHandlerIsSet
import org.eclipse.core.net.proxy.IProxyData; //导入依赖的package包/类
@Test
public void testInit_ProxyChangeHandlerIsSet() {
when(proxyService.select(any(URI.class))).thenReturn(new IProxyData[0]);
googleApiFactory.setProxyService(proxyService);
googleApiFactory.init();
verify(proxyService).addProxyChangeListener(any(IProxyChangeListener.class));
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:10,代码来源:GoogleApiFactoryWithProxyServerTest.java