use of org.eclipse.jetty.client.HttpClient in project athenz by yahoo.
the class CloudStoreTest method testGetMetaDataEmptyResponse.
@Test
public void testGetMetaDataEmptyResponse() throws InterruptedException, ExecutionException, TimeoutException {
CloudStore store = new CloudStore(null);
HttpClient httpClient = Mockito.mock(HttpClient.class);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(response.getStatus()).thenReturn(200);
Mockito.when(response.getContentAsString()).thenReturn("");
store.setHttpClient(httpClient);
Mockito.when(httpClient.GET("http://169.254.169.254/latest/iam-info")).thenReturn(response);
assertNull(store.getMetaData("/iam-info"));
store.close();
}
use of org.eclipse.jetty.client.HttpClient in project smarthome by eclipse.
the class SecureHttpClientFactoryTest method testGetClient.
@Test
public void testGetClient() throws Exception {
secureHttpClientFactory.activate(createConfigMap(10, 200, 60, 5, 10, 60));
HttpClient client = secureHttpClientFactory.getCommonHttpClient();
assertThat(client, is(notNullValue()));
secureHttpClientFactory.deactivate();
}
use of org.eclipse.jetty.client.HttpClient in project smarthome by eclipse.
the class FSInternetRadioHandlerJavaTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
ServletHolder holder = new ServletHolder(radioServiceDummy);
server = new TestServer(DEFAULT_CONFIG_PROPERTY_IP, DEFAULT_CONFIG_PROPERTY_PORT, TIMEOUT, holder);
setTheChannelsMap();
server.startServer();
httpClient = new HttpClient();
httpClient.start();
}
use of org.eclipse.jetty.client.HttpClient in project apache-kafka-on-k8s by banzaicloud.
the class RestClient method httpRequest.
/**
* Sends HTTP request to remote REST server
*
* @param url HTTP connection will be established with this url.
* @param method HTTP method ("GET", "POST", "PUT", etc.)
* @param requestBodyData Object to serialize as JSON and send in the request body.
* @param responseFormat Expected format of the response to the HTTP request.
* @param <T> The type of the deserialized response to the HTTP request.
* @return The deserialized response to the HTTP request, or null if no data is expected.
*/
public static <T> HttpResponse<T> httpRequest(String url, String method, Object requestBodyData, TypeReference<T> responseFormat, WorkerConfig config) {
HttpClient client;
if (url.startsWith("https://")) {
client = new HttpClient(SSLUtils.createSslContextFactory(config, true));
} else {
client = new HttpClient();
}
client.setFollowRedirects(false);
try {
client.start();
} catch (Exception e) {
log.error("Failed to start RestClient: ", e);
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR, "Failed to start RestClient: " + e.getMessage(), e);
}
try {
String serializedBody = requestBodyData == null ? null : JSON_SERDE.writeValueAsString(requestBodyData);
log.trace("Sending {} with input {} to {}", method, serializedBody, url);
Request req = client.newRequest(url);
req.method(method);
req.accept("application/json");
req.agent("kafka-connect");
if (serializedBody != null) {
req.content(new StringContentProvider(serializedBody, StandardCharsets.UTF_8), "application/json");
}
ContentResponse res = req.send();
int responseCode = res.getStatus();
log.debug("Request's response code: {}", responseCode);
if (responseCode == HttpStatus.NO_CONTENT_204) {
return new HttpResponse<>(responseCode, convertHttpFieldsToMap(res.getHeaders()), null);
} else if (responseCode >= 400) {
ErrorMessage errorMessage = JSON_SERDE.readValue(res.getContentAsString(), ErrorMessage.class);
throw new ConnectRestException(responseCode, errorMessage.errorCode(), errorMessage.message());
} else if (responseCode >= 200 && responseCode < 300) {
T result = JSON_SERDE.readValue(res.getContentAsString(), responseFormat);
return new HttpResponse<>(responseCode, convertHttpFieldsToMap(res.getHeaders()), result);
} else {
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Unexpected status code when handling forwarded request: " + responseCode);
}
} catch (IOException | InterruptedException | TimeoutException | ExecutionException e) {
log.error("IO error forwarding REST request: ", e);
throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR, "IO Error trying to forward REST request: " + e.getMessage(), e);
} finally {
if (client != null)
try {
client.stop();
} catch (Exception e) {
log.error("Failed to stop HTTP client", e);
}
}
}
use of org.eclipse.jetty.client.HttpClient in project rpki-validator-3 by RIPE-NCC.
the class BgpRisDownloader method postConstruct.
@PostConstruct
public void postConstruct() throws Exception {
httpClient = new HttpClient();
httpClient.start();
}
Aggregations