use of org.apache.metron.stellar.dsl.functions.RestConfig in project metron by apache.
the class RestFunctionsTest method restGetShouldThrowExceptionOnContentLengthMismatch.
@Test
public void restGetShouldThrowExceptionOnContentLengthMismatch() throws Exception {
RestFunctions.RestGet restGet = new RestFunctions.RestGet();
RestConfig restConfig = new RestConfig();
HttpGet httpGet = mock(HttpGet.class);
HttpEntity httpEntity = mock(HttpEntity.class);
restConfig.put(VERIFY_CONTENT_LENGTH, true);
when(httpGet.getURI()).thenReturn(new URI("uri"));
when(httpEntity.getContent()).thenReturn(new ByteArrayInputStream("{\"get\":\"success\"}".getBytes(StandardCharsets.UTF_8)));
when(httpEntity.getContentLength()).thenReturn(-1L);
IOException e = assertThrows(IOException.class, () -> RestFunctions.parseResponse(restConfig, httpGet, httpEntity));
assertEquals("Stellar REST request to uri returned incorrect or missing content length. Content length in the response was -1 but the actual body content length was 17.", e.getMessage());
}
use of org.apache.metron.stellar.dsl.functions.RestConfig in project metron by apache.
the class RestFunctionsTest method restShouldBuildRestConfig.
/**
* RestConfig should be built with settings in the correct order of precedence.
*/
@Test
public void restShouldBuildRestConfig() {
Map<String, Object> config = new HashMap<String, Object>() {
{
put(BASIC_AUTH_USER, "user");
put(PROXY_BASIC_AUTH_USER, "proxyUser");
}
};
Map<String, Object> priorityConfig = new HashMap<String, Object>() {
{
put(BASIC_AUTH_USER, "priorityUser");
}
};
RestConfig restConfig = RestFunctions.buildRestConfig(config, priorityConfig);
assertEquals(6, restConfig.size());
assertEquals(Collections.singletonList(200), restConfig.getResponseCodesAllowed());
assertEquals("priorityUser", restConfig.getBasicAuthUser());
assertEquals("proxyUser", restConfig.getProxyBasicAuthUser());
assertTrue(restConfig.enforceJson());
assertEquals(1000, restConfig.getTimeout().intValue());
assertFalse(restConfig.verifyContentLength());
}
use of org.apache.metron.stellar.dsl.functions.RestConfig in project metron by apache.
the class RestFunctionsTest method restGetShouldParseResponseOnNullContent.
@Test
public void restGetShouldParseResponseOnNullContent() throws Exception {
RestConfig restConfig = new RestConfig();
HttpGet httpGet = mock(HttpGet.class);
HttpEntity httpEntity = mock(HttpEntity.class);
// return empty on null content
when(httpEntity.getContent()).thenReturn(null);
assertEquals(Optional.empty(), RestFunctions.parseResponse(restConfig, httpGet, httpEntity));
}
use of org.apache.metron.stellar.dsl.functions.RestConfig in project metron by apache.
the class RestFunctionsTest method restGetShouldGetPoolingConnectionManager.
@Test
public void restGetShouldGetPoolingConnectionManager() {
RestConfig restConfig = new RestConfig();
restConfig.put(POOLING_MAX_TOTAL, 5);
restConfig.put(POOLING_DEFAULT_MAX_PER_RUOTE, 2);
PoolingHttpClientConnectionManager cm = RestFunctions.getConnectionManager(restConfig);
assertEquals(5, cm.getMaxTotal());
assertEquals(2, cm.getDefaultMaxPerRoute());
}
use of org.apache.metron.stellar.dsl.functions.RestConfig in project metron by apache.
the class RestFunctions method getHttpClient.
/**
* Retrieves the ClosableHttpClient from a pooling connection manager.
*
* @param context The execution context.
* @return A ClosableHttpClient.
*/
protected static CloseableHttpClient getHttpClient(Context context) {
RestConfig restConfig = buildRestConfig(getGlobalConfig(context));
PoolingHttpClientConnectionManager cm = getConnectionManager(restConfig);
return HttpClients.custom().setConnectionManager(cm).build();
}
Aggregations