use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class StructuredEventFilter method createRequestDetails.
private RestRequestDetails createRequestDetails(ContainerRequestContext requestContext, String body) {
RestRequestDetails restRequest = new RestRequestDetails();
restRequest.setRequestUri(requestContext.getUriInfo().getRequestUri().toString());
restRequest.setBody(body);
restRequest.setCookies(requestContext.getCookies().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().toString())));
restRequest.setHeaders(requestContext.getHeaders().entrySet().stream().filter(e -> !skippedHeadersList.contains(e.getKey())).collect(Collectors.toMap(Entry::getKey, e -> StringUtils.join(e.getValue(), ","))));
MediaType mediaType = requestContext.getMediaType();
restRequest.setMediaType(mediaType != null ? mediaType.toString() : "");
restRequest.setMethod(requestContext.getMethod());
return restRequest;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails 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.RestRequestDetails in project cloudbreak by hortonworks.
the class CDPRestCommonService method collectCrnAndNameIfPresent.
public Map<String, String> collectCrnAndNameIfPresent(RestCallDetails restCallDetails, CDPOperationDetails operationDetails, Map<String, String> restParams, String nameField, String crnField) {
Map<String, String> params = new HashMap<>();
RestRequestDetails restRequest = restCallDetails.getRestRequest();
Json requestJson = getJson(restRequest.getBody());
Json responseJson = getJson(restCallDetails.getRestResponse().getBody());
Map<String, String> copyRestParams = new HashMap<>(restParams);
copyRestParams.putAll(collectFromCrnOrNameProvider(restCallDetails, operationDetails, restParams, nameField, crnField));
String resourceCrn = getCrn(requestJson, responseJson, operationDetails, copyRestParams, crnField);
String name = getName(requestJson, responseJson, operationDetails, copyRestParams, nameField);
checkNameOrCrnProvided(restRequest, resourceCrn, name);
addNameAndCrnIfNotEmpty(nameField, crnField, params, resourceCrn, name);
return params;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails 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.RestRequestDetails in project cloudbreak by hortonworks.
the class RestEventFilterRelatedObjectFactory method createRequestDetails.
public RestRequestDetails createRequestDetails(ContainerRequestContext requestContext, String body) {
LOGGER.debug("Request body length: {}", body.length());
RestRequestDetails restRequest = new RestRequestDetails();
restRequest.setRequestUri(requestContext.getUriInfo().getRequestUri().toString());
restRequest.setBody(body);
restRequest.setCookies(convertCookies(requestContext));
restRequest.setHeaders(convertHeaders(requestContext));
restRequest.setMediaType(getMediaType(requestContext.getMediaType()));
restRequest.setMethod(requestContext.getMethod());
return restRequest;
}
Aggregations