Search in sources :

Example 81 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project undertow by undertow-io.

the class SimpleConfidentialRedirectTestCase method simpleRedirectTestCase.

@Test
public void simpleRedirectTestCase() throws IOException, GeneralSecurityException {
    TestHttpClient client = new TestHttpClient();
    // create our own context to force http-request.config
    // notice that, if we just create http context, the config is ovewritten before request is sent
    // if we add the config to the HttpClient instead, it is ignored
    HttpContext httpContext = new BasicHttpContext() {

        private final RequestConfig config = RequestConfig.copy(RequestConfig.DEFAULT).setNormalizeUri(false).build();

        @Override
        public void setAttribute(final String id, final Object obj) {
            if ("http.request-config".equals(id))
                return;
            super.setAttribute(id, obj);
        }

        @Override
        public Object getAttribute(final String id) {
            if ("http.request-config".equals(id))
                return config;
            return super.getAttribute(id);
        }
    };
    client.setSSLContext(DefaultServer.getClientSSLContext());
    try {
        sendRequest(client, httpContext, "/foo", null);
        sendRequest(client, httpContext, "/foo+bar", null);
        sendRequest(client, httpContext, "/foo+bar;aa", null);
        sendRequest(client, httpContext, "/foo+bar;aa", "x=y");
        sendRequest(client, httpContext, "/foo+bar%3Aaa", "x=%3Ablah");
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) HttpString(io.undertow.util.HttpString) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 82 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project stanbol by apache.

the class RequestExecutor method execute.

/**
 * Executes a {@link Request} using this executor. <p>
 * Note that this cleans up all data of the previous executed request.
 * @param r the request to execute
 * @return this
 * @throws ClientProtocolException
 * @throws IOException
 */
public RequestExecutor execute(Request r) throws ClientProtocolException, IOException {
    clear();
    request = r.getRequest();
    RequestConfig rc = RequestConfig.custom().setRedirectsEnabled(r.getRedirects()).setRelativeRedirectsAllowed(true).build();
    request.setConfig(rc);
    // Execute request
    response = httpClient.execute(request);
    entity = response.getEntity();
    if (entity != null) {
        // We fully read the content every time, not super efficient but
        // how can we read it on demand while avoiding a (boring) cleanup()
        // method on this class?
        content = EntityUtils.toByteArray(entity);
        contentType = ContentType.getOrDefault(entity);
        charset = contentType.getCharset();
        contentString = new String(content, charset != null ? charset : HTTP.DEF_CONTENT_CHARSET);
        // and close the stream
        entity.getContent().close();
    }
    return this;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig)

Example 83 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project stanbol by apache.

the class MultiThreadedTestBase method initialiseHttpClient.

@Before
public void initialiseHttpClient() {
    if (this.pooledHttpClient == null) {
        // init for the first test
        RequestConfig requestConfig = RequestConfig.custom().setRedirectsEnabled(true).setMaxRedirects(3).build();
        SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).build();
        connectionManager = new PoolingHttpClientConnectionManager();
        connectionManager.setDefaultSocketConfig(socketConfig);
        connectionManager.setMaxTotal(20);
        connectionManager.setDefaultMaxPerRoute(20);
        pooledHttpClient = HttpClientBuilder.create().setUserAgent("Stanbol Integration Test").setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig).build();
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) SocketConfig(org.apache.http.config.SocketConfig) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Before(org.junit.Before)

Example 84 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project zm-mailbox by Zimbra.

the class ZimbraAuthToken method encode.

@Override
public void encode(HttpClientBuilder clientBuilder, HttpRequestBase method, boolean isAdminReq, String cookieDomain) throws ServiceException {
    String origAuthData = AuthTokenUtil.getOrigAuthData(this);
    BasicCookieStore state = new BasicCookieStore();
    BasicClientCookie cookie = new BasicClientCookie(ZimbraCookie.authTokenCookieName(isAdminReq), origAuthData);
    cookie.setDomain(cookieDomain);
    cookie.setPath("/");
    cookie.setSecure(false);
    state.addCookie(cookie);
    clientBuilder.setDefaultCookieStore(state);
    RequestConfig reqConfig = RequestConfig.copy(ZimbraHttpConnectionManager.getInternalHttpConnMgr().getZimbraConnMgrParams().getReqConfig()).setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
    clientBuilder.setDefaultRequestConfig(reqConfig);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie)

Example 85 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project zm-mailbox by Zimbra.

the class ZimbraAuthToken method encode.

@Override
public void encode(HttpClient client, HttpRequestBase method, boolean isAdminReq, String cookieDomain) throws ServiceException {
    String origAuthData = AuthTokenUtil.getOrigAuthData(this);
    BasicCookieStore state = new BasicCookieStore();
    BasicClientCookie cookie = new BasicClientCookie(ZimbraCookie.authTokenCookieName(isAdminReq), origAuthData);
    cookie.setDomain(cookieDomain);
    cookie.setPath("/");
    cookie.setSecure(false);
    state.addCookie(cookie);
    HttpClientBuilder clientBuilder = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
    clientBuilder.setDefaultCookieStore(state);
    RequestConfig reqConfig = RequestConfig.copy(ZimbraHttpConnectionManager.getInternalHttpConnMgr().getZimbraConnMgrParams().getReqConfig()).setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
    clientBuilder.setDefaultRequestConfig(reqConfig);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder)

Aggregations

RequestConfig (org.apache.http.client.config.RequestConfig)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)146 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)97 HttpGet (org.apache.http.client.methods.HttpGet)94 IOException (java.io.IOException)78 HttpEntity (org.apache.http.HttpEntity)67 HttpPost (org.apache.http.client.methods.HttpPost)65 HttpResponse (org.apache.http.HttpResponse)60 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)55 URI (java.net.URI)46 StringEntity (org.apache.http.entity.StringEntity)43 Map (java.util.Map)41 Test (org.junit.Test)41 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)33 HttpHost (org.apache.http.HttpHost)32 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)32 HttpClient (org.apache.http.client.HttpClient)31 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)27 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)24 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)24