当前位置: 首页>>代码示例>>Java>>正文


Java Type.HTTP属性代码示例

本文整理汇总了Java中java.net.Proxy.Type.HTTP属性的典型用法代码示例。如果您正苦于以下问题:Java Type.HTTP属性的具体用法?Java Type.HTTP怎么用?Java Type.HTTP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.net.Proxy.Type的用法示例。


在下文中一共展示了Type.HTTP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createProxy

@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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:26,代码来源:ProxyFactory.java

示例2: convert

protected void convert(String pacResult, List<Proxy> result) {
    Matcher m = PAC_RESULT_PATTERN.matcher(pacResult);
    while (m.find()) {
        String scriptProxyType = m.group(1);
        if ("DIRECT".equals(scriptProxyType)) {
            result.add(Proxy.NO_PROXY);
        } else {
            Type proxyType;
            if ("PROXY".equals(scriptProxyType)) {
                proxyType = Type.HTTP;
            } else if ("SOCKS".equals(scriptProxyType)) {
                proxyType = Type.SOCKS;
            } else {
                // Should never happen, already filtered by Pattern.
                throw new RuntimeException("Unrecognized proxy type.");
            }
            result.add(new Proxy(proxyType, new InetSocketAddress(m
                    .group(2), Integer.parseInt(m.group(3)))));
        }
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:21,代码来源:PacProxySelector.java

示例3: getProxyFromProxyData

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;
}
 
开发者ID:kwin,项目名称:cppcheclipse,代码行数:20,代码来源:HttpClientService.java

示例4: initHttpProxy

/**
 * 初始化HTTP代理服务器
 */
private void initHttpProxy() {
    // 初始化代理服务器
    if (httpProxyHost != null && httpProxyPort != null) {
        SocketAddress sa = new InetSocketAddress(httpProxyHost, httpProxyPort);
        proxy = new Proxy(Type.HTTP, sa);
        // 初始化代理服务器的用户验证
        if (httpProxyUsername != null && httpProxyPassword != null) {
            Authenticator.setDefault(new Authenticator() {

                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(httpProxyUsername, httpProxyPassword.toCharArray());
                }
            });
        }

    }
}
 
开发者ID:caijianqing,项目名称:weixinmp4java,代码行数:21,代码来源:AbstractWeixinmpController.java

示例5: restTemplate

@Bean
public RestTemplate restTemplate() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();

    Proxy proxy= new Proxy(Type.HTTP, new InetSocketAddress("vip-px.main.aviva.eu.corp", 8080));
    requestFactory.setProxy(proxy);
    return new RestTemplate(requestFactory);
   // return new RestTemplate();
}
 
开发者ID:ammiladi,项目名称:geocoder-microservices,代码行数:9,代码来源:RestTemplateConfig.java

示例6: openConnection

private HttpURLConnection openConnection ( final URL url ) throws IOException
{
    final String host = this.properties.getProperty ( "local.proxy.host" );
    final String port = this.properties.getProperty ( "local.proxy.port" );

    if ( host != null && port != null && !host.isEmpty () && !port.isEmpty () )
    {
        final Proxy proxy = new Proxy ( Type.HTTP, new InetSocketAddress ( host, Integer.parseInt ( port ) ) );
        return (HttpURLConnection)url.openConnection ( proxy );
    }
    else
    {
        return (HttpURLConnection)url.openConnection ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:Processor.java

示例7: toType

Type toType(){
    switch (this){
        case SOCKS: return Type.SOCKS;
        case HTTP: return Type.HTTP;
    }
    return  Type.DIRECT;
}
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:7,代码来源:HTTPProxy.java

示例8: setHttpProxy

public void setHttpProxy(String host, int port) {
    if (host != null && !host.isEmpty()) {
        // Debug
        logger.debug("Using HTTP proxy for REST connection: " + host + ":" + port);

        // Set proxy
        SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) getRequestFactory();
        Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(host, port));
        requestFactory.setProxy(proxy);
    }
}
 
开发者ID:nuagenetworks,项目名称:java-bambou,代码行数:11,代码来源:RestClientTemplate.java

示例9: proxiedRequestToItsOwnUrlWithoutIllEffect

@Test
public void proxiedRequestToItsOwnUrlWithoutIllEffect() throws Exception {
    Request request = new Request.Builder().url("http://localhost:9092/").build();
    Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("localhost", 9092));
    Response response = client.newBuilder().proxy(proxy).build().newCall(request).execute();
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.code());
    // HTTP 1.1 persistent connection needs content-length
    assertEquals(Protocol.HTTP_1_1, response.protocol());
    assertEquals("24", response.header("content-length"));
    assertEquals("text/plain; charset=UTF-8", response.header("content-type"));
    assertEquals("Failure: 404 Not Found", response.body().source().readUtf8Line());
    // since proxied URI is http://localhost:9092/ instead of /
    // TODO should respond cached or upstream content
}
 
开发者ID:ganskef,项目名称:shortcircuit-proxy,代码行数:14,代码来源:EvaluationServerAcceptanceTest.java

示例10: securedProxiedRequestToItsOwnUrlWithoutIllEffect

