private CloseableHttpResponse createAndExecuteRequest(final HttpMethods method, final String path, final Map<String, String> parameters, final Optional<String> jsonPayLoad) throws CloudstackRESTException { final HttpUriRequest httpRequest = HttpUriRequestBuilder.create() .path(path) .parameters(parameters) .jsonPayload(jsonPayLoad) .method(method) .build(); if (jsonPayLoad.isPresent()) { s_logger.debug("Built request '" + httpRequest + "' with payload: " + jsonPayLoad); } return executeRequest(httpRequest); }
@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)); }
private CloseableHttpResponse createAndExecuteRequest(final HttpMethods method, final String path, final Map<String, String> parameters, final Optional<String> jsonPayLoad) throws CosmicRESTException { final HttpUriRequest httpRequest = HttpUriRequestBuilder.create() .path(path) .parameters(parameters) .jsonPayload(jsonPayLoad) .method(method) .build(); if (jsonPayLoad.isPresent()) { s_logger.debug("Built request '" + httpRequest + "' with payload: " + jsonPayLoad); } return executeRequest(httpRequest); }
@Test public void testBuildRequestWithParameters() throws Exception { final HashMap<String, String> parameters = new HashMap<>(); 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)); }