Search in sources :

Example 31 with RequestBuilder

use of org.asynchttpclient.RequestBuilder in project async-http-client by AsyncHttpClient.

the class SimpleAsyncHttpClient method post.

public Future<Response> post(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws IOException {
    RequestBuilder r = rebuildRequest(requestBuilder.build());
    r.setMethod("POST");
    r.setBody(bodyGenerator);
    return execute(r, bodyConsumer, throwableHandler);
}
Also used : RequestBuilder(org.asynchttpclient.RequestBuilder)

Example 32 with RequestBuilder

use of org.asynchttpclient.RequestBuilder in project async-http-client by AsyncHttpClient.

the class SimpleAsyncHttpClient method head.

public Future<Response> head() throws IOException {
    RequestBuilder r = rebuildRequest(requestBuilder.build());
    r.setMethod("HEAD");
    return execute(r, null, null);
}
Also used : RequestBuilder(org.asynchttpclient.RequestBuilder)

Example 33 with RequestBuilder

use of org.asynchttpclient.RequestBuilder in project async-http-client by AsyncHttpClient.

the class ConnectSuccessInterceptor method exitAfterHandlingConnect.

public //
boolean exitAfterHandlingConnect(//
final Channel channel, //
final NettyResponseFuture<?> future, //
final Request request, //
ProxyServer proxyServer, //
int statusCode, HttpRequest httpRequest) throws IOException {
    if (future.isKeepAlive())
        future.attachChannel(channel, true);
    Uri requestUri = request.getUri();
    LOGGER.debug("Connecting to proxy {} for scheme {}", proxyServer, requestUri.getScheme());
    channelManager.upgradeProtocol(channel.pipeline(), requestUri);
    future.setReuseChannel(true);
    future.setConnectAllowed(false);
    requestSender.drainChannelAndExecuteNextRequest(channel, future, new RequestBuilder(future.getTargetRequest()).build());
    return true;
}
Also used : RequestBuilder(org.asynchttpclient.RequestBuilder) Uri(org.asynchttpclient.uri.Uri)

Example 34 with RequestBuilder

use of org.asynchttpclient.RequestBuilder in project camel by apache.

the class DefaultAhcBinding method prepareRequest.

public Request prepareRequest(AhcEndpoint endpoint, Exchange exchange) throws CamelExchangeException {
    if (endpoint.isBridgeEndpoint()) {
        exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
        // Need to remove the Host key as it should be not used 
        exchange.getIn().getHeaders().remove("host");
    }
    RequestBuilder builder = new RequestBuilder();
    URI uri;
    try {
        // creating the url to use takes 2-steps
        String url = AhcHelper.createURL(exchange, endpoint);
        uri = AhcHelper.createURI(exchange, url, endpoint);
        // get the url from the uri
        url = uri.toASCIIString();
        log.trace("Setting url {}", url);
        builder.setUrl(url);
    } catch (Exception e) {
        throw new CamelExchangeException("Error creating URL", exchange, e);
    }
    String method = extractMethod(exchange);
    log.trace("Setting method {}", method);
    builder.setMethod(method);
    populateHeaders(builder, endpoint, exchange);
    populateCookieHeaders(builder, endpoint, exchange, uri);
    populateBody(builder, endpoint, exchange);
    return builder.build();
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) RequestBuilder(org.asynchttpclient.RequestBuilder) URI(java.net.URI) IOException(java.io.IOException) CamelExchangeException(org.apache.camel.CamelExchangeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 35 with RequestBuilder

use of org.asynchttpclient.RequestBuilder in project async-http-client by AsyncHttpClient.

the class OAuthSignatureCalculatorTest method testPercentEncodeKeyValues.

@Test
public void testPercentEncodeKeyValues() {
    // see https://github.com/AsyncHttpClient/async-http-client/issues/1415
    String keyValue = "\u3b05\u000c\u375b";
    ConsumerKey consumer = new ConsumerKey(keyValue, "secret");
    RequestToken reqToken = new RequestToken(keyValue, "secret");
    OAuthSignatureCalculator calc = new OAuthSignatureCalculator(consumer, reqToken);
    RequestBuilder reqBuilder = new RequestBuilder().setUrl("https://api.dropbox.com/1/oauth/access_token?oauth_token=%EC%AD%AE%E3%AC%82%EC%BE%B8%E7%9C%9A%E8%BD%BD%E1%94%A5%E8%AD%AF%E8%98%93%E0%B9%99%E5%9E%96%EF%92%A2%EA%BC%97%EA%90%B0%E4%8A%91%E8%97%BF%EF%A8%BB%E5%B5%B1%DA%98%E2%90%87%E2%96%96%EE%B5%B5%E7%B9%AD%E9%AD%87%E3%BE%93%E5%AF%92%EE%BC%8F%E3%A0%B2%E8%A9%AB%E1%8B%97%EC%BF%80%EA%8F%AE%ED%87%B0%E5%97%B7%E9%97%BF%E8%BF%87%E6%81%A3%E5%BB%A1%EC%86%92%E8%92%81%E2%B9%94%EB%B6%86%E9%AE%8A%E6%94%B0%EE%AC%B5%E6%A0%99%EB%8B%AD%EB%BA%81%E7%89%9F%E5%B3%B7%EA%9D%B7%EC%A4%9C%E0%BC%BA%EB%BB%B9%ED%84%A9%E8%A5%B9%E8%AF%A0%E3%AC%85%0C%E3%9D%9B%E8%B9%8B%E6%BF%8C%EB%91%98%E7%8B%B3%E7%BB%A8%E2%A7%BB%E6%A3%84%E1%AB%B2%E8%8D%93%E4%BF%98%E9%B9%B9%EF%9A%8B%E8%A5%93");
    Request req = reqBuilder.build();
    calc.calculateAndAddSignature(req, reqBuilder);
}
Also used : RequestBuilder(org.asynchttpclient.RequestBuilder) Request(org.asynchttpclient.Request) Test(org.testng.annotations.Test)

Aggregations

RequestBuilder (org.asynchttpclient.RequestBuilder)44 Request (org.asynchttpclient.Request)18 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)17 Test (org.testng.annotations.Test)17 Response (org.asynchttpclient.Response)14 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)9 Realm (org.asynchttpclient.Realm)4 SpnegoEngineException (org.asynchttpclient.spnego.SpnegoEngineException)4 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)3 Uri (org.asynchttpclient.uri.Uri)3 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)2 HttpRequest (io.netty.handler.codec.http.HttpRequest)2 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Consumer (java.util.function.Consumer)2 Slf4j (lombok.extern.slf4j.Slf4j)2 lombok.val (lombok.val)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 REQUEST (org.asynchttpclient.extras.retrofit.AsyncHttpClientCallTest.REQUEST)2