use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project androidquery by androidquery.
the class AbstractAjaxCallback method httpPut.
private void httpPut(String url, Map<String, Object> params, AjaxStatus status) throws ClientProtocolException, IOException {
AQUtility.debug("put", url);
HttpEntityEnclosingRequestBase req = new HttpPut(url);
httpEntity(url, req, params, status);
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project androidquery by androidquery.
the class AbstractAjaxCallback method httpPost.
private void httpPost(String url, Map<String, Object> params, AjaxStatus status) throws ClientProtocolException, IOException {
AQUtility.debug("post", url);
HttpEntityEnclosingRequestBase req = new HttpPost(url);
httpEntity(url, req, params, status);
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project camel by apache.
the class RestletPostFormTest method testPostBody.
@Test
public void testPostBody() throws Exception {
HttpUriRequest method = new HttpPost("http://localhost:" + portNum + "/users");
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("foo", "bar"));
((HttpEntityEnclosingRequestBase) method).setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = doExecute(method);
assertHttpResponse(response, 200, "text/plain");
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project camel by apache.
the class Olingo2AppImpl method execute.
/**
* public for unit test, not to be used otherwise
*/
public void execute(HttpUriRequest httpUriRequest, ContentType contentType, FutureCallback<HttpResponse> callback) {
// add accept header when its not a form or multipart
final String contentTypeString = contentType.toString();
if (!ContentType.APPLICATION_FORM_URLENCODED.getMimeType().equals(contentType.getMimeType()) && !contentType.getMimeType().startsWith(MULTIPART_MIME_TYPE)) {
// otherwise accept what is being sent
httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentTypeString);
}
// is something being sent?
if (httpUriRequest instanceof HttpEntityEnclosingRequestBase && httpUriRequest.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) {
httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentTypeString);
}
// set user specified custom headers
if (httpHeaders != null && !httpHeaders.isEmpty()) {
for (Map.Entry<String, String> entry : httpHeaders.entrySet()) {
httpUriRequest.setHeader(entry.getKey(), entry.getValue());
}
}
// add client protocol version if not specified
if (!httpUriRequest.containsHeader(ODataHttpHeaders.DATASERVICEVERSION)) {
httpUriRequest.addHeader(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V20);
}
if (!httpUriRequest.containsHeader(MAX_DATA_SERVICE_VERSION)) {
httpUriRequest.addHeader(MAX_DATA_SERVICE_VERSION, ODataServiceVersion.V30);
}
// execute request
if (client instanceof CloseableHttpAsyncClient) {
((CloseableHttpAsyncClient) client).execute(httpUriRequest, callback);
} else {
// request synchronously
try {
CloseableHttpResponse result = ((CloseableHttpClient) client).execute(httpUriRequest);
callback.completed(result);
} catch (IOException e) {
callback.failed(e);
}
}
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project gocd by gocd.
the class RemoteRegistrationRequesterTest method hasAllParams.
private TypeSafeMatcher<HttpRequestBase> hasAllParams(final String uuid, final String elasticAgentId, final String elasticPluginId) {
return new TypeSafeMatcher<HttpRequestBase>() {
@Override
public boolean matchesSafely(HttpRequestBase item) {
try {
HttpEntityEnclosingRequestBase postMethod = (HttpEntityEnclosingRequestBase) item;
List<NameValuePair> params = URLEncodedUtils.parse(postMethod.getEntity());
assertThat(getParameter(params, "hostname"), is("cruise.com"));
assertThat(getParameter(params, "uuid"), is(uuid));
String workingDir = SystemUtil.currentWorkingDirectory();
assertThat(getParameter(params, "location"), is(workingDir));
assertThat(getParameter(params, "operatingSystem"), not(nullValue()));
assertThat(getParameter(params, "agentAutoRegisterKey"), is("t0ps3cret"));
assertThat(getParameter(params, "agentAutoRegisterResources"), is("linux, java"));
assertThat(getParameter(params, "agentAutoRegisterEnvironments"), is("uat, staging"));
assertThat(getParameter(params, "agentAutoRegisterHostname"), is("agent01.example.com"));
assertThat(getParameter(params, "elasticAgentId"), is(elasticAgentId));
assertThat(getParameter(params, "elasticPluginId"), is(elasticPluginId));
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private String getParameter(List<NameValuePair> params, String paramName) {
for (NameValuePair param : params) {
if (param.getName().equals(paramName)) {
return param.getValue();
}
}
return null;
}
public void describeTo(Description description) {
description.appendText("params containing");
}
};
}
Aggregations