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));
}
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();
}
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;
}
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;
}
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();
}
Aggregations