Search in sources :

Example 6 with HttpEntityEnclosingRequestBase

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);
}
Also used : HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpPut(org.apache.http.client.methods.HttpPut)

Example 7 with HttpEntityEnclosingRequestBase

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase)

Example 8 with HttpEntityEnclosingRequestBase

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");
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Test(org.junit.Test)

Example 9 with HttpEntityEnclosingRequestBase

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);
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) CloseableHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with HttpEntityEnclosingRequestBase

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");
        }
    };
}
Also used : NameValuePair(org.apache.http.NameValuePair) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) List(java.util.List) IOException(java.io.IOException)

Aggregations

HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)38 HttpPost (org.apache.http.client.methods.HttpPost)17 IOException (java.io.IOException)9 HttpPut (org.apache.http.client.methods.HttpPut)9 HttpEntity (org.apache.http.HttpEntity)7 HttpResponse (org.apache.http.HttpResponse)6 InputStream (java.io.InputStream)5 Header (org.apache.http.Header)5 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)5 NameValuePair (org.apache.http.NameValuePair)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 StringEntity (org.apache.http.entity.StringEntity)4 File (java.io.File)3 HashMap (java.util.HashMap)3 HttpDelete (org.apache.http.client.methods.HttpDelete)3 HttpGet (org.apache.http.client.methods.HttpGet)3 FileEntity (org.apache.http.entity.FileEntity)3 OutputStream (java.io.OutputStream)2 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2