Package com.belladati.httpclientandroidlib.client.methods

Examples of com.belladati.httpclientandroidlib.client.methods.HttpPost


    return post(relativeUrl, tokenHolder, null, parameters);
  }

  public byte[] post(String relativeUrl, TokenHolder tokenHolder, HttpParameters oauthParams,
    List<? extends NameValuePair> parameters) {
    HttpPost post = new HttpPost(baseUrl + relativeUrl);
    if (parameters != null) {
      try {
        post.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));
      } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Invalid URL encoding", e);
      }
    }
    return doRequest(post, tokenHolder, oauthParams);
View Full Code Here


    }
    return doRequest(post, tokenHolder, oauthParams);
  }

  public byte[] postUpload(String relativeUrl, TokenHolder tokenHolder, String content) {
    HttpPost post = new HttpPost(baseUrl + relativeUrl);
    try {
      StringEntity entity = new StringEntity(content, "UTF-8");
      entity.setContentType("application/octet-stream");
      post.setEntity(entity);
    } catch (UnsupportedEncodingException e) {
      throw new IllegalArgumentException("Invalid URL encoding", e);
    }
    return doRequest(post, tokenHolder);
  }
View Full Code Here

            }
            if (!commsTokenAlreadyRenewed) {
                session.createCommsTokenAsRequired();
            }

            HttpPost httpRequest = requestBuilder.build(session);
            try {
                JsonNode jsonNode = executeRequest(httpRequest);

                // Handle fault codes from the API
                GroovesharkException exception = mapGroovesharkFaultCodeToException(jsonNode);
                if (exception != null) {
                    if (exception instanceof GroovesharkException.InvalidSessionException) {
                        // Attempt to renew session and retry
                        if (sessionAlreadyRenewed) {
                            throw new GroovesharkException.ServerErrorException(
                                    "Failed with invalid session. Renewed session still invalid.");
                        } else {
                            createSession();
                            sessionAlreadyRenewed = true;
                            continue;
                        }
                    } else if (exception instanceof GroovesharkException.InvalidCommsTokenException) {
                        // Attempt to renew token and retry
                        if (commsTokenAlreadyRenewed) {
                            throw new GroovesharkException.ServerErrorException(
                                    "Failed with invalid comms token. Renewed token also invalid.");
                        } else {
                            session.createCommsToken();
                            commsTokenAlreadyRenewed = true;
                            continue;
                        }
                    } else {
                        // The exception can't be handled internally
                        throw exception;
                    }
                }

                return jsonNode;
            } finally {
                // Finished with connection at this point, so make it reuseable
                httpRequest.reset();
            }
        }
    }
View Full Code Here

            rootNode.put("parameters", parameters);
        }

        // Build and send request
        String url = "https://" + Client.DOMAIN + "/more.php#" + method;
        HttpPost httpRequest = new HttpPost(url);
        httpRequest.setEntity(new StringEntity(rootNode.toString()));
        HttpResponse httpResponse = client.getHttpClient().execute(httpRequest);
        String payload = CharStreams.toString(new InputStreamReader(httpResponse.getEntity()
                .getContent(), Charsets.UTF_8));

        // Parse response JSON
View Full Code Here

            }
        }

        // Build request object
        String url = (secure ? "https" : "http") + "://" + Client.DOMAIN + "/more.php#" + method;
        HttpPost httpRequest = new HttpPost(url);
        httpRequest.setEntity(new StringEntity(rootNode.toString(), Charsets.UTF_8));
        return httpRequest;
    }
View Full Code Here

TOP

Related Classes of com.belladati.httpclientandroidlib.client.methods.HttpPost

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.