use of org.slf4j.event.Level.TRACE in project mockserver by mock-server.
the class HttpRequestsPropertiesMatcher method apply.
@VisibleForTesting
public boolean apply(RequestDefinition requestDefinition, List<LogEntry> logEntries) {
OpenAPIDefinition openAPIDefinition = requestDefinition instanceof OpenAPIDefinition ? (OpenAPIDefinition) requestDefinition : null;
if (this.openAPIDefinition == null || !this.openAPIDefinition.equals(openAPIDefinition)) {
this.openAPIDefinition = openAPIDefinition;
if (openAPIDefinition != null && isNotBlank(openAPIDefinition.getSpecUrlOrPayload())) {
httpRequestPropertiesMatchers = new ArrayList<>();
httpRequests = new ArrayList<>();
OpenAPISerialiser openAPISerialiser = new OpenAPISerialiser(mockServerLogger);
try {
OpenAPI openAPI = buildOpenAPI(openAPIDefinition.getSpecUrlOrPayload(), mockServerLogger);
try {
final Map<String, List<Pair<String, Operation>>> stringListMap = openAPISerialiser.retrieveOperations(openAPI, openAPIDefinition.getOperationId());
stringListMap.forEach((path, operations) -> operations.forEach(methodOperationPair -> {
Operation operation = methodOperationPair.getValue();
if (operation.getRequestBody() != null && operation.getRequestBody().getContent() != null) {
operation.getRequestBody().getContent().forEach(handleRequestBody(openAPIDefinition, openAPI, path, methodOperationPair, Boolean.TRUE.equals(operation.getRequestBody().getRequired()), logEntries));
} else {
HttpRequest httpRequest = createHttpRequest(openAPIDefinition, openAPI, path, methodOperationPair);
try {
addRequestMatcher(openAPIDefinition, methodOperationPair, httpRequest, "");
} catch (Throwable throwable) {
logEntries.add(new LogEntry().setLogLevel(ERROR).setMessageFormat("exception while creating adding request matcher for operation:{}method:{}in open api:{}").setArguments(methodOperationPair.getRight().getOperationId(), methodOperationPair.getLeft(), openAPIDefinition));
}
}
}));
} catch (Throwable throwable) {
logEntries.add(new LogEntry().setLogLevel(ERROR).setMessageFormat((StringUtils.isBlank(throwable.getMessage()) || !throwable.getMessage().contains(OPEN_API_LOAD_ERROR) ? OPEN_API_LOAD_ERROR + (isNotBlank(throwable.getMessage()) ? ", " : "") : "") + throwable.getMessage() + " for open api:{}").setArguments(openAPIDefinition));
}
} catch (Throwable throwable) {
String message = (StringUtils.isBlank(throwable.getMessage()) || !throwable.getMessage().contains(OPEN_API_LOAD_ERROR) ? OPEN_API_LOAD_ERROR + (isNotBlank(throwable.getMessage()) ? ", " : "") : "") + throwable.getMessage();
throw new IllegalArgumentException(message, throwable);
}
logEntries.forEach(mockServerLogger::logEvent);
}
this.hashCode = 0;
if (MockServerLogger.isEnabled(TRACE)) {
mockServerLogger.logEvent(new LogEntry().setLogLevel(TRACE).setHttpRequest(requestDefinition).setMessageFormat("created request matcher{}for open api definition{}").setArguments(this, requestDefinition));
}
return true;
} else {
return false;
}
}
Aggregations