Java Code Examples for org.eclipse.jetty.client.HttpClient#setFollowRedirects()

The following examples show how to use org.eclipse.jetty.client.HttpClient#setFollowRedirects() . 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: InjectionModule.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
private HttpClient createHttpClient() {
    //Allow ssl by default
    SslContextFactory sslContextFactory = new SslContextFactory();
    //Don't exclude RSA because Sixt needs them, dammit!
    sslContextFactory.setExcludeCipherSuites("");
    HttpClient client = new HttpClient(sslContextFactory);
    client.setFollowRedirects(false);
    client.setMaxConnectionsPerDestination(16);
    client.setRequestBufferSize(65536);
    client.setConnectTimeout(FeatureFlags.getHttpConnectTimeout(serviceProperties));
    client.setAddressResolutionTimeout(FeatureFlags.getHttpAddressResolutionTimeout(serviceProperties));
    //You can set more restrictive timeouts per request, but not less, so
    //  we set the maximum timeout of 1 hour here.
    client.setIdleTimeout(60 * 60 * 1000);
    try {
        client.start();
    } catch (Exception e) {
        logger.error("Error building http client", e);
    }
    return client;
}
 
Example 2
Source File: ServiceImpersonatorLoadBalancer.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
private HttpClient createHttpClient() {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setExcludeCipherSuites("");
    HttpClient client = new HttpClient(sslContextFactory);
    client.setFollowRedirects(false);
    client.setMaxConnectionsPerDestination(2);
    //You can set more restrictive timeouts per request, but not less, so
    //  we set the maximum timeout of 1 hour here.
    client.setIdleTimeout(60 * 60 * 1000);
    try {
        client.start();
    } catch (Exception e) {
        logger.error("Error building http client", e);
    }
    return client;
}
 
Example 3
Source File: TestInjectionModule.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
@Provides
public HttpClient getHttpClient() {
	HttpClient client = new HttpClient();
	client.setFollowRedirects(false);
	client.setMaxConnectionsPerDestination(32);
	client.setConnectTimeout(100);
	client.setAddressResolutionTimeout(100);
	//You can set more restrictive timeouts per request, but not less, so
	//  we set the maximum timeout of 1 hour here.
	client.setIdleTimeout(60 * 60 * 1000);
	try {
		client.start();
	} catch (Exception e) {
		logger.error("Error building http client", e);
	}
	return client;
}
 
Example 4
Source File: HttpOperatorFactory.java    From digdag with Apache License 2.0 6 votes vote down vote up
HttpClient client()
{
    boolean insecure = params.get("insecure", boolean.class, false);

    HttpClient httpClient = new HttpClient(new SslContextFactory(insecure));

    configureProxy(httpClient);

    boolean followRedirects = params.get("follow_redirects", boolean.class, true);

    httpClient.setFollowRedirects(followRedirects);
    httpClient.setMaxRedirects(maxRedirects);

    httpClient.setUserAgentField(new HttpField(
            USER_AGENT, userAgent + ' ' + httpClient.getUserAgentField().getValue()));

    try {
        httpClient.start();
    }
    catch (Exception e) {
        throw new TaskExecutionException(e);
    }
    return httpClient;
}
 
Example 5
Source File: JettyConnectionMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void contributesClientConnectorMetrics() throws Exception {
    HttpClient httpClient = new HttpClient();
    httpClient.setFollowRedirects(false);
    httpClient.addBean(new JettyConnectionMetrics(registry));

    CountDownLatch latch = new CountDownLatch(1);
    httpClient.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() {
        @Override
        public void lifeCycleStopped(LifeCycle event) {
            latch.countDown();
        }
    });

    httpClient.start();

    Request post = httpClient.POST("http://localhost:" + connector.getLocalPort());
    post.content(new StringContentProvider("123456"));
    post.send();
    httpClient.stop();

    assertTrue(latch.await(10, SECONDS));
    assertThat(registry.get("jetty.connections.max").gauge().value()).isEqualTo(1.0);
    assertThat(registry.get("jetty.connections.request").tag("type", "client").timer().count())
            .isEqualTo(1);
    assertThat(registry.get("jetty.connections.bytes.out").summary().totalAmount()).isGreaterThan(1);
}
 
