Search in sources :

Example 1 with UnsupportedSchemeException

use of org.apache.http.conn.UnsupportedSchemeException in project lavaplayer by sedmelluq.

the class ExtendedConnectionOperator method upgrade.

@Override
public void upgrade(ManagedHttpClientConnection connection, HttpHost host, HttpContext context) throws IOException {
    ConnectionSocketFactory socketFactory = getSocketFactory(host, HttpClientContext.adapt(context));
    if (!(socketFactory instanceof LayeredConnectionSocketFactory)) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol does not support connection upgrade");
    }
    LayeredConnectionSocketFactory layeredFactory = (LayeredConnectionSocketFactory) socketFactory;
    Socket socket = connection.getSocket();
    int port = this.schemePortResolver.resolve(host);
    socket = layeredFactory.createLayeredSocket(socket, host.getHostName(), port, context);
    connection.bind(socket);
}
Also used : LayeredConnectionSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) LayeredConnectionSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory) UnsupportedSchemeException(org.apache.http.conn.UnsupportedSchemeException) Socket(java.net.Socket)

Example 2 with UnsupportedSchemeException

use of org.apache.http.conn.UnsupportedSchemeException in project lavaplayer by sedmelluq.

the class AbstractRoutePlanner method determineRoute.

@Override
public HttpRoute determineRoute(final HttpHost host, final HttpRequest request, final HttpContext context) throws HttpException {
    Args.notNull(request, "Request");
    if (host == null) {
        throw new ProtocolException("Target host is not specified");
    }
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final RequestConfig config = clientContext.getRequestConfig();
    int remotePort;
    if (host.getPort() <= 0) {
        try {
            remotePort = schemePortResolver.resolve(host);
        } catch (final UnsupportedSchemeException e) {
            throw new HttpException(e.getMessage());
        }
    } else
        remotePort = host.getPort();
    final Tuple<Inet4Address, Inet6Address> remoteAddresses = IpAddressTools.getRandomAddressesFromHost(host);
    final Tuple<InetAddress, InetAddress> addresses = determineAddressPair(remoteAddresses);
    final HttpHost target = new HttpHost(addresses.r, host.getHostName(), remotePort, host.getSchemeName());
    final HttpHost proxy = config.getProxy();
    final boolean secure = target.getSchemeName().equalsIgnoreCase("https");
    clientContext.setAttribute(CHOSEN_IP_ATTRIBUTE, addresses.l);
    log.debug("Setting route context attribute to {}", addresses.l);
    if (proxy == null) {
        return new HttpRoute(target, addresses.l, secure);
    } else {
        return new HttpRoute(target, addresses.l, proxy, secure);
    }
}
Also used : ProtocolException(org.apache.http.ProtocolException) RequestConfig(org.apache.http.client.config.RequestConfig) Inet4Address(java.net.Inet4Address) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) Inet6Address(java.net.Inet6Address) HttpRoute(org.apache.http.conn.routing.HttpRoute) HttpHost(org.apache.http.HttpHost) UnsupportedSchemeException(org.apache.http.conn.UnsupportedSchemeException) HttpException(org.apache.http.HttpException) InetAddress(java.net.InetAddress)

Example 3 with UnsupportedSchemeException

use of org.apache.http.conn.UnsupportedSchemeException in project lavaplayer by sedmelluq.

the class ExtendedConnectionOperator method getSocketFactory.

private ConnectionSocketFactory getSocketFactory(HttpHost host, HttpContext context) throws IOException {
    Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(context);
    ConnectionSocketFactory socketFactory = registry.lookup(host.getSchemeName());
    if (socketFactory == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }
    return socketFactory;
}
Also used : LayeredConnectionSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) UnsupportedSchemeException(org.apache.http.conn.UnsupportedSchemeException)

Aggregations

UnsupportedSchemeException (org.apache.http.conn.UnsupportedSchemeException)3 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)2 LayeredConnectionSocketFactory (org.apache.http.conn.socket.LayeredConnectionSocketFactory)2 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1 Socket (java.net.Socket)1 HttpException (org.apache.http.HttpException)1 HttpHost (org.apache.http.HttpHost)1 ProtocolException (org.apache.http.ProtocolException)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)1 HttpRoute (org.apache.http.conn.routing.HttpRoute)1