use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.
the class StructuredEventFilter method createResponseDetails.
private RestResponseDetails createResponseDetails(ContainerResponseContext responseContext) {
RestResponseDetails restResponse = new RestResponseDetails();
restResponse.setStatusCode(responseContext.getStatus());
restResponse.setCookies(responseContext.getCookies().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().toString())));
restResponse.setHeaders(responseContext.getHeaders().entrySet().stream().filter(e -> !skippedHeadersList.contains(e.getKey())).collect(Collectors.toMap(Entry::getKey, e -> StringUtils.join(e.getValue(), ","))));
MediaType mediaType = responseContext.getMediaType();
restResponse.setMediaType(mediaType != null ? mediaType.toString() : "");
return restResponse;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.
the class StructuredEventFilter method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
context.proceed();
if (BooleanUtils.isTrue((Boolean) context.getProperty(LOGGING_ENABLED_PROPERTY))) {
Long requestTime = (Long) context.getProperty(REQUEST_TIME);
RestRequestDetails restRequest = (RestRequestDetails) context.getProperty(REQUEST_DETAILS);
RestResponseDetails restResponse = (RestResponseDetails) context.getProperty(RESPONSE_DETAILS);
String responseBody = ((LoggingStream) context.getProperty(LOGGINGSTREAM_PROPERTY)).getStringBuilder(MessageUtils.getCharset(context.getMediaType())).toString();
Map<String, String> restParams = (Map<String, String>) context.getProperty(REST_PARAMS);
extendRestParamsFromResponse(restParams, responseBody);
sendStructuredEvent(restRequest, restResponse, restParams, requestTime, responseBody);
}
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.
the class CDPStructuredEventFilter method sendStructuredEvent.
private void sendStructuredEvent(WriterInterceptorContext context) {
Long requestTime = (Long) context.getProperty(REQUEST_TIME);
RestRequestDetails restRequest = (RestRequestDetails) context.getProperty(REQUEST_DETAILS);
RestResponseDetails restResponse = (RestResponseDetails) context.getProperty(RESPONSE_DETAILS);
String responseBody = ((LoggingStream) context.getProperty(LOGGINGSTREAM_PROPERTY)).getStringBuilder(MessageUtils.getCharset(context.getMediaType())).toString();
Map<String, String> restParams = (Map<String, String>) context.getProperty(REST_PARAMS);
if (restParams == null) {
restParams = new HashMap<>();
}
structuredEventFilterUtil.sendStructuredEvent(restRequest, restResponse, restParams, requestTime, responseBody);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.
the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheMapParameterButExistInRequestAndResponse.
@Test
public void testWhenNameAndResourceCrnComeFromTheMapParameterButExistInRequestAndResponse() {
Map<String, String> restParams = Map.of(CLUSTER_NAME, "name1", CLUSTER_CRN, "crn1");
RestCallDetails restCallDetails = new RestCallDetails();
RestRequestDetails request = new RestRequestDetails();
request.setBody(new Json(Map.of("name", "name2", "resourceCrn", "crn2")).getValue());
RestResponseDetails response = new RestResponseDetails();
response.setBody(new Json(Map.of("name", "name3", "resourceCrn", "crn3")).getValue());
restCallDetails.setRestRequest(request);
restCallDetails.setRestResponse(response);
Map<String, String> expected = new HashMap<>();
expected.put(CLUSTER_NAME, "name1");
expected.put(CLUSTER_CRN, "crn1");
Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, null, restParams, CLUSTER_NAME, CLUSTER_CRN);
assertEquals(expected, actual);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.
the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheNameOrCrnProvider.
@Test
public void testWhenNameAndResourceCrnComeFromTheNameOrCrnProvider() {
RestCallDetails restCallDetails = new RestCallDetails();
RestRequestDetails request = new RestRequestDetails();
RestResponseDetails response = new RestResponseDetails();
CDPOperationDetails operationDetails = new CDPOperationDetails();
restCallDetails.setRestRequest(request);
restCallDetails.setRestResponse(response);
Map<String, String> restParams = new HashMap<>();
restParams.put(RESOURCE_TYPE, "mock");
CustomCrnOrNameProvider customCrnOrNameProvider = mock(CustomCrnOrNameProvider.class);
customCrnOrNameProviders.put("mockCustomCrnOrNameProvider", customCrnOrNameProvider);
when(customCrnOrNameProvider.provide(restCallDetails, operationDetails, restParams, "names", "crns")).thenReturn(Map.of("crns", "pCrn", "names", "pName"));
Map<String, Object> expected = new HashMap<>();
expected.put("names", "pName");
expected.put("crns", "pCrn");
Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, operationDetails, restParams, "names", "crns");
assertEquals(expected, actual);
}
Aggregations