Java Code Examples for org.apache.http.entity.ContentType#APPLICATION_FORM_URLENCODED

The following examples show how to use org.apache.http.entity.ContentType#APPLICATION_FORM_URLENCODED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpRequestBuilderTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void buildPostWithContentAndContentType() throws HttpRequestBuildException, IOException
{
    ContentType contentType = ContentType.APPLICATION_FORM_URLENCODED;
    HttpRequestBase request = builder.withHttpMethod(HttpMethod.POST).withEndpoint(ENDPOINT)
            .withContent(CONTENT, contentType).build();
    assertRequestWithContent(request, HttpMethod.POST.name(), ENDPOINT, CONTENT);
    String expectedContentType = contentType.getMimeType() + "; charset=" + contentType.getCharset();
    assertEquals(expectedContentType,
            ((HttpEntityEnclosingRequestBase) request).getEntity().getContentType().getValue());
}
 
Example 2
Source File: BasicRequest.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
BasicResponse postForm(SwarmConfig config, String path, Map<String, Object> form)
        throws IOException, UnauthorizedAccessException {
    final String url = toUrl(config, path, null);
    final HttpPost request = new HttpPost(url);
    final HttpEntity entity = new StringEntity(toFormBody(form), ContentType.APPLICATION_FORM_URLENCODED);
    request.setEntity(entity);
    return request(config, request);
}
 
Example 3
Source File: Client.java    From moip-sdk-java-le with MIT License 5 votes vote down vote up
private String getBody(Object object, ContentType contentType) {
    if (contentType == ContentType.APPLICATION_FORM_URLENCODED) {
        return jsonToUrlEncodedString((JsonObject) new JsonParser().parse(gson.toJson(object)));
    }

    return gson.toJson(object);
}
 
Example 4
Source File: FakeAOSmithWaterHeater.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
private void pollServer() {	   
   Timer oldTimer = timerRef.getAndSet(null);
   if (oldTimer != null) {
      oldTimer.cancel();
   }
   HttpClientBuilder builder = HttpClientBuilder.create();
   builder.setSslcontext(sslContext);
	CloseableHttpClient httpClient = builder.build();
	
	boolean fastPoll = false;
	try {
		StringEntity entity = new StringEntity(buildPayload(), ContentType.APPLICATION_FORM_URLENCODED);
		HttpUriRequest pollingMsg = RequestBuilder.post()
				.setUri(uri)
				.setEntity(entity)
				.build();
		CloseableHttpResponse response = httpClient.execute(pollingMsg);
		try {
			HttpEntity stuff = response.getEntity();
			String thing = EntityUtils.toString(stuff);
			System.out.println("####\n#### RESPONSE " + response.getStatusLine());
			System.out.println("####\n    Response Message: " + thing + "\n####");
			
			fastPoll = applyResults(thing);
		}
		finally {
			response.close();
		}
	}
	catch(Exception ex) {
		ex.printStackTrace();
	}
	finally {
		try {
			httpClient.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	   timerRef.set(new Timer());
		if (fastPoll) {
		   System.out.println("####\n#### Schedule Fast Poll: " + FAST_POLL + "s" + "\n####");
		   timerRef.get().schedule(new PollServerTask(), FAST_POLL * 1000);
		}
		else {
		   int pollingInterval = Integer.valueOf(state.get(AosConstants.AOS_PARAM_UPDATERATE));
		   System.out.println("####\n#### Schedule Standard Poll: " + pollingInterval + "s" + "\n####");
		   timerRef.get().schedule(new PollServerTask(), pollingInterval * 1000);
		}
	}
}