Example 6
Source File: HttpRpcEndpoint.java    From nutzcloud with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    client = new HttpClient(new SslContextFactory(true));
    client.setFollowRedirects(false);
    client.setCookieStore(new HttpCookieStore.Empty());

    executor = new QueuedThreadPool(conf.getInt(PRE + ".maxThreads", 256));
    client.setExecutor(executor);
    client.setMaxConnectionsPerDestination(conf.getInt(PRE + ".maxConnections", 256));
    client.setIdleTimeout(conf.getLong(PRE + ".idleTimeout", 30000));

    client.setConnectTimeout(conf.getLong(PRE + ".connectTime", 1000));

    if (conf.has(PRE + "requestBufferSize"))
        client.setRequestBufferSize(conf.getInt(PRE + "requestBufferSize"));

    if (conf.has(PRE + "responseBufferSize"))
        client.setResponseBufferSize(conf.getInt(PRE + "responseBufferSize"));

    client.start();

    // Content must not be decoded, otherwise the client gets confused.
    client.getContentDecoderFactories().clear();

    // Pass traffic to the client, only intercept what's necessary.
    ProtocolHandlers protocolHandlers = client.getProtocolHandlers();
    protocolHandlers.clear();
}
 
Example 7
Source File: WebServerTest.java    From app-runner with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
    client = new HttpClient();
    client.setFollowRedirects(false);
    client.start();
    AppEstate estate = new AppEstate(proxyMap, fileSandbox(),
        new AppRunnerFactoryProvider(new ArrayList<>()));
    int port = WebServer.getAFreePort();
    webServerUrl = "http://localhost:" + port;
    SystemInfo systemInfo = SystemInfo.create();
    webServer = new WebServer(port, -1, null, null, -1, proxyMap, "test-app",
        new SystemResource(systemInfo, new AtomicBoolean(true), new ArrayList<>(), null), new AppResource(estate, systemInfo, fileSandbox()), PROXY_TIMEOUT, PROXY_TIMEOUT, "apprunner", 500 * 1024 * 1024);
    webServer.start();
    appServer = new TestServer();
}
 
Example 8
Source File: HttpCertSigner.java    From athenz with Apache License 2.0 5 votes vote down vote up
void setupHttpClient(HttpClient client, long requestTimeout, long connectTimeout) {

        client.setFollowRedirects(false);
        client.setConnectTimeout(connectTimeout);
        client.setStopTimeout(TimeUnit.MILLISECONDS.convert(requestTimeout, TimeUnit.SECONDS));
        try {
            client.start();
        } catch (Exception ex) {
            LOGGER.error("HttpCertSigner: unable to start http client", ex);
            throw new ResourceException(ResourceException.INTERNAL_SERVER_ERROR,
                    "Http client not available");
        }
    }
 
Example 9
Source File: CloudStore.java    From athenz with Apache License 2.0 5 votes vote down vote up
void setupHttpClient(HttpClient client) {

        client.setFollowRedirects(false);
        client.setStopTimeout(1000);
        try {
            client.start();
        } catch (Exception ex) {
            LOGGER.error("CloudStore: unable to start http client", ex);
            throw new ResourceException(ResourceException.INTERNAL_SERVER_ERROR,
                    "Http client not available");
        }
    }
 
Example 10
Source File: ZeppelinhubRestApiHandler.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private HttpClient getAsyncClient() {
  SslContextFactory sslContextFactory = new SslContextFactory();
  HttpClient httpClient = new HttpClient(sslContextFactory);
  // Configure HttpClient
  httpClient.setFollowRedirects(false);
  httpClient.setMaxConnectionsPerDestination(100);

  // Config considerations
  //TODO(khalid): consider multi-threaded connection manager case
  return httpClient;
}