Java HTTP Port createProxy(final Proxy.Type type, final String host, final int port)

Here you can find the source of createProxy(final Proxy.Type type, final String host, final int port)

Description

create Proxy

License

Open Source License

Parameter

Parameter Description
type a parameter
host a parameter
port a parameter

Declaration

public static Proxy createProxy(final Proxy.Type type, final String host, final int port) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2013 compeople AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  w w w  .  j  av  a2  s .  com
 *    compeople AG - initial API and implementation
 *******************************************************************************/

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;

public class Main {
    /**
     * @param type
     * @param host
     * @param port
     * @return
     */
    public static Proxy createProxy(final Proxy.Type type, final String host, final int port) {
        return new Proxy(type, InetSocketAddress.createUnresolved(host, port));
    }

    /**
     * @param scheme
     * @param sa
     * @return
     */
    public static Proxy createProxy(final String scheme, final SocketAddress sa) {
        final Proxy.Type type = resolveProxyType(scheme);
        return new Proxy(type, sa);
    }

    /**
     * @param protocol
     * @return
     */
    public static Proxy.Type resolveProxyType(final String protocol) {
        if (protocol != null && (protocol.equalsIgnoreCase("socks") || protocol.equalsIgnoreCase("socket"))) { //$NON-NLS-1$ //$NON-NLS-2$
            return Proxy.Type.SOCKS;
        } else {
            return Proxy.Type.HTTP;
        }
    }
}

Related

  1. checkHostAvailability(String host, int port)
  2. checkHostPort(String connectionString)
  3. checkIfPortAvailable(int port)
  4. create(final int[] ports)
  5. create(String scheme, String rawUserInfo, String host, int port, String rawPath, String rawQuery, String rawFragment)
  6. createServer(final String host, final int port)