Search in sources :

Example 11 with HttpPut

use of org.apache.http.client.methods.HttpPut in project nanohttpd by NanoHttpd.

the class TestNanolets method doSomeBasicMethodTest.

@Test
public void doSomeBasicMethodTest() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet("http://localhost:9090/user/blabla");
    CloseableHttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    String string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("<html><body>User handler. Method: GET<br><h1>Uri parameters:</h1><div> Param: id&nbsp;Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
    response.close();
    HttpPost httppost = new HttpPost("http://localhost:9090/user/blabla");
    response = httpclient.execute(httppost);
    entity = response.getEntity();
    string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("<html><body>User handler. Method: POST<br><h1>Uri parameters:</h1><div> Param: id&nbsp;Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
    response.close();
    HttpPut httpgput = new HttpPut("http://localhost:9090/user/blabla");
    response = httpclient.execute(httpgput);
    entity = response.getEntity();
    string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("<html><body>User handler. Method: PUT<br><h1>Uri parameters:</h1><div> Param: id&nbsp;Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
    response.close();
    HttpDelete httpdelete = new HttpDelete("http://localhost:9090/user/blabla");
    response = httpclient.execute(httpdelete);
    entity = response.getEntity();
    string = new String(readContents(entity), "UTF-8");
    Assert.assertEquals("<html><body>User handler. Method: DELETE<br><h1>Uri parameters:</h1><div> Param: id&nbsp;Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
    response.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 12 with HttpPut

use of org.apache.http.client.methods.HttpPut in project OpenAttestation by OpenAttestation.

the class ApacheHttpClient method put.

public ApiResponse put(String requestURL, ApiRequest message) throws IOException, SignatureException {
    log.debug("PUT url: {}", requestURL);
    log.debug("PUT content: {}", message == null ? "(empty)" : message.content);
    HttpPut request = new HttpPut(requestURL);
    if (message != null && message.content != null) {
        request.setEntity(new StringEntity(message.content, ContentType.create(message.contentType.toString(), "UTF-8")));
    }
    HttpResponse httpResponse = httpClient.execute(request);
    ApiResponse apiResponse = readResponse(httpResponse);
    request.releaseConnection();
    return apiResponse;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut)

Example 13 with HttpPut

use of org.apache.http.client.methods.HttpPut in project openkit-android by OpenKit.

the class OKHTTPClient method putJSON.

public static void putJSON(String relativeUrl, JSONObject requestParams, AsyncHttpResponseHandler responseHandler) {
    StringEntity sEntity = getJSONString(requestParams);
    HttpPut request = new HttpPut(getAbsoluteUrl(relativeUrl));
    if (sEntity == null) {
        responseHandler.onFailure(new Throwable("JSON encoding error"), "JSON encoding error");
    } else {
        request.setEntity(sEntity);
        sign(request);
        client.put(request, "application/json", responseHandler);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpPut(org.apache.http.client.methods.HttpPut)

Example 14 with HttpPut

use of org.apache.http.client.methods.HttpPut in project FastDev4Android by jiangqqlmj.

the class HttpClientStackTest method createPutRequest.

@Test
public void createPutRequest() throws Exception {
    TestRequest.Put request = new TestRequest.Put();
    assertEquals(request.getMethod(), Method.PUT);
    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpPut);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpPut(org.apache.http.client.methods.HttpPut) HttpPut(org.apache.http.client.methods.HttpPut) TestRequest(com.android.volley.mock.TestRequest) Test(org.junit.Test)

Example 15 with HttpPut

use of org.apache.http.client.methods.HttpPut in project FastDev4Android by jiangqqlmj.

the class HttpClientStackTest method createPutRequestWithBody.

@Test
public void createPutRequestWithBody() throws Exception {
    TestRequest.PutWithBody request = new TestRequest.PutWithBody();
    assertEquals(request.getMethod(), Method.PUT);
    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpPut);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpPut(org.apache.http.client.methods.HttpPut) TestRequest(com.android.volley.mock.TestRequest) Test(org.junit.Test)

Aggregations

HttpPut (org.apache.http.client.methods.HttpPut)153 StringEntity (org.apache.http.entity.StringEntity)89 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)50 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)40 HttpResponse (org.apache.http.HttpResponse)29 Test (org.junit.Test)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)27 Deployment (org.activiti.engine.test.Deployment)27 HttpPost (org.apache.http.client.methods.HttpPost)19 HttpGet (org.apache.http.client.methods.HttpGet)17 IOException (java.io.IOException)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HttpDelete (org.apache.http.client.methods.HttpDelete)14 HttpEntity (org.apache.http.HttpEntity)13 URI (java.net.URI)12 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)12 HttpHead (org.apache.http.client.methods.HttpHead)11 Execution (org.activiti.engine.runtime.Execution)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)9