From 659e6759aa8d37bb78276000c2fc21da79ae5e24 Mon Sep 17 00:00:00 2001 From: mosidev Date: Sun, 26 Nov 2023 23:30:23 +0330 Subject: [PATCH] [enhancement] reduce logs on certificate loading --- .../http/core/certificate/CertificateLoader.java | 13 ++++++------- .../http/starter/impl/feign/CustomErrorDecoder.java | 13 +++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/certificate/CertificateLoader.java b/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/certificate/CertificateLoader.java index 76289a0..4438a8a 100644 --- a/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/certificate/CertificateLoader.java +++ b/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/certificate/CertificateLoader.java @@ -23,7 +23,6 @@ * @since 1/22/2021 */ public class CertificateLoader { - private static final Logger LOGGER = LoggerFactory.getLogger(CertificateLoader.class); private CertificateLoader() { @@ -76,7 +75,7 @@ public static SSLContext buildSSLContext(HttpClientProperties.SSLConfiguration s public static TrustManagerFactory getTrustManagerFactory(HttpClientProperties.SSLConfiguration sslConfiguration) { HttpClientProperties.TruststoreConfiguration truststoreConfiguration = sslConfiguration.getTruststore(); if (StringUtils.isAnyBlank(truststoreConfiguration.getPath(), truststoreConfiguration.getPassword())) { - LOGGER.warn("Truststore Configuration incomplete, skipping"); + LOGGER.debug("Truststore Configuration incomplete, skipping"); return null; } @@ -85,7 +84,7 @@ public static TrustManagerFactory getTrustManagerFactory(HttpClientProperties.SS keyStore.load(is, truststoreConfiguration.getPassword().toCharArray()); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(keyStore); - LOGGER.info("Truststore initialized successfully"); + LOGGER.debug("Truststore initialized successfully"); return tmf; } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException ex) { LOGGER.error("Truststore could not be loaded, skipping", ex); @@ -100,7 +99,7 @@ public static TrustManagerFactory getTrustManagerFactory(HttpClientProperties.SS public static KeyManagerFactory getKeyManagerFactory(HttpClientProperties.SSLConfiguration sslConfiguration) { HttpClientProperties.KeystoreConfiguration keystoreConfiguration = sslConfiguration.getKeystore(); if (StringUtils.isAnyBlank(keystoreConfiguration.getPath(), keystoreConfiguration.getPassword())) { - LOGGER.warn("Keystore Configuration incomplete, skipping"); + LOGGER.debug("Keystore Configuration incomplete, skipping"); return null; } try (FileInputStream is = new FileInputStream(ResourceUtils.getFile(keystoreConfiguration.getPath()))) { @@ -109,7 +108,7 @@ public static KeyManagerFactory getKeyManagerFactory(HttpClientProperties.SSLCon KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(keyStore, keystoreConfiguration.getPassword().toCharArray()); - LOGGER.info("Keystore initialized successfully"); + LOGGER.debug("Keystore initialized successfully"); return kmf; } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | UnrecoverableKeyException ex) { LOGGER.error("Keystore could not be loaded, skipping", ex); @@ -129,13 +128,13 @@ public static KeyStore getTrustStore(HttpClientProperties.SSLConfiguration sslCo private static KeyStore getStore(String path, String password, String type) { if (StringUtils.isAnyBlank(path, password)) { - LOGGER.warn("Keystore Configuration incomplete, skipping"); + LOGGER.debug("Keystore Configuration incomplete, skipping"); return null; } try (FileInputStream is = new FileInputStream(ResourceUtils.getFile(path))) { KeyStore keyStore = KeyStore.getInstance(type); keyStore.load(is, password.toCharArray()); - LOGGER.info("Keystore initialized successfully"); + LOGGER.debug("Keystore initialized successfully"); return keyStore; } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException ex) { LOGGER.error("Keystore could not be loaded, skipping", ex); diff --git a/tosan-httpclient-spring-boot-starter/src/main/java/com/tosan/client/http/starter/impl/feign/CustomErrorDecoder.java b/tosan-httpclient-spring-boot-starter/src/main/java/com/tosan/client/http/starter/impl/feign/CustomErrorDecoder.java index a8ac137..796c0f5 100644 --- a/tosan-httpclient-spring-boot-starter/src/main/java/com/tosan/client/http/starter/impl/feign/CustomErrorDecoder.java +++ b/tosan-httpclient-spring-boot-starter/src/main/java/com/tosan/client/http/starter/impl/feign/CustomErrorDecoder.java @@ -48,14 +48,14 @@ public Exception decode(String methodKey, Response response) { StreamUtils.copy(body.asInputStream(), output); String responseBody = output.toString(); int status = response.status(); - LOGGER.info("ServerErrorResponse :\n ResponseStatus:{}\n ResponseBody:{}", status, - responseBody); + LOGGER.info("ServerErrorResponse :\n ResponseStatus:{}\n ResponseBody:{}", status, responseBody); Map> exceptionMap = customErrorDecoderConfig.getExceptionMap(); if (status >= 400 && status < 500) { return extractBadRequestErrorException(responseBody, exceptionMap); } return extractInternalServerErrorException(responseBody, status, exceptionMap); } catch (Exception e) { + LOGGER.error("ServerInternalRuntimeException", e); return extractCustomErrorDecoderException(e); } } @@ -77,7 +77,6 @@ protected Exception extractBadRequestErrorException(String responseBody, } protected Exception extractCustomErrorDecoderException(Exception e) { - LOGGER.warn("ServerInternalRuntimeException", e); InternalServerException internalServerException = new InternalServerException("Internal error", e); internalServerException.setErrorType("customErrorDecoder"); internalServerException.setErrorCode(e.getClass().getSimpleName()); @@ -108,7 +107,6 @@ protected Exception extractInternalServerErrorException(String responseBody, int @Override public void afterPropertiesSet() { ExceptionExtractType exceptionExtractType; - if (customErrorDecoderConfig != null) { if (customErrorDecoderConfig.getObjectMapper() != null) { objectMapper = customErrorDecoderConfig.getObjectMapper(); @@ -141,11 +139,11 @@ public void afterPropertiesSet() { } } - protected T jsonToObject(String string, Class type) { + protected T jsonToObject(String string, Class type) { try { return objectMapper.readValue(string, type); } catch (Exception e) { - throw new JsonConvertException("error in converting Json to object"); + throw new JsonConvertException("error in converting Json to object", e); } } @@ -168,8 +166,7 @@ private void extractAndFillMap(Class type) { exceptionMap.put(exceptionKey, type); } catch (IllegalAccessException | NoSuchMethodException | InstantiationException | InvocationTargetException e) { - LOGGER.warn("error on construction of {}.", type.getSimpleName()); - LOGGER.warn("Exception:", e); + LOGGER.error("error on construction of " + type.getSimpleName(), e); } } else if (exceptionExtractType.equals(ExceptionExtractType.FULL_NAME_REFLECTION)) { exceptionMap.put(type.getName(), type);