@Test
public void securedProxiedRequestToItsOwnUrlWithoutIllEffect() throws Exception {
    Request request = new Request.Builder().url("https://localhost:9092/").build();
    Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("localhost", 9092));
    Response response = client.newBuilder().proxy(proxy).build().newCall(request).execute();
    assertEquals(HttpURLConnection.HTTP_OK, response.code());
    // HTTP 1.1 persistent connection needs content-length
    assertEquals(Protocol.HTTP_1_1, response.protocol());
    assertEquals("25", response.header("content-length"));
    assertEquals("text/plain; charset=UTF-8", response.header("content-type"));
    assertEquals("Response status: 200 OK", response.body().source().readUtf8Line());
    // since proxied URI is /, TODO needs host and port from CONNECT
    // TODO should respond cached or upstream content
}
 
开发者ID:ganskef,项目名称:shortcircuit-proxy,代码行数:14,代码来源:EvaluationServerAcceptanceTest.java

示例11: testConstructorWithProxy

@Test
public void testConstructorWithProxy() throws MalformedURLException, IOException {
  Proxy proxy =
      new Proxy(Type.HTTP,
                new InetSocketAddress(proxyServer.getHostname(), proxyServer.getPort()));
  HttpURLConnection connection =
      new TimeoutAwareConnectionFactory(proxy).openConnection(new URL(NONEXISTENTDOMAIN));
  connectReadAndDisconnect(connection);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:9,代码来源:TimeoutAwareConnectionFactoryTest.java

示例12: testConstructorWithProxyAndTimeouts

@Test
public void testConstructorWithProxyAndTimeouts() throws MalformedURLException, IOException {
  Proxy proxy =
      new Proxy(Type.HTTP,
                new InetSocketAddress(proxyServer.getHostname(), proxyServer.getPort()));
  HttpURLConnection connection =
      new TimeoutAwareConnectionFactory(proxy, 1764, 3528)
          .openConnection(new URL(NONEXISTENTDOMAIN));
  connectReadAndDisconnect(connection);
  assertThat(connection.getConnectTimeout(), is(1764));
  assertThat(connection.getReadTimeout(), is(3528));
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:12,代码来源:TimeoutAwareConnectionFactoryTest.java

示例13: getConnection

private HttpURLConnection getConnection(String url) throws IOException {
    HttpURLConnection con = null;
    if (proxyHost != null && !proxyHost.equals("")) {
        if (proxyAuthUser != null && !proxyAuthUser.equals("")) {
            log("Proxy AuthUser: " + proxyAuthUser);
            log("Proxy AuthPassword: " + proxyAuthPassword);
            Authenticator.setDefault(new Authenticator() {
                @Override
                protected PasswordAuthentication
                getPasswordAuthentication() {
                    //respond only to proxy auth requests
                    if (getRequestorType().equals(RequestorType.PROXY)) {
                        return new PasswordAuthentication(proxyAuthUser,
                                proxyAuthPassword
                                        .toCharArray());
                    } else {
                        return null;
                    }
                }
            });
        }
        final Proxy proxy = new Proxy(Type.HTTP, InetSocketAddress
                .createUnresolved(proxyHost, proxyPort));
        if(DEBUG){
            log("Opening proxied connection(" + proxyHost + ":" + proxyPort + ")");
        }
        con = (HttpURLConnection) new URL(url).openConnection(proxy);
    } else {
        con = (HttpURLConnection) new URL(url).openConnection();
    }
    if (connectionTimeout > 0 && !isJDK14orEarlier) {
        con.setConnectTimeout(connectionTimeout);
    }
    if (readTimeout > 0 && !isJDK14orEarlier) {
        con.setReadTimeout(readTimeout);
    }
    return con;
}
 
开发者ID:WildDogTeam,项目名称:demo-android-login,代码行数:38,代码来源:HttpClient.java

示例14: testHttpResponseFromBrowser

@Test
public void testHttpResponseFromBrowser() throws URISyntaxException {
    proxySelector.setBrowserResponse(new URI("http://" + PROXY_HOST + ":" + PROXY_PORT));

    List<Proxy> result = proxySelector.select(new URI("http://example.org"));

    Proxy expectedProxy = new Proxy(Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT));

    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(expectedProxy, result.get(0));
}
 
开发者ID:GITNE,项目名称:icedtea-web,代码行数:12,代码来源:PluginProxySelectorTest.java

示例15: getProxy

private static Proxy getProxy ( final String url )
{
    final ProxySelector ps = ProxySelector.getDefault ();
    if ( ps == null )
    {
        logger.debug ( "No proxy selector found" );
        return null;
    }

    final List<java.net.Proxy> proxies = ps.select ( URI.create ( url ) );
    for ( final java.net.Proxy proxy : proxies )
    {
        if ( proxy.type () != Type.HTTP )
        {
            logger.debug ( "Unsupported proxy type: {}", proxy.type () );
            continue;
        }

        final SocketAddress addr = proxy.address ();
        logger.debug ( "Proxy address: {}", addr );

        if ( ! ( addr instanceof InetSocketAddress ) )
        {
            logger.debug ( "Unsupported proxy address type: {}", addr.getClass () );
            continue;
        }

        final InetSocketAddress inetAddr = (InetSocketAddress)addr;

        return new Proxy ( Proxy.TYPE_HTTP, inetAddr.getHostString (), inetAddr.getPort () );
    }

    logger.debug ( "No proxy found" );
    return null;
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:35,代码来源:Helper.java


注:本文中的java.net.Proxy.Type.HTTP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。