Package com.ning.http.client

Examples of com.ning.http.client.RequestBuilder


public class APIExceptionTest {

    @Test
    public void testGetMessage() throws Exception {
        final Request request = new RequestBuilder()
                .setUrl("http://user:password@localhost:1234/some/path?query=foo#fragment")
                .build();
        final APIException apiException = new APIException(request, (Response) null);

        final String message = apiException.getMessage();
View Full Code Here


    protected void doCloseRequest() {

        ((DefaultOptions) options).b.reconnect(false);

        if (!closedByProtocol.getAndSet(true)) {
            RequestBuilder r = new RequestBuilder();
            FluentStringsMap f = new FluentStringsMap();
            f.add("X-Atmosphere-Transport", "close").add("X-Atmosphere-tracking-id", decodeQueryString(request).get("X-Atmosphere-tracking-id"));

            r.setUrl(request.uri())
                    .setMethod("GET")
                    .setHeaders(request.headers())
                    .setQueryParams(f);
            try {
                options.runtime().prepareRequest(r.build()).execute().get();
            } catch (Exception e) {
                logger.trace("", e);
            }
        }
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public Socket open(Request request, long timeout, TimeUnit tu) throws IOException {
        this.request = request;
        RequestBuilder r = new RequestBuilder();
        r.setUrl(request.uri())
                .setMethod(request.method().name())
                .setHeaders(request.headers())
                .setQueryParams(decodeQueryString(request));

        List<Transport> transports = getTransport(r, request);
View Full Code Here

            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();
        try {
            String url = AhcHelper.createURL(exchange, endpoint);
            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);
        populateBody(builder, endpoint, exchange);

        return builder.build();
    }
View Full Code Here

    }

    private Request setupHttpRequest(final ClientRequest cr, final NonCloseableOutputStream ncos, final OutputStream adaptedOutputStream) {
        URI uri = cr.getURI();
        String method = cr.getMethod();
        RequestBuilder builder = new RequestBuilder(method);
        builder.setUrl(uri.toString());

        MultivaluedMap<String, String> headers = cr.getHeaders();
        for (String header : headers.keySet()) {
            List<String> values = headers.get(header);
            for (String value : values) {
                if (value != null) {
                    builder.addHeader(header, value);
                }
            }
        }

        if (method.equalsIgnoreCase("PUT") || method.equalsIgnoreCase("POST")) {
            builder.setBody(new Request.EntityWriter()
            {
                public void writeEntity(OutputStream os) throws IOException {
                    ncos.setOutputStream(os);
                    AsyncHttpClientConnectionHandler.this.writeEntity(cr, adaptedOutputStream);
                }
            });
        }

        return builder.build();
    }
View Full Code Here

    public Request prepareRequest(AhcEndpoint endpoint, Exchange exchange) throws CamelExchangeException {
        if (endpoint.isBridgeEndpoint()) {
            exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
        }

        RequestBuilder builder = new RequestBuilder();
        try {
            String url = AhcHelper.createURL(exchange, endpoint);
            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);
        populateBody(builder, endpoint, exchange);

        return builder.build();
    }
View Full Code Here

            throw new ZenDeskException(e.getMessage(), e);
        }
    }

    private Request req(String method, String url) {
        RequestBuilder builder = new RequestBuilder(method);
        if (realm != null) {
            builder.setRealm(realm);
        }
        builder.setUrl(this.url + url);
        return builder.build();
    }
View Full Code Here

        builder.setUrl(this.url + url);
        return builder.build();
    }

    private Request jsonReq(String method, String url, String body) {
        RequestBuilder builder = new RequestBuilder(method);
        if (realm != null) {
            builder.setRealm(realm);
        }
        builder.setUrl(this.url + url);
        builder.addHeader("Content-type", "application/json");
        builder.setBody(body);
        return builder.build();
    }
View Full Code Here

        builder.setBody(body);
        return builder.build();
    }

    private Request req(String method, String url, int page) {
        RequestBuilder builder = new RequestBuilder(method);
        if (realm != null) {
            builder.setRealm(realm);
        }
        builder.addQueryParameter("page", Integer.toString(page));
        builder.setUrl(this.url + url);
        return builder.build();
    }
View Full Code Here

    Request getRequest(final ClientRequest cr) {
        final String strMethod = cr.getMethod();
        final URI uri = cr.getURI();

        RequestBuilder builder = new RequestBuilder(strMethod).setUrl(uri.toString());

        final Request.EntityWriter entity = getHttpEntity(cr);

        if(entity != null) {
            builder = builder.setBody(entity);
        }

        ProxyServer proxyServer = createProxyServer(cr);
        if(proxyServer != null)
            builder.setProxyServer(proxyServer);

        if(this.clientConfig != null) {
            if(!this.clientConfig.getPropertyAsFeature(NonBlockingClientConfig.PROPERTY_DISABLE_COOKIES)) {
                for(Cookie cookie : cookieStore.get())
                    builder = builder.addCookie(cookie);
                cookieStore.remove();
            }

            if(this.clientConfig.getPropertyAsFeature(ClientConfig.PROPERTY_FOLLOW_REDIRECTS))
                builder = builder.setFollowRedirects(true);
            else
                builder = builder.setFollowRedirects(false);
        }

        Request request = builder.build();

//        /* extremely ugly, unnecessary and inefficient. Unfortunately it is needed
//           because client side providers which modifies header values when entity is
//           being written. Ning Client writes is too late, so header is ClientRequest is
//           not yet changed and not propagated into Nings Request.
View Full Code Here

TOP

Related Classes of com.ning.http.client.RequestBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.