static void closeQuietly(final AutoCloseable closeable) { try { if (closeable != null) { closeable.close(); } } catch (final Exception e) { SphereInternalLogger.getLogger("io").error(() -> "Error on closing resource.", e); } } }
static void closeQuietly(final AutoCloseable closeable) { try { if (closeable != null) { closeable.close(); } } catch (final Exception e) { SphereInternalLogger.getLogger(AutoCloseableService.class).error(() -> "Error on closing resource.", e); } } }
static void closeQuietly(final AutoCloseable closeable) { try { if (closeable != null) { closeable.close(); } } catch (final Exception e) { SphereInternalLogger.getLogger("io").error(() -> "Error on closing resource.", e); } } }
static void closeQuietly(final AutoCloseable closeable) { try { if (closeable != null) { closeable.close(); } } catch (final Exception e) { SphereInternalLogger.getLogger(AutoCloseableService.class).error(() -> "Error on closing resource.", e); } } }
private void log(final Supplier<Object> message) { SphereInternalLogger.getLogger(this.getClass()).trace(message); }
public static SphereInternalLogger getLogger(final HttpResponse response) { final String firstPathElement = Optional.ofNullable(response.getAssociatedRequest()) .map(r -> getPathElement(r)).orElse("endpoint-unknown"); final String lastPathElement = Optional.ofNullable(response.getAssociatedRequest()) .map(r -> requestOrCommandScopeSegment(r)).orElse("execution-type-unknown"); return getLogger(firstPathElement + ".responses." + lastPathElement); }
public final Optional<JsonNode> getJsonBody() { final Function<byte[], JsonNode> f = body -> JsonUtils.readTree(body); try { return httpResponse.flatMap(r -> r.getResponseBody().map(f)); } catch (final Exception e) { SphereInternalLogger.getLogger(SphereServiceException.class).error(() -> "Cannot provide JSON body.", e); return Optional.empty(); } } }
protected void delete(T item) { try { execute(deleteCommand(item)); } catch (final Exception e) { getLogger("test.fixtures").warn(() -> String.format("tried to delete %s but an Exception occurred: %s", item, e.toString())); } }
public static SphereInternalLogger getLogger(final HttpResponse response) { final String firstPathElement = response.getAssociatedRequest() .map(r -> getFirstPathElement(r)).orElse("endpoint-unknown"); final String lastPathElement = response.getAssociatedRequest() .map(r -> requestOrCommandScopeSegment(r.getHttpMethod())).orElse("execution-type-unknown"); return getLogger(firstPathElement + ".responses." + lastPathElement); }
public static SphereInternalLogger getLogger(final HttpResponse response) { final String firstPathElement = response.getAssociatedRequest() .map(r -> getPathElement(r)).orElse("endpoint-unknown"); final String lastPathElement = response.getAssociatedRequest() .map(r -> requestOrCommandScopeSegment(r.getHttpMethod())).orElse("execution-type-unknown"); return getLogger(firstPathElement + ".responses." + lastPathElement); }
protected void delete(T item) { try { client().execute(deleteCommand(item)); } catch (final Exception e) { getLogger("test.fixtures").warn(() -> String.format("tried to delete %s but an Exception occurred: %s", item, e.toString())); } }
public static SphereInternalLogger getLogger(final HttpRequest httpRequest) { final HttpMethod httpMethod = httpRequest.getHttpMethod(); return getLogger(getPathElement(httpRequest) + ".requests." + requestOrCommandScopeSegment(httpMethod)); }
private static <T> T processHttpResponse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse) { final SphereInternalLogger logger = getLogger(httpResponse); logger.debug(() -> httpResponse); logger.trace(() -> httpResponse.getStatusCode() + "\n" + Optional.ofNullable(httpResponse.getResponseBody()).map(body -> SphereJsonUtils.prettyPrint(bytesToString(body))).orElse("No body present.") + "\n"); final List<String> notices = httpResponse.getHeaders().getHeadersAsMap().get(SphereHttpHeaders.X_DEPRECATION_NOTICE); if (notices != null) { notices.stream().forEach(message -> logger.warn(() -> "Deprecation notice : " + message)); } return parse(sphereRequest, objectMapper, config, httpResponse); }
private static <T> T processHttpResponse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse, final HttpRequest httpRequest) { final SphereInternalLogger logger = getLogger(httpResponse); logger.debug(() -> httpResponse); logger.trace(() -> httpResponse.getStatusCode() + "\n" + Optional.ofNullable(httpResponse.getResponseBody()).map(body -> SphereJsonUtils.prettyPrint(bytesToString(body))).orElse("No body present.")); final List<String> notices = httpResponse.getHeaders().getHeadersAsMap().get(SphereHttpHeaders.X_DEPRECATION_NOTICE); if (notices != null) { notices.forEach(message -> logger.warn(() -> "Deprecation notice : " + message)); } return parse(sphereRequest, objectMapper, config, httpResponse, httpRequest); }
static <T> Function<HttpResponse, T> preProcess(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config) { return httpResponse -> { final SphereInternalLogger logger = getLogger(httpResponse); logger.debug(() -> httpResponse); logger.trace(() -> httpResponse.getStatusCode() + "\n" + httpResponse.getResponseBody().map(body -> JsonUtils.prettyPrintJsonStringSecure(bytesToString(body))).orElse("No body present.") + "\n"); final List<String> notices = httpResponse.getHeaders().getHeadersAsMap().get(SphereHttpHeaders.X_DEPRECATION_NOTICE); if (notices != null) { notices.stream().forEach(message -> logger.warn(() -> "Deprecation notice : " + message)); } return parse(httpResponse, sphereRequest, objectMapper, config); }; }
private static <T> T processHttpResponse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse, final HttpRequest httpRequest) { final SphereInternalLogger logger = getLogger(httpResponse); logger.debug(() -> httpResponse); logger.trace(() -> httpResponse.getStatusCode() + "\n" + Optional.ofNullable(httpResponse.getResponseBody()).map(body -> SphereJsonUtils.prettyPrint(bytesToString(body))).orElse("No body present.")); final List<String> notices = httpResponse.getHeaders().getHeadersAsMap().get(SphereHttpHeaders.X_DEPRECATION_NOTICE); if (notices != null) { notices.forEach(message -> logger.warn(() -> "Deprecation notice : " + message)); } return parse(sphereRequest, objectMapper, config, httpResponse, httpRequest); }
public static SphereInternalLogger getLogger(final Requestable requestable) { final HttpRequest httpRequest = requestable.httpRequest(); final HttpMethod httpMethod = httpRequest.getHttpMethod(); return getLogger(getFirstPathElement(httpRequest) + ".requests." + requestOrCommandScopeSegment(httpMethod)); }
@Override public <T> CompletableFuture<T> execute(final ClientRequest<T> clientRequest) { final SphereInternalLogger logger = getLogger(clientRequest); logger.debug(() -> clientRequest); logger.trace(() -> { final Optional<String> requestBody = clientRequest.httpRequest().getBody(); return requestBody.map(body -> JsonUtils.prettyPrintJsonStringSecure(body)).orElse("no request body present"); }); return requestExecutor. execute(clientRequest). thenApply(preProcess(clientRequest, clientRequest.resultMapper())); }
protected void delete(Product item) { try { client().executeBlocking(deleteCommand(item)); } catch (final Exception e) { getLogger("test.fixtures").warn(() -> String.format("tried to delete %s but an Exception occurred: %s", item, e.toString())); } }
public static void deleteProductType(final BlockingSphereClient client, final ProductType productType) { try { client.executeBlocking(ProductTypeDeleteCommand.of(productType)); } catch (Exception e) { getLogger("test.fixtures").debug(() -> "no product type to delete"); } }