Search in sources :

Example 66 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project cloudstack by apache.

the class HttpUriRequestBuilderTest method testBuildRequestWithParameters.

@Test
public void testBuildRequestWithParameters() throws Exception {
    final HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("key1", "value1");
    final HttpUriRequest request = HttpUriRequestBuilder.create().method(HttpMethods.GET).path("/path").parameters(parameters).build();
    assertThat(request, notNullValue());
    assertThat(request.getURI().getPath(), equalTo("/path"));
    assertThat(request.getURI().getQuery(), equalTo("key1=value1"));
    assertThat(request.getURI().getScheme(), nullValue());
    assertThat(request.getURI().getHost(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 67 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project asterixdb by apache.

the class TestExecutor method executeJSONGet.

public InputStream executeJSONGet(OutputFormat fmt, URI uri) throws Exception {
    HttpUriRequest request = constructGetMethod(uri, fmt, new ArrayList<>());
    HttpResponse response = executeAndCheckHttpRequest(request);
    return response.getEntity().getContent();
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpResponse(org.apache.http.HttpResponse)

Example 68 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project asterixdb by apache.

the class TestExecutor method executeAnyAQLAsync.

// Executes AQL in either async or async-defer mode.
public InputStream executeAnyAQLAsync(String statement, boolean defer, OutputFormat fmt, URI uri, Map<String, Object> variableCtx) throws Exception {
    // Create a method instance.
    HttpUriRequest request = RequestBuilder.post(uri).addParameter("mode", defer ? "asynchronous-deferred" : "asynchronous").setEntity(new StringEntity(statement, StandardCharsets.UTF_8)).setHeader("Accept", fmt.mimeType()).build();
    String handleVar = getHandleVariable(statement);
    HttpResponse response = executeAndCheckHttpRequest(request);
    InputStream resultStream = response.getEntity().getContent();
    String resultStr = IOUtils.toString(resultStream, "UTF-8");
    ObjectNode resultJson = new ObjectMapper().readValue(resultStr, ObjectNode.class);
    final JsonNode jsonHandle = resultJson.get("handle");
    final String strHandle = jsonHandle.asText();
    if (handleVar != null) {
        variableCtx.put(handleVar, strHandle);
        return resultStream;
    }
    return null;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpResponse(org.apache.http.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 69 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project asterixdb by apache.

the class TestExecutor method constructPostMethod.

private HttpUriRequest constructPostMethod(URI uri, OutputFormat fmt, List<CompilationUnit.Parameter> params) {
    HttpUriRequest method = constructPostMethod(uri, params);
    // Set accepted output response type
    method.setHeader("Accept", fmt.mimeType());
    return method;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest)

Example 70 with HttpUriRequest

use of org.apache.http.client.methods.HttpUriRequest in project asterixdb by apache.

the class TestExecutor method executeQueryService.

protected InputStream executeQueryService(String str, OutputFormat fmt, URI uri, List<CompilationUnit.Parameter> params, boolean jsonEncoded, boolean cancellable) throws Exception {
    final List<CompilationUnit.Parameter> newParams = upsertParam(params, "format", fmt.mimeType());
    HttpUriRequest method = jsonEncoded ? constructPostMethodJson(str, uri, "statement", newParams) : constructPostMethodUrl(str, uri, "statement", newParams);
    // Set accepted output response type
    method.setHeader("Accept", OutputFormat.CLEAN_JSON.mimeType());
    HttpResponse response = executeHttpRequest(method);
    return response.getEntity().getContent();
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpResponse(org.apache.http.HttpResponse)

Aggregations

HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)185 Test (org.junit.Test)62 TestRequest (com.android.volley.mock.TestRequest)52 HttpGet (org.apache.http.client.methods.HttpGet)45 URI (java.net.URI)43 HttpResponse (org.apache.http.HttpResponse)41 HttpEntity (org.apache.http.HttpEntity)38 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)36 HttpPost (org.apache.http.client.methods.HttpPost)22 IOException (java.io.IOException)19 Header (org.apache.http.Header)18 JSONObject (org.json.JSONObject)18 BufferedReader (java.io.BufferedReader)17 InputStreamReader (java.io.InputStreamReader)17 PrintWriter (java.io.PrintWriter)17 StringWriter (java.io.StringWriter)17 HttpHost (org.apache.http.HttpHost)13 HttpPut (org.apache.http.client.methods.HttpPut)12 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)11 StringEntity (org.apache.http.entity.StringEntity)10