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);
}
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);
}
}
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;
}
Aggregations