Example usage for org.apache.http.conn UnsupportedSchemeException UnsupportedSchemeException

List of usage examples for org.apache.http.conn UnsupportedSchemeException UnsupportedSchemeException

Introduction

In this page you can find the example usage for org.apache.http.conn UnsupportedSchemeException UnsupportedSchemeException.

Prototype

public UnsupportedSchemeException(final String message) 

Source Link

Document

Creates a UnsupportedSchemeException with the specified detail message.

Usage

From source file:com.olacabs.fabric.compute.builder.impl.JarScanner.java

URL[] download(Collection<String> urls) {

    ArrayList<URL> downloadedURLs = urls.stream().map(url -> {
        URI uri = URI.create(url);
        String downloaderImplClassName = properties.getProperty(String.format("fs.%s.impl", uri.getScheme()));
        if (null == downloaderImplClassName) {
            throw new RuntimeException(
                    new UnsupportedSchemeException(uri.getScheme() + " is not supported for downloading jars"));
        }/*from  ww w .  j a  va 2 s . c  om*/
        try {
            Class clazz = Class.forName(downloaderImplClassName);
            if (JarDownloader.class.isAssignableFrom(clazz)) {
                try {
                    return ((JarDownloader) clazz.newInstance()).download(url).toUri().toURL();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
                throw new RuntimeException("Unsupported implementation " + downloaderImplClassName + " of "
                        + JarDownloader.class.getSimpleName());
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toCollection(ArrayList::new));
    return downloadedURLs.toArray(new URL[downloadedURLs.size()]);
}

From source file:sabina.integration.TestScenario.java

TestScenario(String backend, int port, boolean secure, boolean externalFiles) {
    this.port = port;
    this.backend = backend;
    this.secure = secure;
    this.externalFiles = externalFiles;

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslFactory(),
            ALLOW_ALL_HOSTNAME_VERIFIER);

    Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", sslConnectionSocketFactory).build();

    HttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(socketFactoryRegistry,
            new ManagedHttpClientConnectionFactory());

    RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.NETSCAPE).build();
    cookieStore = new BasicCookieStore();
    HttpClientContext context = HttpClientContext.create();
    context.setCookieStore(cookieStore);

    this.httpClient = HttpClients.custom().setSchemePortResolver(h -> {
        Args.notNull(h, "HTTP host");
        final int port1 = h.getPort();
        if (port1 > 0) {
            return port1;
        }/*from w  ww  . j a  v  a  2s  . c  om*/

        final String name = h.getSchemeName();
        if (name.equalsIgnoreCase("http")) {
            return port1;
        } else if (name.equalsIgnoreCase("https")) {
            return port1;
        } else {
            throw new UnsupportedSchemeException("unsupported protocol: " + name);
        }
    }).setConnectionManager(connManager).setDefaultRequestConfig(globalConfig).build();
}

From source file:org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.java

@Override
public void connect(final ManagedHttpClientConnection conn, final HttpHost host,
        final InetSocketAddress localAddress, final int connectTimeout, final SocketConfig socketConfig,
        final HttpContext context) throws IOException {
    final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(context);
    final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }//from   w ww  . j a v a2 s .co  m
    final InetAddress[] addresses = host.getAddress() != null ? new InetAddress[] { host.getAddress() }
            : this.dnsResolver.resolve(host.getHostName());
    final int port = this.schemePortResolver.resolve(host);
    for (int i = 0; i < addresses.length; i++) {
        final InetAddress address = addresses[i];
        final boolean last = i == addresses.length - 1;

        Socket sock = sf.createSocket(context);
        sock.setSoTimeout(socketConfig.getSoTimeout());
        sock.setReuseAddress(socketConfig.isSoReuseAddress());
        sock.setTcpNoDelay(socketConfig.isTcpNoDelay());
        sock.setKeepAlive(socketConfig.isSoKeepAlive());
        final int linger = socketConfig.getSoLinger();
        if (linger >= 0) {
            sock.setSoLinger(true, linger);
        }
        conn.bind(sock);

        final InetSocketAddress remoteAddress = new InetSocketAddress(address, port);
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connecting to " + remoteAddress);
        }
        try {
            sock = sf.connectSocket(connectTimeout, sock, host, remoteAddress, localAddress, context);
            conn.bind(sock);
            if (this.log.isDebugEnabled()) {
                this.log.debug("Connection established " + conn);
            }
            return;
        } catch (final SocketTimeoutException ex) {
            if (last) {
                throw new ConnectTimeoutException(ex, host, addresses);
            }
        } catch (final ConnectException ex) {
            if (last) {
                final String msg = ex.getMessage();
                if ("Connection timed out".equals(msg)) {
                    throw new ConnectTimeoutException(ex, host, addresses);
                } else {
                    throw new HttpHostConnectException(ex, host, addresses);
                }
            }
        } catch (final NoRouteToHostException ex) {
            if (last) {
                throw ex;
            }
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connect to " + remoteAddress + " timed out. "
                    + "Connection will be retried using another IP address");
        }
    }
}

From source file:org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.java

@Override
public void upgrade(final ManagedHttpClientConnection conn, final HttpHost host, final HttpContext context)
        throws IOException {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext);
    final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }//w ww  .  java2 s .  c  om
    if (!(sf instanceof LayeredConnectionSocketFactory)) {
        throw new UnsupportedSchemeException(
                host.getSchemeName() + " protocol does not support connection upgrade");
    }
    final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
    Socket sock = conn.getSocket();
    final int port = this.schemePortResolver.resolve(host);
    sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
    conn.bind(sock);
}

