Search in sources :

Example 6 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project Fling by entertailion.

the class RampClient method closeCurrentApp.

public void closeCurrentApp() {
    if (dialServer != null) {
        try {
            DefaultHttpClient defaultHttpClient = HttpRequestHelper.createHttpClient();
            CustomRedirectHandler handler = new CustomRedirectHandler();
            defaultHttpClient.setRedirectHandler(handler);
            BasicHttpContext localContext = new BasicHttpContext();
            // check if any app is running
            HttpGet httpGet = new HttpGet(dialServer.getAppsUrl());
            httpGet.setHeader(HEADER_CONNECTION, HEADER_CONNECTION_VALUE);
            httpGet.setHeader(HEADER_USER_AGENT, HEADER_USER_AGENT_VALUE);
            httpGet.setHeader(HEADER_ACCEPT, HEADER_ACCEPT_VALUE);
            httpGet.setHeader(HEADER_DNT, HEADER_DNT_VALUE);
            httpGet.setHeader(HEADER_ACCEPT_ENCODING, HEADER_ACCEPT_ENCODING_VALUE);
            httpGet.setHeader(HEADER_ACCEPT_LANGUAGE, HEADER_ACCEPT_LANGUAGE_VALUE);
            HttpResponse httpResponse = defaultHttpClient.execute(httpGet);
            if (httpResponse != null) {
                int responseCode = httpResponse.getStatusLine().getStatusCode();
                Log.d(LOG_TAG, "get response code=" + httpResponse.getStatusLine().getStatusCode());
                if (responseCode == 204) {
                // nothing is running
                } else if (responseCode == 200) {
                    // app is running
                    // Need to get real URL after a redirect
                    // http://stackoverflow.com/a/10286025/594751
                    String lastUrl = dialServer.getAppsUrl();
                    if (handler.lastRedirectedUri != null) {
                        lastUrl = handler.lastRedirectedUri.toString();
                        Log.d(LOG_TAG, "lastUrl=" + lastUrl);
                    }
                    String response = EntityUtils.toString(httpResponse.getEntity());
                    Log.d(LOG_TAG, "get response=" + response);
                    parseXml(new StringReader(response));
                    Header[] headers = httpResponse.getAllHeaders();
                    for (int i = 0; i < headers.length; i++) {
                        Log.d(LOG_TAG, headers[i].getName() + "=" + headers[i].getValue());
                    }
                    // stop the app instance
                    HttpDelete httpDelete = new HttpDelete(lastUrl);
                    httpResponse = defaultHttpClient.execute(httpDelete);
                    if (httpResponse != null) {
                        Log.d(LOG_TAG, "delete response code=" + httpResponse.getStatusLine().getStatusCode());
                        response = EntityUtils.toString(httpResponse.getEntity());
                        Log.d(LOG_TAG, "delete response=" + response);
                    } else {
                        Log.d(LOG_TAG, "no delete response");
                    }
                }
            } else {
                Log.i(LOG_TAG, "no get response");
                return;
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "closeCurrentApp", e);
        }
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpGet(org.apache.http.client.methods.HttpGet) StringReader(java.io.StringReader) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ProtocolException(org.apache.http.ProtocolException)

Example 7 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project android-volley by mcxiaoke.

the class HttpClientStackTest method createDeleteRequest.

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

Example 8 with HttpDelete

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

the class ApacheHttpClient method delete.

public ApiResponse delete(String requestURL) throws IOException, SignatureException {
    log.debug("DELETE url: {}", requestURL);
    HttpDelete request = new HttpDelete(requestURL);
    // send the request and print the response
    HttpResponse httpResponse = httpClient.execute(request);
    ApiResponse apiResponse = readResponse(httpResponse);
    request.releaseConnection();
    return apiResponse;
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse)

Example 9 with HttpDelete

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

the class HttpClientStackTest method createDeleteRequest.

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

Example 10 with HttpDelete

use of org.apache.http.client.methods.HttpDelete 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)

Aggregations

HttpDelete (org.apache.http.client.methods.HttpDelete)108 HttpResponse (org.apache.http.HttpResponse)25 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)22 Test (org.junit.Test)21 HttpGet (org.apache.http.client.methods.HttpGet)16 HttpPut (org.apache.http.client.methods.HttpPut)16 HttpPost (org.apache.http.client.methods.HttpPost)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)14 IOException (java.io.IOException)12 Deployment (org.activiti.engine.test.Deployment)12 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)11 Task (org.activiti.engine.task.Task)9 StringEntity (org.apache.http.entity.StringEntity)9 URI (java.net.URI)7 RequestExecutor (org.apache.stanbol.commons.testing.http.RequestExecutor)7 URISyntaxException (java.net.URISyntaxException)6 Header (org.apache.http.Header)6 HttpEntity (org.apache.http.HttpEntity)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 User (org.activiti.engine.identity.User)5