Skip to content

Commit 7e3b2ff

Browse files
authored
#311: dependency updates (spring-boot 2.4.0, spring-cloud to 2020.0.0, cxf to 3.4.1, etc.) (#310)
1 parent d0c2f10 commit 7e3b2ff

File tree

12 files changed

+119
-43
lines changed

12 files changed

+119
-43
lines changed

boms/bom/pom.xml

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
<inceptionYear>2014</inceptionYear>
1919

2020
<properties>
21-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23-
<cxf.version>3.3.6</cxf.version>
24-
<mmm.util.version>8.7.0</mmm.util.version>
25-
<slf4j.version>1.7.28</slf4j.version>
2621
<flatten.mode>bom</flatten.mode>
2722
</properties>
2823

@@ -73,7 +68,7 @@
7368
<artifactId>javax.inject</artifactId>
7469
<version>1</version>
7570
</dependency>
76-
<!-- JSR 250 for common annotations (component-bean lifecycle, security,
71+
<!-- JSR 250 for common annotations (component-bean lifecycle, security,
7772
etc.) -->
7873
<dependency>
7974
<groupId>javax.annotation</groupId>

modules/cxf-client-rest/src/main/java/com/devonfw/module/cxf/common/impl/client/rest/RestServiceExceptionMapper.java

+81-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
package com.devonfw.module.cxf.common.impl.client.rest;
22

3+
import java.lang.reflect.Method;
34
import java.net.URI;
5+
import java.util.Map;
46

57
import javax.ws.rs.core.MediaType;
68
import javax.ws.rs.core.Response;
79
import javax.ws.rs.ext.Provider;
810

911
import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;
12+
import org.apache.cxf.jaxrs.impl.ResponseImpl;
13+
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
14+
import org.apache.cxf.message.Message;
15+
import org.apache.cxf.transport.Conduit;
16+
import org.apache.cxf.ws.addressing.AttributedURIType;
17+
import org.apache.cxf.ws.addressing.EndpointReferenceType;
1018

1119
import com.devonfw.module.service.common.api.client.ServiceClientErrorFactory;
1220
import com.devonfw.module.service.common.api.client.context.ServiceContext;
@@ -45,13 +53,83 @@ public Throwable fromResponse(Response response) {
4553
String data = response.readEntity(String.class);
4654
if ((data != null) && !data.isEmpty()) {
4755
MediaType mediaType = response.getMediaType();
48-
URI url = response.getLocation();
49-
String operation = null;
50-
String serviceDetails = this.context.getServiceDescription(operation, url.toString());
56+
String url = getUrl(response);
57+
String operation = getOperation(response);
58+
String serviceDetails = this.context.getServiceDescription(operation, url);
5159
return this.errorUnmarshaller.unmarshall(data, mediaType.toString(), response.getStatus(), serviceDetails);
5260
}
5361
}
5462
return null;
5563
}
5664

65+
private String getOperation(Response response) {
66+
67+
if (response instanceof ResponseImpl) {
68+
Message message = ((ResponseImpl) response).getOutMessage();
69+
if (message != null) {
70+
Object invocationContext = message.get(Message.INVOCATION_CONTEXT);
71+
Object requestContext = getFromMap(invocationContext, "RequestContext");
72+
OperationResourceInfo operation = getFromMap(requestContext, OperationResourceInfo.class);
73+
if (operation != null) {
74+
Method method = operation.getAnnotatedMethod();
75+
if (method != null) {
76+
return method.getName();
77+
}
78+
}
79+
}
80+
}
81+
return "";
82+
}
83+
84+
@SuppressWarnings("rawtypes")
85+
private static Object getFromMap(Object map, Object key) {
86+
87+
if (map instanceof Map) {
88+
return ((Map) map).get(key);
89+
}
90+
return null;
91+
}
92+
93+
@SuppressWarnings("rawtypes")
94+
private static <T> T getFromMap(Object map, Class<T> key) {
95+
96+
if (map instanceof Map) {
97+
Object value = ((Map) map).get(key.getName());
98+
if (value != null) {
99+
try {
100+
return key.cast(value);
101+
} catch (Exception e) {
102+
}
103+
}
104+
}
105+
return null;
106+
}
107+
108+
private String getUrl(Response response) {
109+
110+
URI url = response.getLocation();
111+
if (url != null) {
112+
return url.toString();
113+
} else if (response instanceof ResponseImpl) {
114+
Message message = ((ResponseImpl) response).getOutMessage();
115+
if (message != null) {
116+
Object uri = message.get(Message.REQUEST_URI);
117+
if (uri instanceof String) {
118+
return (String) uri;
119+
}
120+
Conduit conduit = message.get(Conduit.class);
121+
if (conduit != null) {
122+
EndpointReferenceType target = conduit.getTarget();
123+
if (target != null) {
124+
AttributedURIType address = target.getAddress();
125+
if (address != null) {
126+
return address.getValue();
127+
}
128+
}
129+
}
130+
}
131+
}
132+
return "";
133+
}
134+
57135
}

modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/MessageListenerLoggingAspect.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.devonfw.module.kafka.common.messaging.logging.impl;
22

3-
import static brave.internal.HexCodec.toLowerHex;
3+
import static brave.internal.codec.HexCodec.toLowerHex;
44

55
import java.lang.reflect.Method;
66
import java.time.Instant;

modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/logging/impl/ProducerLoggingListener.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.devonfw.module.kafka.common.messaging.logging.impl;
22

3-
import java.util.Optional;
4-
3+
import org.apache.kafka.clients.producer.ProducerRecord;
54
import org.apache.kafka.clients.producer.RecordMetadata;
65
import org.slf4j.Logger;
76
import org.slf4j.LoggerFactory;
@@ -12,8 +11,6 @@
1211
*
1312
* @param <K> The key type
1413
* @param <V> The value type
15-
*
16-
*
1714
*/
1815
public class ProducerLoggingListener<K, V> implements ProducerListener<K, V> {
1916

@@ -32,23 +29,27 @@ public ProducerLoggingListener(MessageLoggingSupport loggingSupport) {
3229
}
3330

3431
@Override
35-
public void onSuccess(String topic, Integer partition, Object key, Object value, RecordMetadata recordMetadata) {
32+
public void onSuccess(ProducerRecord<K, V> record, RecordMetadata recordMetadata) {
3633

37-
String messageKey = (String) Optional.ofNullable(key).orElse("<no message key>");
34+
String messageKey = "<no message key>";
35+
K key = record.key();
36+
if (key != null) {
37+
messageKey = key.toString();
38+
}
3839

3940
if (recordMetadata != null) {
4041
this.loggingSupport.logMessageSent(LOG, messageKey, recordMetadata.topic(), recordMetadata.partition(),
4142
recordMetadata.offset());
4243

4344
} else {
44-
this.loggingSupport.logMessageSent(LOG, messageKey, topic, partition, null);
45+
this.loggingSupport.logMessageSent(LOG, messageKey, record.topic(), record.partition(), null);
4546
}
4647
}
4748

4849
@Override
49-
public void onError(String topic, Integer partition, Object key, Object value, Exception exception) {
50+
public void onError(ProducerRecord<K, V> record, RecordMetadata recordMetadata, Exception exception) {
5051

51-
this.loggingSupport.logMessageNotSent(LOG, topic, partition,
52+
this.loggingSupport.logMessageNotSent(LOG, record.topic(), record.partition(),
5253
(exception != null ? exception.getLocalizedMessage() : "unknown"));
5354
}
5455
}

modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanExtractor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.devonfw.module.kafka.common.messaging.trace.impl;
22

3-
import static brave.internal.HexCodec.lowerHexToUnsignedLong;
3+
import static brave.internal.codec.HexCodec.lowerHexToUnsignedLong;
44
import static com.devonfw.module.kafka.common.messaging.util.MessageUtil.getHeaderValue;
55

66
import java.util.Optional;

modules/kafka/src/main/java/com/devonfw/module/kafka/common/messaging/trace/impl/MessageSpanInjector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.devonfw.module.kafka.common.messaging.trace.impl;
22

3-
import static brave.internal.HexCodec.toLowerHex;
3+
import static brave.internal.codec.HexCodec.toLowerHex;
44
import static com.devonfw.module.kafka.common.messaging.util.MessageUtil.addHeaderValue;
55

66
import java.util.Optional;

modules/kafka/src/test/java/com/devonfw/example/module/MessageRetryOperationsTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.devonfw.example.module;
22

3+
import java.nio.charset.StandardCharsets;
34
import java.time.Instant;
45
import java.time.temporal.ChronoUnit;
56

6-
import org.apache.commons.codec.Charsets;
77
import org.apache.kafka.clients.consumer.ConsumerRecord;
88
import org.apache.kafka.clients.producer.ProducerRecord;
99
import org.apache.kafka.common.header.Headers;
@@ -40,10 +40,11 @@ public class MessageRetryOperationsTest extends AbstractKafkaBaseTest {
4040
@Override
4141
protected void doSetUp() {
4242

43-
this.consumerRecord = new ConsumerRecord<>(AbstractKafkaBaseTest.RETRY_TEST_TOPIC, 0, 0, AbstractKafkaBaseTest.RETRY_TEST_TOPIC, "message");
43+
this.consumerRecord = new ConsumerRecord<>(AbstractKafkaBaseTest.RETRY_TEST_TOPIC, 0, 0,
44+
AbstractKafkaBaseTest.RETRY_TEST_TOPIC, "message");
4445
Headers headers = this.consumerRecord.headers();
45-
headers.add(MessageRetryContext.RETRY_COUNT, "0".getBytes(Charsets.UTF_8));
46-
headers.add(MessageRetryContext.RETRY_STATE, "Pending".getBytes(Charsets.UTF_8));
46+
headers.add(MessageRetryContext.RETRY_COUNT, "0".getBytes(StandardCharsets.UTF_8));
47+
headers.add(MessageRetryContext.RETRY_STATE, "Pending".getBytes(StandardCharsets.UTF_8));
4748
headers.add(MessageRetryContext.RETRY_NEXT, Instant.now().plus(1, ChronoUnit.MINUTES).toString().getBytes());
4849
headers.add(MessageRetryContext.RETRY_UNTIL, Instant.now().toString().getBytes());
4950

modules/service/src/main/java/com/devonfw/module/service/common/api/client/context/ServiceContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ default String getServiceDescription(String operation) {
6363
default String getServiceDescription(String operation, String url) {
6464

6565
StringBuilder sb = new StringBuilder(getApi().getName());
66-
if (operation != null) {
66+
if ((operation != null) && !operation.isEmpty()) {
6767
sb.append('#');
6868
sb.append(operation);
6969
}
70-
if (url != null) {
70+
if ((url != null) && !url.isEmpty()) {
7171
sb.append('[');
7272
sb.append(url);
7373
sb.append(']');

pom.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
<changelist>-SNAPSHOT</changelist>
2929
<github.repository>devon4j</github.repository>
3030
<devon4j.version>${revision}${changelist}</devon4j.version>
31-
<spring.boot.version>2.3.3.RELEASE</spring.boot.version>
31+
<spring.boot.version>2.4.0</spring.boot.version>
3232
<!-- Spring boot and spring cloud version has to match -->
33-
<spring.cloud.dependencies.version>Greenwich.SR6</spring.cloud.dependencies.version>
33+
<spring.cloud.dependencies.version>2020.0.0</spring.cloud.dependencies.version>
3434
<jackson.version>2.11.2</jackson.version> <!-- Overriding Jackson for fixing vulnerabilities -->
35-
<guava.version>28.1-jre</guava.version>
36-
<junit.version>5.6.1</junit.version>
37-
35+
<guava.version>30.0-jre</guava.version>
36+
<junit.version>5.7.0</junit.version>
37+
<cxf.version>3.4.1</cxf.version>
38+
<mmm.util.version>8.7.0</mmm.util.version>
39+
<slf4j.version>1.7.30</slf4j.version>
3840
</properties>
3941

4042
<build>

starters/starter-cxf-client-rest/src/test/java/com/devonfw/module/cxf/common/impl/client/rest/CxfRestClientTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testBusinessError() {
5858
failBecauseExceptionWasNotThrown(ServiceInvocationFailedException.class);
5959
} catch (ServiceInvocationFailedException e) {
6060
assertThat(e.getNlsMessage().getMessage()).matches(
61-
"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\\.");
61+
"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\\.");
6262
assertThat(e.getCode()).isEqualTo(MyBusinessException.CODE);
6363
assertThat(e.isForUser()).isTrue();
6464
assertThat(e.isTechnical()).isTrue();
@@ -82,7 +82,7 @@ public void testTechnicalError() {
8282
failBecauseExceptionWasNotThrown(ServiceInvocationFailedException.class);
8383
} catch (ServiceInvocationFailedException e) {
8484
assertThat(e.getNlsMessage().getMessage()).matches(
85-
"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\\.");
85+
"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\\.");
8686
assertThat(e.getCode()).isEqualTo(TechnicalErrorUserException.CODE);
8787
assertThat(e.isForUser()).isTrue();
8888
assertThat(e.isTechnical()).isTrue();

templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/BaseWebSecurityConfig.java

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.springframework.security.web.authentication.logout.LogoutFilter;
1515
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
1616
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
17-
import org.springframework.security.web.csrf.CsrfFilter;
1817
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
1918
import org.springframework.web.cors.CorsConfiguration;
2019
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

templates/server/src/main/resources/archetype-resources/core/src/main/java/__packageInPathFormat__/general/service/impl/config/WebConfig.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public class WebConfig {
2828
* with their duration and status code.
2929
*/
3030
@Bean
31-
public FilterRegistrationBean performanceLogFilter() {
31+
public FilterRegistrationBean<PerformanceLogFilter> performanceLogFilter() {
3232

33-
FilterRegistrationBean registration = new FilterRegistrationBean();
34-
Filter performanceLogFilter = new PerformanceLogFilter();
33+
FilterRegistrationBean<PerformanceLogFilter> registration = new FilterRegistrationBean<>();
34+
PerformanceLogFilter performanceLogFilter = new PerformanceLogFilter();
3535
this.beanFactory.autowireBean(performanceLogFilter);
3636
registration.setFilter(performanceLogFilter);
3737
registration.addUrlPatterns("/*");
@@ -52,10 +52,10 @@ public DiagnosticContextFacade diagnosticContextFacade() {
5252
* correlation id as MDC so it will be included in all associated logs.
5353
*/
5454
@Bean
55-
public FilterRegistrationBean diagnosticContextFilter() {
55+
public FilterRegistrationBean<DiagnosticContextFilter> diagnosticContextFilter() {
5656

57-
FilterRegistrationBean registration = new FilterRegistrationBean();
58-
Filter diagnosticContextFilter = new DiagnosticContextFilter();
57+
FilterRegistrationBean<DiagnosticContextFilter> registration = new FilterRegistrationBean<>();
58+
DiagnosticContextFilter diagnosticContextFilter = new DiagnosticContextFilter();
5959
this.beanFactory.autowireBean(diagnosticContextFilter);
6060
registration.setFilter(diagnosticContextFilter);
6161
registration.addUrlPatterns(ServiceConstants.URL_PATH_SERVICES + "/*");
@@ -66,9 +66,9 @@ public FilterRegistrationBean diagnosticContextFilter() {
6666
* @return the {@link FilterRegistrationBean} to register the {@link CharacterEncodingFilter} to set the encoding.
6767
*/
6868
@Bean
69-
public FilterRegistrationBean setCharacterEncodingFilter() {
69+
public FilterRegistrationBean<CharacterEncodingFilter> setCharacterEncodingFilter() {
7070

71-
FilterRegistrationBean registration = new FilterRegistrationBean();
71+
FilterRegistrationBean<CharacterEncodingFilter> registration = new FilterRegistrationBean<>();
7272
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
7373
characterEncodingFilter.setEncoding("UTF-8");
7474
characterEncodingFilter.setForceEncoding(false);

0 commit comments

Comments
 (0)