Package org.apache.http.client.fluent

Examples of org.apache.http.client.fluent.Request


    private void deliverPackage(Executor executor, ReplicationPackage replicationPackage,
                                ReplicationEndpoint replicationEndpoint) throws IOException {
        String type = replicationPackage.getType();


        Request req = Request.Post(replicationEndpoint.getUri()).useExpectContinue();

        if (useCustomHeaders) {
            String[] customizedHeaders = getCustomizedHeaders(customHeaders, replicationPackage.getAction(), replicationPackage.getPaths());
            for (String header : customizedHeaders) {
                addHeader(req, header);
            }
        }

        InputStream inputStream = null;
        Response response = null;
        try {
            if (useCustomBody) {
                String body = customBody == null ? "" : customBody;
                inputStream = new ByteArrayInputStream(body.getBytes("UTF-8"));
            } else {
                inputStream = replicationPackage.createInputStream();
            }

            req = req.bodyStream(inputStream, ContentType.APPLICATION_OCTET_STREAM);

            response = executor.execute(req);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
View Full Code Here


            TransportAuthenticationContext context = new TransportAuthenticationContext();
            context.addAttribute("endpoint", replicationEndpoint);
            executor = transportAuthenticationProvider.authenticate(executor, context);

            Request req = Request.Post(replicationEndpoint.getUri()).useExpectContinue();

            InputStream inputStream = null;
            Response response = null;
            try {

                inputStream = replicationPackage.createInputStream();

                req = req.bodyStream(inputStream, ContentType.APPLICATION_OCTET_STREAM);
                response = executor.execute(req);
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
View Full Code Here

            Executor executor = Executor.newInstance();
            TransportAuthenticationContext context = new TransportAuthenticationContext();
            context.addAttribute("endpoint", replicationEndpoint);
            executor = transportAuthenticationProvider.authenticate(executor, context);

            Request req = Request.Post(replicationURI).useExpectContinue();

            // TODO : add queue parameter

            // continuously requests package streams as long as type header is received with the response (meaning there's a package of a certain type)
            HttpResponse httpResponse;
View Full Code Here

   */
  public byte[] send(final String host, final String port,
      final String proxyhost, final String proxyport, final byte[] bytes)
      throws ExecutionException {
    try {
      final Request request = Request.Post("http://" + host + ":" + port)
          .socketTimeout(0).connectTimeout(0);
      if (proxyhost != null && proxyport != null) {
        request.viaProxy(new HttpHost(proxyhost, Integer.valueOf(proxyport)));
      }
      final HttpResponse response = request
          .addHeader(Version.HEADER, Version.getCurrentVersion().toString())
          .bodyByteArray(bytes).execute().returnResponse();
      return handleResponse(response);
    } catch (final Exception e) {
      if (e instanceof SmallerException) {
View Full Code Here

  private <E, T> T sendRequestToOrion(E ctxElement, String path,
      Class<T> responseClazz) {
    String jsonEntity = gson.toJson(ctxElement);
    log.debug("Send request to Orion: {}", jsonEntity);

    Request req = Request.Post(orionAddr.toString() + path)
        .addHeader("Accept", APPLICATION_JSON.getMimeType())
        .bodyString(jsonEntity, APPLICATION_JSON).connectTimeout(5000)
        .socketTimeout(5000);
    Response response;
    try {
      response = req.execute();
    } catch (IOException e) {
      throw new OrionConnectorException("Could not execute HTTP request",
          e);
    }
View Full Code Here

    public HttpResponse getResponse(String url) throws IOException {
        return EXECUTOR.execute(Request.Get(url)).returnResponse();
    }

    public String getWithHeader(String url, ImmutableMap<String, String> headers) throws IOException {
        Request request = Request.Get(url);
        for (Map.Entry<String, String> entry : headers.entrySet()) {
            request = request.addHeader(entry.getKey(), entry.getValue());
        }

        return get(request);
    }
View Full Code Here

    }

    // curl -i -X GET -H "X-Parse-Application-Id: z8NmDvVsa7WPBpqsQGXtrqZRyVlokCNoEb40BdOE" -H "X-Parse-REST-API-Key: m1KOhmEbRcPlCkvGHiPKN71Y2H1zPeXZnACaB9H6"  "https://api.parse.com/1/classes/token_states?where={"state": "23456"} "
    TokenCodeState readTokenState(String requestUuid) throws IOException {
        final URI read = tokenStatesUri(requestUuid);
        final Request request = parseConfiguration.configureRequest(Request.Get(read));
        final TokenCodeState tokenCode = request.execute().handleResponse(new ResponseHandler<TokenCodeState>() {

            @Override
            public TokenCodeState handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                final TokenCodeState tokenCode;
                if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
View Full Code Here

                tokenUri.addParameter(TOKEN_PARAMETER_CLIENT_SECRET, clientSecret);
                tokenUri.addParameter(TOKEN_PARAMETER_CODE, scopeContext.getAuthenticationCode());
                tokenUri.addParameter(TOKEN_PARAMETER_GRANT_TYPE, TOKEN_PARAMETER_GRANT_TYPE_VALUE);
                tokenUri.addParameter(TOKEN_PARAMETER_REDIRECT_URI, scopeContext.getRedirectUri().toString());

                final Request request;

                try {
                    request = Request.Post(tokenUriString)
                        .bodyString(tokenUri.build().getQuery(), ContentType.APPLICATION_FORM_URLENCODED)
                        ;
                } catch (URISyntaxException e) {
                    throw new RuntimeException("Bad authorization URL for provided client and callback.", e);
                }

                final TokenServiceResponse token;
                final Response response;
                try {
                    response = request.execute();
                    final String responseContent = response.returnContent().asString();

                    token = mapper.readValue(responseContent, TokenServiceResponse.class);
                } catch (JsonParseException e) {
                    throw new RuntimeException("Infusionsoft's protocol seemingly has changed.  Invalid Token service response.", e);
View Full Code Here

TOP

Related Classes of org.apache.http.client.fluent.Request

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.