Examples of HttpPost


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

  protected InputStream sendPostRequest(String serviceURL,
      String requestBody, String contentType) {
    HttpClient httpclient = ogpHttpClient.getHttpClient();
    InputStream replyStream = null;
    try {
      HttpPost httppost = new HttpPost(serviceURL);
      logger.debug(requestBody);
      StringEntity postEntity = new StringEntity(requestBody, ContentType.create(contentType, "UTF-8"));
      httppost.setEntity(postEntity);
      logger.info("executing POST request to " + httppost.getURI());
      HttpResponse response = httpclient.execute(httppost);
      this.setStatus(response.getStatusLine().getStatusCode());
      this.setHeaders(response.getAllHeaders());
      HttpEntity entity = response.getEntity();
     
View Full Code Here

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

          foundMatch=true;
      if (!foundMatch)
        Assert.fail(String.format("Could not find request header matching: %s", header));
    }
    if(request instanceof HttpPost) {
      HttpPost post = (HttpPost)request;
      HttpEntity entity = post.getEntity();
      Parameters actualParameters = extractParameters(entity);

      String [] expectedNames = parameters.getNames();
      String [] actualNames = actualParameters.getNames();
      Arrays.sort(expectedNames);
View Full Code Here

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

    }
  }

  private void assertParameters(final HttpRequestBase request) throws ArrayComparisonFailure {
    if(request instanceof HttpPost) {
      HttpPost post = (HttpPost)request;
      HttpEntity entity = post.getEntity();
      Parameters actualParameters = extractParameters(entity);

      String [] expectedNames = parameters.getNames();
      String [] actualNames = actualParameters.getNames();
      Arrays.sort(expectedNames);
View Full Code Here

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

  }

  public <T extends Resource> T post() {
    //    HttpPost request = (!hasFiles()) || isMultiPart ? composePostRequest(getBaseUri(), parameters) :
    //      composeMultiPartFormRequest(getBaseUri(), parameters, files);
    HttpPost request = (hasFiles() || isMultiPart) ? composeMultiPartFormRequest(getBaseUri(), parameters, files) :
      composePostRequest(getBaseUri(), parameters);
    buildHeaders(request);
    return requestor.request(request);
  }
View Full Code Here

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

      throw MechanizeExceptionFactory.newException(e);
    }
  }

  private HttpPost composePostRequest(final String uri, final Parameters parameters) {
    HttpPost request = new HttpPost(uri);
    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    for(Parameter param : parameters)
      if(param.isSingleValue())
        formparams.add(new BasicNameValuePair(param.getName(), param.getValue()));
      else
        for(String value : param.getValues())
          formparams.add(new BasicNameValuePair(param.getName(), value));
    try {
      UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
      request.setEntity(entity);
    } catch (UnsupportedEncodingException e) {
      throw MechanizeExceptionFactory.newException(e);
    }

    return request;
View Full Code Here

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

    return request;
  }

  private HttpPost composeMultiPartFormRequest(final String uri, final Parameters parameters, final Map<String, ContentBody> files) {
    HttpPost request = new HttpPost(uri);
    MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

    try {
      Charset utf8 = Charset.forName("UTF-8");
      for(Parameter param : parameters)
        if(param.isSingleValue())
          multiPartEntity.addPart(param.getName(), new StringBody(param.getValue(), utf8));
        else
          for(String value : param.getValues())
            multiPartEntity.addPart(param.getName(), new StringBody(value, utf8));
    } catch (UnsupportedEncodingException e) {
      throw MechanizeExceptionFactory.newException(e);
    }

    List<String> fileNames = new ArrayList<String>(files.keySet());
    Collections.sort(fileNames);
    for(String name : fileNames) {
      ContentBody contentBody = files.get(name);
      multiPartEntity.addPart(name, contentBody);
    }
    request.setEntity(multiPartEntity);
    return request;
  }
View Full Code Here

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

  }

  @Before
  public void setUp() {
    httpClient = new DefaultHttpClient();
    postRequest = new HttpPost("http://0.0.0.0:" + selectedPort);
  }
View Full Code Here

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

    while (statusCode != HttpStatus.SC_OK && triesCount < serversList.size()) {
      triesCount++;
      String host = serversList.get();
      String url = host + "/" + BULK_ENDPOINT;
      HttpPost httpRequest = new HttpPost(url);
      httpRequest.setEntity(new StringEntity(entity));
      response = httpClient.execute(httpRequest);
      statusCode = response.getStatusLine().getStatusCode();
      logger.info("Status code from elasticsearch: " + statusCode);
      if (response.getEntity() != null)
        logger.debug("Status message from elasticsearch: " + EntityUtils.toString(response.getEntity(), "UTF-8"));
View Full Code Here

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

    assertTrue(StringUtils.isNotBlank(accessTokenResponse.getTokenType()));
    assertTrue(accessTokenResponse.getExpiresIn() > 0);

    String tokenUrl = String.format("%s/oauth2/token", baseUrl());

    final HttpPost tokenRequest = new HttpPost(tokenUrl);
   
    /*
     * Now make a request for a new AccessToken based on the refreshToken
     */
    String postBody = String.format("grant_type=%s&refresh_token=%s&state=%s",
            OAuth2Validator.GRANT_TYPE_REFRESH_TOKEN, accessTokenResponse.getRefreshToken(), "dummy");

    tokenRequest.setEntity(new ByteArrayEntity(postBody.getBytes()));
    tokenRequest.addHeader("Authorization", AuthorizationCodeTestIT.authorizationBasic(clientId, secret));

    tokenRequest.addHeader("Content-Type", "application/x-www-form-urlencoded");

    HttpResponse tokenHttpResponse = new DefaultHttpClient().execute(tokenRequest);
    final InputStream responseContent = tokenHttpResponse.getEntity().getContent();
    String responseAsString = IOUtils.toString(responseContent);

View Full Code Here

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

    Map<String, String> params = getParamsFromUri(uri);
    String authorizationCode = params.get("code");
    authorizationResponseState = params.get("state");
    LOG.debug("URL: {}, state: {}", uri, authorizationResponseState);

    final HttpPost tokenRequest = new HttpPost(oauthServerBaseUrl + "/oauth2/token");
    String postBody = getPostBody(authorizationCode, grantType);

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

    HttpResponse tokenHttpResponse = new DefaultHttpClient().execute(tokenRequest);
    final InputStream responseContent = tokenHttpResponse.getEntity().getContent();
    String responseAsString = new Scanner(responseContent).useDelimiter("\\A").next();
    responseContent.close();
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.