From source file:org.apache.http.impl.conn.HttpClientConnectionOperator.java

public void connect(final ManagedHttpClientConnection conn, final HttpHost host,
        final InetSocketAddress localAddress, final int connectTimeout, final SocketConfig socketConfig,
        final HttpContext context) throws IOException {
    final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(context);
    final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }/*w  w  w .ja v  a 2s.  co  m*/
    final InetAddress[] addresses = this.dnsResolver.resolve(host.getHostName());
    final int port = this.schemePortResolver.resolve(host);
    for (int i = 0; i < addresses.length; i++) {
        final InetAddress address = addresses[i];
        final boolean last = i == addresses.length - 1;

        Socket sock = sf.createSocket(context);
        sock.setReuseAddress(socketConfig.isSoReuseAddress());
        conn.bind(sock);

        final InetSocketAddress remoteAddress = new InetSocketAddress(address, port);
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connecting to " + remoteAddress);
        }
        try {
            sock.setSoTimeout(socketConfig.getSoTimeout());
            sock = sf.connectSocket(connectTimeout, sock, host, remoteAddress, localAddress, context);
            sock.setTcpNoDelay(socketConfig.isTcpNoDelay());
            sock.setKeepAlive(socketConfig.isSoKeepAlive());
            final int linger = socketConfig.getSoLinger();
            if (linger >= 0) {
                sock.setSoLinger(linger > 0, linger);
            }
            conn.bind(sock);
            if (this.log.isDebugEnabled()) {
                this.log.debug("Connection established " + conn);
            }
            return;
        } catch (final SocketTimeoutException ex) {
            if (last) {
                throw new ConnectTimeoutException(ex, host, addresses);
            }
        } catch (final ConnectException ex) {
            if (last) {
                final String msg = ex.getMessage();
                if ("Connection timed out".equals(msg)) {
                    throw new ConnectTimeoutException(ex, host, addresses);
                } else {
                    throw new HttpHostConnectException(ex, host, addresses);
                }
            }
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connect to " + remoteAddress + " timed out. "
                    + "Connection will be retried using another IP address");
        }
    }
}

From source file:org.apache.http.impl.conn.HttpClientConnectionOperator.java

public void upgrade(final ManagedHttpClientConnection conn, final HttpHost host, final HttpContext context)
        throws IOException {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext);
    final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }//from   w  w w  .java2s.c  o  m
    if (!(sf instanceof LayeredConnectionSocketFactory)) {
        throw new UnsupportedSchemeException(
                host.getSchemeName() + " protocol does not support connection upgrade");
    }
    final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
    Socket sock = conn.getSocket();
    final int port = this.schemePortResolver.resolve(host);
    sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
    conn.bind(sock);
}

From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java

@Override
public Future<NHttpClientConnection> requestConnection(final HttpRoute route, final Object state,
        final long connectTimeout, final long leaseTimeout, final TimeUnit tunit,
        final FutureCallback<NHttpClientConnection> callback) {
    Args.notNull(route, "HTTP route");
    if (this.log.isDebugEnabled()) {
        this.log.debug("Connection request: " + format(route, state) + formatStats(route));
    }/*www. j  av a2  s. c om*/
    final BasicFuture<NHttpClientConnection> future = new BasicFuture<NHttpClientConnection>(callback);
    final HttpHost host;
    if (route.getProxyHost() != null) {
        host = route.getProxyHost();
    } else {
        host = route.getTargetHost();
    }
    final SchemeIOSessionStrategy sf = this.iosessionFactoryRegistry.lookup(host.getSchemeName());
    if (sf == null) {
        future.failed(new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported"));
        return future;
    }
    this.pool.lease(route, state, connectTimeout, leaseTimeout, tunit != null ? tunit : TimeUnit.MILLISECONDS,
            new InternalPoolEntryCallback(future));
    return future;
}

From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java

@Override
public void startRoute(final NHttpClientConnection managedConn, final HttpRoute route,
        final HttpContext context) throws IOException {
    Args.notNull(managedConn, "Managed connection");
    Args.notNull(route, "HTTP route");
    final HttpHost host;
    if (route.getProxyHost() != null) {
        host = route.getProxyHost();// w ww .  ja  va2s . c om
    } else {
        host = route.getTargetHost();
    }
    final Lookup<SchemeIOSessionStrategy> reg = getIOSessionFactoryRegistry(context);
    final SchemeIOSessionStrategy sf = reg.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }
    if (sf.isLayeringRequired()) {
        synchronized (managedConn) {
            final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
            final ManagedNHttpClientConnection conn = entry.getConnection();
            final IOSession ioSession = conn.getIOSession();
            final IOSession currentSession = sf.upgrade(host, ioSession);
            conn.bind(currentSession);
        }
    }
}

From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java

@Override
public void upgrade(final NHttpClientConnection managedConn, final HttpRoute route, final HttpContext context)
        throws IOException {
    Args.notNull(managedConn, "Managed connection");
    Args.notNull(route, "HTTP route");
    final HttpHost host = route.getTargetHost();
    final Lookup<SchemeIOSessionStrategy> reg = getIOSessionFactoryRegistry(context);
    final SchemeIOSessionStrategy sf = reg.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }// ww  w .j a v  a  2s  .  c  om
    if (!sf.isLayeringRequired()) {
        throw new UnsupportedSchemeException(
                host.getSchemeName() + " protocol does not support connection upgrade");
    }
    synchronized (managedConn) {
        final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
        final ManagedNHttpClientConnection conn = entry.getConnection();
        final IOSession currentSession = sf.upgrade(host, conn.getIOSession());
        conn.bind(currentSession);
    }
}