Package java.net

Examples of java.net.Proxy


     * Client Side Policy.
     *
     * @return The proxy server or null, if not set.
     */
    private Proxy getProxy(HTTPClientPolicy policy) {
        Proxy proxy = null;
        if (policy != null
            && policy.isSetProxyServer()
            && !StringUtils.isEmpty(policy.getProxyServer())) {
            proxy = new Proxy(
                    Proxy.Type.valueOf(policy.getProxyServerType().toString()),
                    new InetSocketAddress(policy.getProxyServer(),
                                          policy.getProxyServerPort()));
        }
        return proxy;
View Full Code Here


        });
        final InetSocketAddress isa1 = new InetSocketAddress(ia, 11111);
        final InetSocketAddress isa2 = new InetSocketAddress(ia, 22222);

        final List<Proxy> proxies = new ArrayList<Proxy>(2);
        proxies.add(new Proxy(Proxy.Type.HTTP, isa1));
        proxies.add(new Proxy(Proxy.Type.HTTP, isa2));

        Mockito.when(proxySelector.select(new URI("http://somehost:80"))).thenReturn(proxies);

        final HttpHost target = new HttpHost("somehost", 80, "http");
        final HttpRequest request =
View Full Code Here

  final HttpURLConnection httpOpen(URL u) throws IOException {
    return httpOpen(METHOD_GET, u);
  }

  final HttpURLConnection httpOpen(String method, URL u) throws IOException {
    final Proxy proxy = HttpSupport.proxyFor(proxySelector, u);
    HttpURLConnection conn = (HttpURLConnection) u.openConnection(proxy);

    if (!http.sslVerify && "https".equals(u.getProtocol())) {
      disableSslVerify(conn);
    }
View Full Code Here

           List l = ProxySelector.getDefault().select(
                        new URI(_STR_URL_));
           
            for (Iterator iter = l.iterator(); iter.hasNext(); ) {
               
                Proxy proxy = (Proxy) iter.next();
               
                //System.out.println(">> " + STR_TOTO + " - url=" + _STR_URL_);
                //System.out.println(">> " + STR_TOTO + " - proxy.type()=" + proxy.type());
               
                InetSocketAddress addr = (InetSocketAddress)
                    proxy.address();
               
                if(addr == null)
                {
                    //System.out.println(">> " + STR_TOTO + " - No Proxy"); 
                }
View Full Code Here

        final HttpURLConnection conn;
        final String proxyHost = getProxyHost();
        final int proxyPort = getProxyPortInt();
        if (proxyHost.length() > 0 && proxyPort > 0){
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
            //TODO - how to define proxy authentication for a single connection?
            // It's not clear if this is possible
//            String user = getProxyUser();
//            if (user.length() > 0){
//                Authenticator auth = new ProxyAuthenticator(user, getProxyPass());
View Full Code Here

     * Client Side Policy.
     *
     * @return The proxy server or null, if not set.
     */
    private Proxy getProxy(HTTPClientPolicy policy) {
        Proxy proxy = null;
        if (policy != null
            && policy.isSetProxyServer()
            && !StringUtils.isEmpty(policy.getProxyServer())) {
            proxy = new Proxy(
                    Proxy.Type.valueOf(policy.getProxyServerType().toString()),
                    new InetSocketAddress(policy.getProxyServer(),
                                          policy.getProxyServerPort()));
        }
        return proxy;
View Full Code Here

        HttpURLConnection connection = null;
        ClientConfig config = request.getAttribute(ClientConfig.class);

        // setup proxy
        if (config.getProxyHost() != null) {
            Proxy proxy =
                new Proxy(Proxy.Type.HTTP, new InetSocketAddress(config.getProxyHost(), config
                    .getProxyPort()));
            connection = (HttpURLConnection)url.openConnection(proxy);
        } else {
            connection = (HttpURLConnection)url.openConnection();
        }
View Full Code Here

    try  {
      System.out.println("Fetching: " + urlSpec);
      URL url = new URL(urlSpec);
      URLConnection con;
      if(inCambridge){
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("wwwcache.cam.ac.uk", 8080));
        con = url.openConnection(proxy);
      } else {
        con = url.openConnection();
      }
      //if(con == null) return false;
View Full Code Here

        }
        super.initHttpHeaders(pRequest);
    }

    protected URLConnection newURLConnection(URL pURL) throws IOException {
        final Proxy prox = getProxy();
        final URLConnection conn = prox == null ? pURL.openConnection() : pURL.openConnection(prox);
        final SSLSocketFactory sslSockFactory = getSSLSocketFactory();
        if (sslSockFactory != null  &&  conn instanceof HttpsURLConnection) {
            ((HttpsURLConnection)conn).setSSLSocketFactory(sslSockFactory);
        }
View Full Code Here

     * @param proxyPort The proxy port number.
     * @throws IllegalArgumentException if the proxyHost parameter is null or if
     *     the proxyPort parameter is outside the range of valid port values.
     */
    public void setProxy(String proxyHost, int proxyPort) {
        setProxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress(proxyHost,proxyPort)));
    }
View Full Code Here

TOP

Related Classes of java.net.Proxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.