From c8c84cc1f80447622de40da7df09d217d9d37c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Hohwiller?= Date: Fri, 13 Nov 2020 17:48:38 +0100 Subject: [PATCH 1/7] update spring-boot to 2.4.0 --- .../logging/impl/ProducerLoggingListener.java | 19 ++++++++++--------- pom.xml | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/ProducerLoggingListener.java b/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/ProducerLoggingListener.java index bb066a77..ebb7ce91 100644 --- a/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/ProducerLoggingListener.java +++ b/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/ProducerLoggingListener.java @@ -1,7 +1,6 @@ package com.devonfw.module.kafka.common.messaging.logging.impl; -import java.util.Optional; - +import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,8 +11,6 @@ * * @param The key type * @param The value type - * - * */ public class ProducerLoggingListener implements ProducerListener { @@ -32,23 +29,27 @@ public ProducerLoggingListener(MessageLoggingSupport loggingSupport) { } @Override - public void onSuccess(String topic, Integer partition, Object key, Object value, RecordMetadata recordMetadata) { + public void onSuccess(ProducerRecord record, RecordMetadata recordMetadata) { - String messageKey = (String) Optional.ofNullable(key).orElse(""); + String messageKey = ""; + K key = record.key(); + if (key != null) { + messageKey = key.toString(); + } if (recordMetadata != null) { this.loggingSupport.logMessageSent(LOG, messageKey, recordMetadata.topic(), recordMetadata.partition(), recordMetadata.offset()); } else { - this.loggingSupport.logMessageSent(LOG, messageKey, topic, partition, null); + this.loggingSupport.logMessageSent(LOG, messageKey, record.topic(), record.partition(), null); } } @Override - public void onError(String topic, Integer partition, Object key, Object value, Exception exception) { + public void onError(ProducerRecord record, RecordMetadata recordMetadata, Exception exception) { - this.loggingSupport.logMessageNotSent(LOG, topic, partition, + this.loggingSupport.logMessageNotSent(LOG, record.topic(), record.partition(), (exception != null ? exception.getLocalizedMessage() : "unknown")); } } diff --git a/pom.xml b/pom.xml index 2cd21178..4c42baf6 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ devon4j develop ${revision}${changelist} - 2.3.3.RELEASE + 2.4.0 Greenwich.SR6 2.11.2 From 467a8ac483a777fe12ad37ce09c9ca77be1a9280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Hohwiller?= Date: Fri, 13 Nov 2020 18:25:59 +0100 Subject: [PATCH 2/7] WIP: update spring-boot to 2.4.0 and other updates --- boms/bom/pom.xml | 7 +------ .../logging/impl/MessageListenerLoggingAspect.java | 2 +- .../messaging/trace/impl/MessageSpanExtractor.java | 2 +- .../messaging/trace/impl/MessageSpanInjector.java | 2 +- .../example/module/MessageRetryOperationsTest.java | 9 +++++---- pom.xml | 10 ++++++---- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/boms/bom/pom.xml b/boms/bom/pom.xml index 2f41c07b..6353a8a4 100644 --- a/boms/bom/pom.xml +++ b/boms/bom/pom.xml @@ -18,11 +18,6 @@ 2014 - UTF-8 - UTF-8 - 3.3.6 - 8.7.0 - 1.7.28 bom @@ -73,7 +68,7 @@ javax.inject 1 - javax.annotation diff --git a/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/MessageListenerLoggingAspect.java b/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/MessageListenerLoggingAspect.java index 14b5bc68..1a4176ff 100644 --- a/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/MessageListenerLoggingAspect.java +++ b/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/MessageListenerLoggingAspect.java @@ -1,6 +1,6 @@ package com.devonfw.module.kafka.common.messaging.logging.impl; -import static brave.internal.HexCodec.toLowerHex; +import static brave.internal.codec.HexCodec.toLowerHex; import java.lang.reflect.Method; import java.time.Instant; diff --git a/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanExtractor.java b/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanExtractor.java index 9d863eba..c8ca82e3 100644 --- a/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanExtractor.java +++ b/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanExtractor.java @@ -1,6 +1,6 @@ package com.devonfw.module.kafka.common.messaging.trace.impl; -import static brave.internal.HexCodec.lowerHexToUnsignedLong; +import static brave.internal.codec.HexCodec.lowerHexToUnsignedLong; import static com.devonfw.module.kafka.common.messaging.util.MessageUtil.getHeaderValue; import java.util.Optional; diff --git a/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanInjector.java b/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanInjector.java index f63c763b..b924aa3b 100644 --- a/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanInjector.java +++ b/modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanInjector.java @@ -1,6 +1,6 @@ package com.devonfw.module.kafka.common.messaging.trace.impl; -import static brave.internal.HexCodec.toLowerHex; +import static brave.internal.codec.HexCodec.toLowerHex; import static com.devonfw.module.kafka.common.messaging.util.MessageUtil.addHeaderValue; import java.util.Optional; diff --git a/modules/kafka/src/test/java/com/devonfw/example/module/MessageRetryOperationsTest.java b/modules/kafka/src/test/java/com/devonfw/example/module/MessageRetryOperationsTest.java index 6fef0344..077e0b39 100644 --- a/modules/kafka/src/test/java/com/devonfw/example/module/MessageRetryOperationsTest.java +++ b/modules/kafka/src/test/java/com/devonfw/example/module/MessageRetryOperationsTest.java @@ -1,9 +1,9 @@ package com.devonfw.example.module; +import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.temporal.ChronoUnit; -import org.apache.commons.codec.Charsets; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.common.header.Headers; @@ -40,10 +40,11 @@ public class MessageRetryOperationsTest extends AbstractKafkaBaseTest { @Override protected void doSetUp() { - this.consumerRecord = new ConsumerRecord<>(AbstractKafkaBaseTest.RETRY_TEST_TOPIC, 0, 0, AbstractKafkaBaseTest.RETRY_TEST_TOPIC, "message"); + this.consumerRecord = new ConsumerRecord<>(AbstractKafkaBaseTest.RETRY_TEST_TOPIC, 0, 0, + AbstractKafkaBaseTest.RETRY_TEST_TOPIC, "message"); Headers headers = this.consumerRecord.headers(); - headers.add(MessageRetryContext.RETRY_COUNT, "0".getBytes(Charsets.UTF_8)); - headers.add(MessageRetryContext.RETRY_STATE, "Pending".getBytes(Charsets.UTF_8)); + headers.add(MessageRetryContext.RETRY_COUNT, "0".getBytes(StandardCharsets.UTF_8)); + headers.add(MessageRetryContext.RETRY_STATE, "Pending".getBytes(StandardCharsets.UTF_8)); headers.add(MessageRetryContext.RETRY_NEXT, Instant.now().plus(1, ChronoUnit.MINUTES).toString().getBytes()); headers.add(MessageRetryContext.RETRY_UNTIL, Instant.now().toString().getBytes()); diff --git a/pom.xml b/pom.xml index 4c42baf6..ee6d4fe1 100644 --- a/pom.xml +++ b/pom.xml @@ -31,11 +31,13 @@ ${revision}${changelist} 2.4.0 - Greenwich.SR6 + Hoxton.SR9 2.11.2 - 28.1-jre - 5.6.1 - + 30.0-jre + 5.7.0 + 3.4.1 + 8.7.0 + 1.7.30 From 50fbf4cb54c1a0826ca2a4fc854a1b929d090977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Hohwiller?= Date: Tue, 12 Jan 2021 10:27:38 +0100 Subject: [PATCH 3/7] #310: update spring-cloud to 2020.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5b49a995..edc85f18 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ ${revision}${changelist} 2.4.0 - Hoxton.SR9 + 2020.0.0 2.11.2 30.0-jre 5.7.0 From 30cbe34e6d5a25aceab1759e9dec8ac3b2ed49ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Hohwiller?= Date: Tue, 12 Jan 2021 11:51:02 +0100 Subject: [PATCH 4/7] #310: fix/workaround for CFX regression bug, improved error handling --- .../rest/RestServiceExceptionMapper.java | 84 ++++++++++++++++++- .../impl/client/rest/CxfRestClientTest.java | 4 +- 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java b/modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java index aa7711c8..6dad2e57 100644 --- a/modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java +++ b/modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java @@ -1,12 +1,20 @@ package com.devonfw.module.cxf.common.impl.client.rest; +import java.lang.reflect.Method; import java.net.URI; +import java.util.Map; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.ext.Provider; import org.apache.cxf.jaxrs.client.ResponseExceptionMapper; +import org.apache.cxf.jaxrs.impl.ResponseImpl; +import org.apache.cxf.jaxrs.model.OperationResourceInfo; +import org.apache.cxf.message.Message; +import org.apache.cxf.transport.Conduit; +import org.apache.cxf.ws.addressing.AttributedURIType; +import org.apache.cxf.ws.addressing.EndpointReferenceType; import com.devonfw.module.service.common.api.client.ServiceClientErrorFactory; import com.devonfw.module.service.common.api.client.context.ServiceContext; @@ -45,13 +53,83 @@ public Throwable fromResponse(Response response) { String data = response.readEntity(String.class); if ((data != null) && !data.isEmpty()) { MediaType mediaType = response.getMediaType(); - URI url = response.getLocation(); - String operation = null; - String serviceDetails = this.context.getServiceDescription(operation, url.toString()); + String url = getUrl(response); + String operation = getOperation(response); + String serviceDetails = this.context.getServiceDescription(operation, url); return this.errorUnmarshaller.unmarshall(data, mediaType.toString(), response.getStatus(), serviceDetails); } } return null; } + private String getOperation(Response response) { + + if (response instanceof ResponseImpl) { + Message message = ((ResponseImpl) response).getOutMessage(); + if (message != null) { + Object invocationContext = message.get(Message.INVOCATION_CONTEXT); + Object requestContext = getFromMap(invocationContext, "RequestContext"); + OperationResourceInfo operation = getFromMap(requestContext, OperationResourceInfo.class); + if (operation != null) { + Method method = operation.getAnnotatedMethod(); + if (method != null) { + return method.getName(); + } + } + } + } + return null; + } + + @SuppressWarnings("rawtypes") + private static Object getFromMap(Object map, Object key) { + + if (map instanceof Map) { + return ((Map) map).get(key); + } + return null; + } + + @SuppressWarnings("rawtypes") + private static T getFromMap(Object map, Class key) { + + if (map instanceof Map) { + Object value = ((Map) map).get(key.getName()); + if (value != null) { + try { + return key.cast(value); + } catch (Exception e) { + } + } + } + return null; + } + + private String getUrl(Response response) { + + URI url = response.getLocation(); + if (url != null) { + return url.toString(); + } else if (response instanceof ResponseImpl) { + Message message = ((ResponseImpl) response).getOutMessage(); + if (message != null) { + Object uri = message.get(Message.REQUEST_URI); + if (uri instanceof String) { + return (String) uri; + } + Conduit conduit = message.get(Conduit.class); + if (conduit != null) { + EndpointReferenceType target = conduit.getTarget(); + if (target != null) { + AttributedURIType address = target.getAddress(); + if (address != null) { + return address.getValue(); + } + } + } + } + } + return "url-not-available-in-cxf-response"; + } + } diff --git a/starters/starter-cxf-client-rest/src/test/java/com/devonfw/module/cxf/common/impl/client/rest/CxfRestClientTest.java b/starters/starter-cxf-client-rest/src/test/java/com/devonfw/module/cxf/common/impl/client/rest/CxfRestClientTest.java index e88a9ad2..67bec535 100644 --- a/starters/starter-cxf-client-rest/src/test/java/com/devonfw/module/cxf/common/impl/client/rest/CxfRestClientTest.java +++ b/starters/starter-cxf-client-rest/src/test/java/com/devonfw/module/cxf/common/impl/client/rest/CxfRestClientTest.java @@ -58,7 +58,7 @@ public void testBusinessError() { failBecauseExceptionWasNotThrown(ServiceInvocationFailedException.class); } catch (ServiceInvocationFailedException e) { assertThat(e.getNlsMessage().getMessage()).matches( - "While invoking the service com\\.devonfw\\.test\\.app\\.myexample\\.service\\.api\\.rest\\.MyExampleRestService\\[http://localhost:[0-9]+/app/services/rest/my-example/v1/business-error\\] the following error occurred: Test of business error.* Probably the service is temporary unavailable\\. Please try again later\\. If the problem persists contact your system administrator\\."); + "While invoking the service com\\.devonfw\\.test\\.app\\.myexample\\.service\\.api\\.rest\\.MyExampleRestService#businessError\\[http://localhost:[0-9]+/app/services/rest/my-example/v1/business-error\\] the following error occurred: Test of business error.* Probably the service is temporary unavailable\\. Please try again later\\. If the problem persists contact your system administrator\\."); assertThat(e.getCode()).isEqualTo(MyBusinessException.CODE); assertThat(e.isForUser()).isTrue(); assertThat(e.isTechnical()).isTrue(); @@ -82,7 +82,7 @@ public void testTechnicalError() { failBecauseExceptionWasNotThrown(ServiceInvocationFailedException.class); } catch (ServiceInvocationFailedException e) { assertThat(e.getNlsMessage().getMessage()).matches( - "While invoking the service com\\.devonfw\\.test\\.app\\.myexample\\.service\\.api\\.rest\\.MyExampleRestService\\[http://localhost:[0-9]+/app/services/rest/my-example/v1/technical-error\\] the following error occurred: An unexpected error has occurred! We apologize any inconvenience\\. Please try again later\\..* Probably the service is temporary unavailable\\. Please try again later\\. If the problem persists contact your system administrator\\."); + "While invoking the service com\\.devonfw\\.test\\.app\\.myexample\\.service\\.api\\.rest\\.MyExampleRestService#technicalError\\[http://localhost:[0-9]+/app/services/rest/my-example/v1/technical-error\\] the following error occurred: An unexpected error has occurred! We apologize any inconvenience\\. Please try again later\\..* Probably the service is temporary unavailable\\. Please try again later\\. If the problem persists contact your system administrator\\."); assertThat(e.getCode()).isEqualTo(TechnicalErrorUserException.CODE); assertThat(e.isForUser()).isTrue(); assertThat(e.isTechnical()).isTrue(); From 1ca34be521e282d59e469bb2a0b4ff3ab4b9f8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Hohwiller?= Date: Tue, 12 Jan 2021 11:55:43 +0100 Subject: [PATCH 5/7] #307: removed unused import to prevent warnings in fresh app from template --- .../general/service/impl/config/BaseWebSecurityConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/BaseWebSecurityConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/BaseWebSecurityConfig.java index 8f828943..06fd3396 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/BaseWebSecurityConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/BaseWebSecurityConfig.java @@ -14,7 +14,6 @@ import org.springframework.security.web.authentication.logout.LogoutFilter; import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import org.springframework.security.web.csrf.CsrfFilter; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; From 0ac5c96673b4c5c2b08ab73b93692aac41b52ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Hohwiller?= Date: Tue, 12 Jan 2021 11:59:39 +0100 Subject: [PATCH 6/7] #310: fixed warnings with generic types --- .../general/service/impl/config/WebConfig.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/WebConfig.java b/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/WebConfig.java index 1ef96539..0941bf99 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/WebConfig.java +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/WebConfig.java @@ -28,10 +28,10 @@ public class WebConfig { * with their duration and status code. */ @Bean - public FilterRegistrationBean performanceLogFilter() { + public FilterRegistrationBean performanceLogFilter() { - FilterRegistrationBean registration = new FilterRegistrationBean(); - Filter performanceLogFilter = new PerformanceLogFilter(); + FilterRegistrationBean registration = new FilterRegistrationBean<>(); + PerformanceLogFilter performanceLogFilter = new PerformanceLogFilter(); this.beanFactory.autowireBean(performanceLogFilter); registration.setFilter(performanceLogFilter); registration.addUrlPatterns("/*"); @@ -52,10 +52,10 @@ public DiagnosticContextFacade diagnosticContextFacade() { * correlation id as MDC so it will be included in all associated logs. */ @Bean - public FilterRegistrationBean diagnosticContextFilter() { + public FilterRegistrationBean diagnosticContextFilter() { - FilterRegistrationBean registration = new FilterRegistrationBean(); - Filter diagnosticContextFilter = new DiagnosticContextFilter(); + FilterRegistrationBean registration = new FilterRegistrationBean<>(); + DiagnosticContextFilter diagnosticContextFilter = new DiagnosticContextFilter(); this.beanFactory.autowireBean(diagnosticContextFilter); registration.setFilter(diagnosticContextFilter); registration.addUrlPatterns(ServiceConstants.URL_PATH_SERVICES + "/*"); @@ -66,9 +66,9 @@ public FilterRegistrationBean diagnosticContextFilter() { * @return the {@link FilterRegistrationBean} to register the {@link CharacterEncodingFilter} to set the encoding. */ @Bean - public FilterRegistrationBean setCharacterEncodingFilter() { + public FilterRegistrationBean setCharacterEncodingFilter() { - FilterRegistrationBean registration = new FilterRegistrationBean(); + FilterRegistrationBean registration = new FilterRegistrationBean<>(); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(false); From 3e94f5a8f73bd91d3655f67c392a4b457d23ffd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Hohwiller?= Date: Tue, 12 Jan 2021 20:51:49 +0100 Subject: [PATCH 7/7] #310: reworked for review feedback --- .../common/impl/client/rest/RestServiceExceptionMapper.java | 4 ++-- .../service/common/api/client/context/ServiceContext.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java b/modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java index 6dad2e57..a55fc8df 100644 --- a/modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java +++ b/modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java @@ -78,7 +78,7 @@ private String getOperation(Response response) { } } } - return null; + return ""; } @SuppressWarnings("rawtypes") @@ -129,7 +129,7 @@ private String getUrl(Response response) { } } } - return "url-not-available-in-cxf-response"; + return ""; } } diff --git a/modules/service/src/main/java/com/devonfw/module/service/common/api/client/context/ServiceContext.java b/modules/service/src/main/java/com/devonfw/module/service/common/api/client/context/ServiceContext.java index 885ec704..2d47d6f2 100644 --- a/modules/service/src/main/java/com/devonfw/module/service/common/api/client/context/ServiceContext.java +++ b/modules/service/src/main/java/com/devonfw/module/service/common/api/client/context/ServiceContext.java @@ -63,11 +63,11 @@ default String getServiceDescription(String operation) { default String getServiceDescription(String operation, String url) { StringBuilder sb = new StringBuilder(getApi().getName()); - if (operation != null) { + if ((operation != null) && !operation.isEmpty()) { sb.append('#'); sb.append(operation); } - if (url != null) { + if ((url != null) && !url.isEmpty()) { sb.append('['); sb.append(url); sb.append(']');