org.apache.http.conn.UnsupportedSchemeException Java Examples

The following examples show how to use org.apache.http.conn.UnsupportedSchemeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtendedConnectionOperator.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: Substitute_RestClient.java    From quarkus with Apache License 2.0 5 votes vote down vote up
protected HttpHost getKey(final HttpHost host) {
    if (host.getPort() <= 0) {
        final int port;
        try {
            port = schemePortResolver.resolve(host);
        } catch (final UnsupportedSchemeException ignore) {
            return host;
        }
        return new HttpHost(host.getHostName(), port, host.getSchemeName());
    } else {
        return host;
    }
}
 
Example #3
Source File: ExtendedConnectionOperator.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: AbstractRoutePlanner.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #5
Source File: TestWithProxiedEmbeddedServer.java    From Bastion with GNU General Public License v3.0 5 votes vote down vote up
private static DefaultSchemePortResolver prepareSchemePortResolver() {
    return new DefaultSchemePortResolver() {
        @Override
        public int resolve(HttpHost host) throws UnsupportedSchemeException {
            if (host.getHostName().equalsIgnoreCase("sushi-shop.test")) {
                return 9876;
            } else {
                return super.resolve(host);
            }
        }
    };
}
 
Example #6
Source File: VespaHttpClientBuilder.java    From vespa with Apache License 2.0 5 votes vote down vote up
private HttpHost resolveTarget(HttpHost host) throws HttpException {
    try {
        String originalScheme = host.getSchemeName();
        String scheme = originalScheme.equalsIgnoreCase("http") ? "https" : originalScheme;
        int port = DefaultSchemePortResolver.INSTANCE.resolve(host);
        return new HttpHost(host.getHostName(), port, scheme);
    } catch (UnsupportedSchemeException e) {
        throw new HttpException(e.getMessage(), e);
    }
}
 
Example #7
Source File: IntegrationTestSupertypeLayer.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Initilisation procedure for this test case.
 * 
 * @throws UnableToBuildSolRDFClientException in case the client cannot be built.
 * @throws Exception in case of Solr startup failure.
 */
@BeforeClass
public static void initITTest() {
	System.setProperty("tests.asserts", "false");	
	System.setProperty("jetty.port", "8080");
	System.setProperty("solr.core.name", "store");
	System.setProperty("solr.data.dir", initCoreDataDir.getAbsolutePath());
		
	try {
		SOLR = createJetty(
				"target/solrdf-integration-tests-1.1-dev/solrdf",
				JettyConfig.builder()
					.setPort(8080)
					.setContext("/solr")
					.stopAtShutdown(true)
					.build());		
		
		final HttpClient httpClient = HttpClientBuilder.create()
				.setRoutePlanner(
						new DefaultRoutePlanner(
								new SchemePortResolver() {
									@Override
									public int resolve(final HttpHost host) throws UnsupportedSchemeException {
										return SOLR.getLocalPort();
									}
								})).build();
		
		
		SOLRDF_CLIENT = SolRDF.newBuilder()
	              .withEndpoint("http://127.0.0.1:8080/solr/store")
	              .withGraphStoreProtocolEndpointPath("/rdf-graph-store")
	              .withHttpClient(httpClient)
	              .withSPARQLEndpointPath("/sparql")
	              .build();
		
		PLAIN_SOLR_CLIENT = new HttpSolrClient(SOLR_URI);
	} catch (final Exception exception) {
		throw new RuntimeException(exception);
	}
}