Search in sources :

Example 1 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project jetty.project by eclipse.

the class HttpClientTransportOverHTTP2Test method testRequestViaForwardHttpProxy.

@Test
public void testRequestViaForwardHttpProxy() throws Exception {
    String path = "/path";
    String query = "a=b";
    start(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            Assert.assertEquals(path, request.getRequestURI());
            Assert.assertEquals(query, request.getQueryString());
        }
    });
    int proxyPort = connector.getLocalPort();
    client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyPort));
    // Any port will do, just not the same as the proxy.
    int serverPort = proxyPort + 1;
    ContentResponse response = client.newRequest("localhost", serverPort).path(path + "?" + query).timeout(5, TimeUnit.SECONDS).send();
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HttpProxy(org.eclipse.jetty.client.HttpProxy) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) Test(org.junit.Test)

Example 2 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project jetty.project by eclipse.

the class ProxyServletFailureTest method prepareClient.

private HttpClient prepareClient() throws Exception {
    HttpClient result = new HttpClient();
    QueuedThreadPool executor = new QueuedThreadPool();
    executor.setName("client");
    result.setExecutor(executor);
    result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
    result.start();
    return result;
}
Also used : HttpProxy(org.eclipse.jetty.client.HttpProxy) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpClient(org.eclipse.jetty.client.HttpClient)

Example 3 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project jetty.project by eclipse.

the class ProxyServletTest method prepareClient.

private HttpClient prepareClient() throws Exception {
    QueuedThreadPool clientPool = new QueuedThreadPool();
    clientPool.setName("client");
    HttpClient result = new HttpClient();
    result.setExecutor(clientPool);
    result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
    result.start();
    return result;
}
Also used : HttpProxy(org.eclipse.jetty.client.HttpProxy) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpClient(org.eclipse.jetty.client.HttpClient)

Example 4 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project jetty.project by eclipse.

the class ForwardProxyTLSServerTest method testExternalProxy.

@Test
@Ignore("External Proxy Server no longer stable enough for testing")
public void testExternalProxy() throws Exception {
    // Free proxy server obtained from http://hidemyass.com/proxy-list/
    String proxyHost = "81.208.25.53";
    int proxyPort = 3128;
    try {
        new Socket(proxyHost, proxyPort).close();
    } catch (Throwable x) {
        Assume.assumeNoException(x);
    }
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.start();
    HttpClient httpClient = new HttpClient(newSslContextFactory());
    httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(proxyHost, proxyPort));
    httpClient.start();
    try {
        ContentResponse response = httpClient.newRequest("https://www.google.com").timeout(20, TimeUnit.SECONDS).send();
        Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
    } finally {
        httpClient.stop();
    }
}
Also used : HttpProxy(org.eclipse.jetty.client.HttpProxy) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) Socket(java.net.Socket) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project jetty.project by eclipse.

the class ForwardProxyTLSServerTest method testProxyAuthentication.

private void testProxyAuthentication(String realm, ConnectHandler connectHandler, boolean includeAddress) throws Exception {
    startTLSServer(new ServerHandler());
    startProxy(connectHandler);
    HttpClient httpClient = new HttpClient(newSslContextFactory());
    HttpProxy httpProxy = newHttpProxy();
    if (includeAddress)
        httpProxy.getIncludedAddresses().add("localhost:" + serverConnector.getLocalPort());
    httpClient.getProxyConfiguration().getProxies().add(httpProxy);
    URI uri = URI.create((proxySslContextFactory == null ? "http" : "https") + "://localhost:" + proxyConnector.getLocalPort());
    httpClient.getAuthenticationStore().addAuthentication(new BasicAuthentication(uri, realm, "proxyUser", "proxyPassword"));
    httpClient.start();
    try {
        String host = "localhost";
        String body = "BODY";
        ContentResponse response = httpClient.newRequest(host, serverConnector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).method(HttpMethod.GET).path("/echo?body=" + URLEncoder.encode(body, "UTF-8")).timeout(5, TimeUnit.SECONDS).send();
        Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
        String content = response.getContentAsString();
        Assert.assertEquals(body, content);
    } finally {
        httpClient.stop();
    }
}
Also used : HttpProxy(org.eclipse.jetty.client.HttpProxy) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication) URI(java.net.URI)

Aggregations

HttpProxy (org.eclipse.jetty.client.HttpProxy)15 HttpClient (org.eclipse.jetty.client.HttpClient)9 ProxyConfiguration (org.eclipse.jetty.client.ProxyConfiguration)6 IOException (java.io.IOException)5 BasicAuthentication (org.eclipse.jetty.client.util.BasicAuthentication)5 URI (java.net.URI)4 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)4 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)4 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)4 ExecutionException (java.util.concurrent.ExecutionException)3 Origin (org.eclipse.jetty.client.Origin)3 Socks4Proxy (org.eclipse.jetty.client.Socks4Proxy)3 DigestAuthentication (org.eclipse.jetty.client.util.DigestAuthentication)3 Test (org.junit.Test)3 TimeoutException (java.util.concurrent.TimeoutException)2 SalesforceSession (org.apache.camel.component.salesforce.internal.SalesforceSession)2 SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)2 Authentication (org.eclipse.jetty.client.api.Authentication)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1