Use new Java features (switch expressions, text blocks, new JDK methods)
Closes gh-29747
This commit is contained in:
committed by
Sam Brannen
parent
48abd493fe
commit
afb8a0d1b1
@@ -378,10 +378,9 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
*/
|
||||
protected HandlerMethod createHandlerMethod(Object handler, Method method) {
|
||||
HandlerMethod handlerMethod;
|
||||
if (handler instanceof String) {
|
||||
if (handler instanceof String beanName) {
|
||||
ApplicationContext context = getApplicationContext();
|
||||
Assert.state(context != null, "ApplicationContext is required for resolving handler bean names");
|
||||
String beanName = (String) handler;
|
||||
handlerMethod = new HandlerMethod(beanName, context.getAutowireCapableBeanFactory(), method);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -93,10 +93,9 @@ public class GenericMessage<T> implements Message<T>, Serializable {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof GenericMessage)) {
|
||||
if (!(other instanceof GenericMessage<?> otherMsg)) {
|
||||
return false;
|
||||
}
|
||||
GenericMessage<?> otherMsg = (GenericMessage<?>) other;
|
||||
// Using nullSafeEquals for proper array equals comparisons
|
||||
return (ObjectUtils.nullSafeEquals(this.payload, otherMsg.payload) && this.headers.equals(otherMsg.headers));
|
||||
}
|
||||
|
||||
@@ -617,8 +617,7 @@ public class MessageHeaderAccessor {
|
||||
* @since 4.1
|
||||
*/
|
||||
public static MessageHeaderAccessor getMutableAccessor(Message<?> message) {
|
||||
if (message.getHeaders() instanceof MutableMessageHeaders) {
|
||||
MutableMessageHeaders mutableHeaders = (MutableMessageHeaders) message.getHeaders();
|
||||
if (message.getHeaders() instanceof MutableMessageHeaders mutableHeaders) {
|
||||
MessageHeaderAccessor accessor = mutableHeaders.getAccessor();
|
||||
return (accessor.isMutable() ? accessor : accessor.createAccessor(message));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,13 +62,13 @@ public class ProtobufMessageConverterTests {
|
||||
this.message = MessageBuilder.withPayload(this.testMsg.toByteArray())
|
||||
.setHeader(CONTENT_TYPE, ProtobufMessageConverter.PROTOBUF).build();
|
||||
this.messageWithoutContentType = MessageBuilder.withPayload(this.testMsg.toByteArray()).build();
|
||||
this.messageJson = MessageBuilder.withPayload(
|
||||
"{\n" +
|
||||
" \"foo\": \"Foo\",\n" +
|
||||
" \"blah\": {\n" +
|
||||
" \"blah\": 123\n" +
|
||||
" }\n" +
|
||||
"}")
|
||||
this.messageJson = MessageBuilder.withPayload("""
|
||||
{
|
||||
"foo": "Foo",
|
||||
"blah": {
|
||||
"blah": 123
|
||||
}
|
||||
}""".replace("\t", " "))
|
||||
.setHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -319,9 +319,7 @@ public class MessageHeaderAccessorTests {
|
||||
})).isEqualTo(expected);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 80; i++) {
|
||||
sb.append('a');
|
||||
}
|
||||
sb.append("a".repeat(80));
|
||||
final String payload = sb.toString() + " > 80";
|
||||
|
||||
String actual = accessor.getShortLogMessage(payload);
|
||||
@@ -355,10 +353,8 @@ public class MessageHeaderAccessorTests {
|
||||
})).isEqualTo(expected);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 80; i++) {
|
||||
sb.append('a');
|
||||
}
|
||||
final String payload = sb.toString() + " > 80";
|
||||
sb.append("a".repeat(80));
|
||||
final String payload = sb + " > 80";
|
||||
|
||||
String actual = accessor.getDetailedLogMessage(payload);
|
||||
assertThat(actual).isEqualTo("headers={contentType=text/plain} payload=" + sb + " > 80");
|
||||
|
||||
Reference in New Issue
Block a user