Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpEntityEnclosingRequestBase


                pw.println(h.getValue());
            }
        }

        if (executor.getRequest() instanceof HttpEntityEnclosingRequestBase) {
            final HttpEntityEnclosingRequestBase heb = (HttpEntityEnclosingRequestBase) executor.getRequest();
            if (heb.getEntity() != null) {
                pw.print("Content-Type:");
                pw.println(heb.getEntity().getContentType().getValue());
                pw.println("Content:");
                final InputStream is = heb.getEntity().getContent();
                final byte[] buffer = new byte[16384];
                int count = 0;
                while ((count = is.read(buffer, 0, buffer.length)) > 0) {
                    // TODO encoding??
                    pw.write(new String(buffer, 0, count));
View Full Code Here


    // Get the http host to connect to.
    HttpHost host = new HttpHost(hostparts[0], port, uri.getScheme());

    try {
      if ("POST".equals(methodType) || "PUT".equals(methodType)) {
        HttpEntityEnclosingRequestBase enclosingMethod = ("POST".equals(methodType))
          ? new HttpPost(requestUri)
          : new HttpPut(requestUri);

        if (request.getPostBodyLength() > 0) {
          enclosingMethod.setEntity(new InputStreamEntity(request.getPostBody(), request.getPostBodyLength()));
        }
        httpMethod = enclosingMethod;
      } else if ("GET".equals(methodType)) {
        httpMethod = new HttpGet(requestUri);
      } else if ("HEAD".equals(methodType)) {
View Full Code Here

    return resources;
  }

  public List<DavResource> search(String url, String language, String query) throws IOException
  {
    HttpEntityEnclosingRequestBase search = new HttpSearch(url);
    SearchRequest searchBody = new SearchRequest(language, query);
    String body = SardineUtil.toXml(searchBody);
    search.setEntity(new StringEntity(body, UTF_8));
    Multistatus multistatus = this.execute(search, new MultiStatusResponseHandler());
    List<Response> responses = multistatus.getResponse();
    List<DavResource> resources = new ArrayList<DavResource>(responses.size());
    for (Response response : responses)
    {
View Full Code Here

    try {
      type = type.split(";")[0];
      handlerFor(type).marshal(payload, writer, client);
      writer.flush();
     
      HttpEntityEnclosingRequestBase verb = (HttpEntityEnclosingRequestBase) verbFor(method, uri);
      add(verb, headers);
      String string = writer.getBuffer().toString();
      verb.setEntity(new StringEntity(string));
      return execute(details, verb);
    } catch (IOException e) {
      throw new RestfulieException("Unable to marshal entity.", e);
    }
View Full Code Here

            HttpRequestBase method, org.apache.http.HttpResponse apacheHttpResponse) throws IOException {

        int status = apacheHttpResponse.getStatusLine().getStatusCode();
        HttpResponse response = createResponse(method, request, apacheHttpResponse);
        if (errorResponseHandler.needsConnectionLeftOpen() && method instanceof HttpEntityEnclosingRequestBase) {
          HttpEntityEnclosingRequestBase entityEnclosingRequest = (HttpEntityEnclosingRequestBase)method;
            response.setContent(new HttpMethodReleaseInputStream(entityEnclosingRequest));
        }

        AmazonServiceException exception = null;
        try {
View Full Code Here

    private void writeToFile(String target, String operation, byte[] contents) throws IOException {
        String targetUrl = target == null ?
                String.format("%s?op=%s&user.name=%s", url, operation, username) :
                String.format("%s/%s?op=%s&user.name=%s", trimUrl(url), target, operation, username);
        HttpEntityEnclosingRequestBase method = getWriteMethod(operation, targetUrl);

        int responseCode;
        HttpResponse response = null;
        try {
            response = httpClient.execute(method);
            StatusLine status = response.getStatusLine();
            responseCode = response.getStatusLine().getStatusCode();
            if (responseCode != 307) {
                throw new IOException(String.format("Error returned from server. Status: %s - %s", responseCode, status.getReasonPhrase()));
            }
        } catch (IOException e) {
            method.abort();
            throw e;
        } finally {
            method.releaseConnection();
        }

        try {
            Header redirectUrl = response.getFirstHeader("Location");
            if (redirectUrl == null) {
                throw new IOException(String.format("Location header, indicating data node location, is null. Cannot continue appending to %s.", url));
            }

            method = getWriteMethod(operation, redirectUrl.getValue());
            method.setEntity(new ByteArrayEntity(contents));
            response = httpClient.execute(method);
            StatusLine status = response.getStatusLine();
            responseCode = response.getStatusLine().getStatusCode();
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                EntityUtils.consume(entity);
            }
            if (responseCode != 200 && responseCode != 201) {
                throw new IOException(String.format("Error returned from server. Status: %s - %s; %s", responseCode, status.getReasonPhrase(), readResponse(entity)));
            }
        } catch (IOException e) {
            method.abort();
            throw e;
        } finally {
            method.releaseConnection();
        }
    }
View Full Code Here

            throw new IllegalArgumentException("The method you specified is not supported.");
        }

        // Put data into the request for POST and PUT requests
        if (method.equals("POST") || method.equals("PUT")) {
            HttpEntityEnclosingRequestBase eeMethod = (HttpEntityEnclosingRequestBase) request;
            String requestBody = data instanceof JSONObject ? ((JSONObject) data).toString() :
                    new ObjectMapper().writeValueAsString(data);

            eeMethod.setEntity(new StringEntity(requestBody, MediaType.APPLICATION_JSON, "UTF-8"));
        }

        // Add the authentication token to the request
        if (authnToken != null) {
            if (type.equals(AuthTokenType.API)) {
View Full Code Here

            throw new IllegalArgumentException("The method you specified is not supported.");
        }

        // Put data into the request for POST and PUT requests
        if (method.equals("POST") || method.equals("PUT") && data != null) {
            HttpEntityEnclosingRequestBase eeMethod = (HttpEntityEnclosingRequestBase) httpMethod;

            eeMethod.setEntity(new StringEntity(data, ContentType.create(mediaType, "UTF-8")));
        }

        /* Set the username/password if any */
        if (username != null) {
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
View Full Code Here

        this.body = body;
    }

    public boolean matches(Object o) {
        if (o instanceof HttpEntityEnclosingRequestBase) {
            HttpEntityEnclosingRequestBase h = (HttpEntityEnclosingRequestBase) o;
            Header contentType = h.getEntity().getContentType();
            return contentType.getValue().toLowerCase().contains("utf-8") &&
                    h.getURI().toString().equals(url) &&
                    h.getEntity().toString().equals(body);
        }
        return false;
    }
View Full Code Here

      HttpRequestBase request;
      // first try read (GET)
      if ("GET".equals(type)) {
        request = new HttpGet(uri);
      } else { // then try write
        HttpEntityEnclosingRequestBase writeRequest;
        if ("POST".equals(type)) {
          writeRequest = new HttpPost(uri);
        } else if ("PUT".equals(type)) {
          writeRequest = new HttpPut(uri);
        } else {
          throw new IllegalArgumentException("Unsupported HttpMethod of type '" + type + "'.");
        }
        // common write parts
        HttpEntity entity = createEntity();
        writeRequest.setEntity(entity);
        request = writeRequest;
      }

      // common request parts
      Set<Entry<String, String>> entries = headers.entrySet();
View Full Code Here

TOP

Related Classes of org.apache.http.client.methods.HttpEntityEnclosingRequestBase

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.