Examples of HttpPost


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

    assertEquals("The client has no permisssion for client credentials", response.get("error_description"));
  }

  private InputStream performClientCredentialTokenPost(String username, String password) throws IOException {
    String tokenUrl = String.format("%s/oauth2/token", baseUrl());
    final HttpPost tokenRequest = new HttpPost(tokenUrl);
    String postBody = String.format("grant_type=%s", OAuth2Validator.GRANT_TYPE_CLIENT_CREDENTIALS );

    tokenRequest.setEntity(new ByteArrayEntity(postBody.getBytes()));
    tokenRequest.addHeader("Authorization", authorizationBasic(username, password));
    tokenRequest.addHeader("Content-Type", "application/x-www-form-urlencoded");

    HttpResponse tokenHttpResponse = new DefaultHttpClient().execute(tokenRequest);
    return tokenHttpResponse.getEntity().getContent();
  }
View Full Code Here

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

  private static Map<String, Object> postJSON(String url, String body, Integer connectionTimeout, Integer soTimeout)
  {
    Map<String, Object> map;
    try
    {
      HttpPost httppost = new HttpPost(url);
      if (body != null)
      {
        httppost.setHeader("Content-Type", "application/json;charset=UTF-8");
        httppost.setEntity(new StringEntity(body, "UTF-8"));
      }
      map = executeMethod(httppost, url, body, connectionTimeout, soTimeout);
    }
    catch (UnsupportedEncodingException e)
    {
View Full Code Here

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

  private static Map<String, Object> postJSON(String url, String body, Integer connectionTimeout, Integer soTimeout)
  {
    Map<String, Object> map;
    try
    {
      HttpPost httppost = new HttpPost(url);
      if (body != null)
      {
        httppost.setHeader("Content-Type", "application/json;charset=UTF-8");
        httppost.setEntity(new StringEntity(body, "UTF-8"));
      }
      map = executeMethod(httppost, url, body, connectionTimeout, soTimeout);
    }
    catch (UnsupportedEncodingException e)
    {
View Full Code Here

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

   */
  private static Map<String, Object> postNoJSON(String url, String body, Integer connectionTimeout, Integer soTimeout){
    Map<String, Object> map;
    try
    {
      HttpPost httppost = new HttpPost(url);
      if (body != null)
      {
        httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
        httppost.setEntity(new StringEntity(body, "UTF-8"));
      }
      map = executeMethod(httppost, url, body, connectionTimeout, soTimeout);
    }
    catch (UnsupportedEncodingException e)
    {
View Full Code Here

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

public class ProviderClient
{
  public static Map<String, Object> post(String url, Map<String, Object> body, Integer connectionTimeout, Integer soTimeout) throws Exception
  {
    HttpClient client = getHttpClient(url, connectionTimeout, soTimeout);
    HttpPost httppost = new HttpPost(url);
    List<NameValuePair> formParams = setParams(httppost, body);
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, "UTF-8");
    httppost.setEntity(entity);
    long t1 = System.currentTimeMillis();
    HttpResponse response = client.execute(httppost);
    long t2 = System.currentTimeMillis();
    NewRelic.addCustomParameter(System.currentTimeMillis()+"--"+url, (t2 - t1) + " ms");
    HttpEntity resEntity = response.getEntity();
View Full Code Here

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

  public static Map<String, Object> post(String url, String body, Integer connectionTimeout, Integer soTimeout)
  {
    Map<String, Object> map;
    try
    {
      HttpPost httppost = new HttpPost(url);
      if (body != null)
      {
        httppost.setHeader("Content-Type", "application/json;charset=UTF-8");
        httppost.setEntity(new StringEntity(body, "UTF-8"));
      }
      map = executeMethod(httppost, url, body, connectionTimeout, soTimeout);
    }
    catch (UnsupportedEncodingException e)
    {
View Full Code Here

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

            matcher.find();
            String value = matcher.group(1);

            String serverName = extractServerNameFromUri(uri);
            uri = uri.replace(serverName, "localhost");
            HttpPost httpPost = new HttpPost(uri);
            if (!serverName.equals("localhost")) {
                httpPost.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(serverName, 8080));
            }
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            formparams.add(new BasicNameValuePair(name, value));
            UrlEncodedFormEntity entity;
            try {
                entity = new UrlEncodedFormEntity(formparams, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
            httpPost.setEntity(entity);
            request = httpPost;
        } else if (responseType == ResponseType.SAML_MESSAGE_REDIRECT_BOUND) {
            String location = response.getFirstHeader("Location").getValue();
            log.info("Received redirect to " + location);
            String serverName = extractServerNameFromUri(location);
View Full Code Here

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

        } catch (JsonProcessingException e) {
            LOG.error("Telemetry is activated but sending failed.", e);
            return;
        }

        final HttpPost post;
        try {
            post = new HttpPost(new URIBuilder(configuration.getTelemetryServiceUri()).build());
            post.setHeader("User-Agent", "graylog2-server");
            post.setHeader("Content-Type", "application/json");
            post.setHeader("Content-Encoding", "gzip");
            post.setEntity(postBody);

            final RequestConfig.Builder configBuilder = RequestConfig.custom()
                    .setConnectTimeout(configuration.getTelemetryServiceConnectTimeOut())
                    .setSocketTimeout(configuration.getTelemetryServiceSocketTimeOut())
                    .setConnectionRequestTimeout(configuration.getTelemetryServiceConnectionRequestTimeOut());

            if (configuration.getHttpProxyUri() != null) {
                try {
                    final URIBuilder uriBuilder = new URIBuilder(configuration.getHttpProxyUri());
                    final URI proxyURI = uriBuilder.build();

                    configBuilder.setProxy(new HttpHost(proxyURI.getHost(), proxyURI.getPort(), proxyURI.getScheme()));
                } catch (Exception e) {
                    LOG.error("Invalid telemetry service proxy URI: {}", configuration.getHttpProxyUri(), e);
                    return;
                }
            }

            post.setConfig(configBuilder.build());
        } catch (URISyntaxException e) {
            LOG.error("Invalid telemetry service endpoint URI.", e);
            return;
        }
View Full Code Here

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

    private HttpResponse uploadMultiPart(String path,
            Map<String, String> reqParams, InputStream ins, String fileName)
            throws Exception {
        Charset utf8 = Charset.availableCharsets().get("UTF-8");
        MultipartEntity reqEntity = new MultipartEntity();
        HttpPost httppost = new HttpPost(getRequestBuilder().buildUrl(path));
        if (reqParams != null) {
            for (Map.Entry<String, String> entry : reqParams.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                reqEntity.addPart(key, new StringBody(value, utf8));
            }
        }
        if (ins != null) {
            ContentBody contentBody = new InputStreamBody(ins, fileName);
            reqEntity.addPart(fileName, contentBody);
        }
        httppost.setEntity(reqEntity);
        HttpResponse response = getRequestExecutor().execute(
            getRequestBuilder().buildOtherRequest(httppost).withCredentials(
                getServerUsername(), getServerPassword())).getResponse();

        int status = response.getStatusLine().getStatusCode();
View Full Code Here

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

    @Override
    public <T> void create(Edm edm, String resourcePath, Object data, Olingo2ResponseHandler<T> responseHandler) {
        final UriInfoImpl uriInfo = parseUri(edm, resourcePath, null);

        writeContent(edm, new HttpPost(createUri(resourcePath, null)), uriInfo, data, responseHandler);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.