mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Use instanceof patterns
See gh-33987
This commit is contained in:
parent
a9c547e767
commit
0e68cae57f
@ -175,8 +175,7 @@ public class WebFluxEndpointManagementContextConfiguration {
|
||||
}
|
||||
|
||||
private void process(Encoder<?> encoder) {
|
||||
if (encoder instanceof Jackson2JsonEncoder) {
|
||||
Jackson2JsonEncoder jackson2JsonEncoder = (Jackson2JsonEncoder) encoder;
|
||||
if (encoder instanceof Jackson2JsonEncoder jackson2JsonEncoder) {
|
||||
jackson2JsonEncoder.registerObjectMappersForType(OperationResponseBody.class, (associations) -> {
|
||||
ObjectMapper objectMapper = this.endpointObjectMapper.get().get();
|
||||
MEDIA_TYPES.forEach((mimeType) -> associations.put(mimeType, objectMapper));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@ -240,10 +240,9 @@ public class JerseyEndpointResourceFactory {
|
||||
Status status = isGet ? Status.NOT_FOUND : Status.NO_CONTENT;
|
||||
return Response.status(status).build();
|
||||
}
|
||||
if (!(response instanceof WebEndpointResponse)) {
|
||||
if (!(response instanceof WebEndpointResponse<?> webEndpointResponse)) {
|
||||
return Response.status(Status.OK).entity(convertIfNecessary(response)).build();
|
||||
}
|
||||
WebEndpointResponse<?> webEndpointResponse = (WebEndpointResponse<?>) response;
|
||||
return Response.status(webEndpointResponse.getStatus())
|
||||
.header("Content-Type", webEndpointResponse.getContentType())
|
||||
.entity(convertIfNecessary(webEndpointResponse.getBody())).build();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@ -379,10 +379,9 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
|
||||
}
|
||||
|
||||
private ResponseEntity<Object> toResponseEntity(Object response) {
|
||||
if (!(response instanceof WebEndpointResponse)) {
|
||||
if (!(response instanceof WebEndpointResponse<?> webEndpointResponse)) {
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
WebEndpointResponse<?> webEndpointResponse = (WebEndpointResponse<?>) response;
|
||||
MediaType contentType = (webEndpointResponse.getContentType() != null)
|
||||
? new MediaType(webEndpointResponse.getContentType()) : null;
|
||||
return ResponseEntity.status(webEndpointResponse.getStatus()).contentType(contentType)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@ -375,10 +375,9 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
|
||||
return new ResponseEntity<>(
|
||||
(httpMethod != HttpMethod.GET) ? HttpStatus.NO_CONTENT : HttpStatus.NOT_FOUND);
|
||||
}
|
||||
if (!(result instanceof WebEndpointResponse)) {
|
||||
if (!(result instanceof WebEndpointResponse<?> response)) {
|
||||
return convertIfNecessary(result);
|
||||
}
|
||||
WebEndpointResponse<?> response = (WebEndpointResponse<?>) result;
|
||||
MediaType contentType = (response.getContentType() != null) ? new MediaType(response.getContentType())
|
||||
: null;
|
||||
return ResponseEntity.status(response.getStatus()).contentType(contentType)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@ -132,8 +132,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
private void customizeAcceptCount(ConfigurableTomcatWebServerFactory factory, int acceptCount) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
if (handler instanceof AbstractProtocol<?> protocol) {
|
||||
protocol.setAcceptCount(acceptCount);
|
||||
}
|
||||
});
|
||||
@ -156,8 +155,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
protocol.setKeepAliveTimeout(keepAliveTimeout.toMillis());
|
||||
}
|
||||
}
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
if (handler instanceof AbstractProtocol<?> protocol) {
|
||||
protocol.setKeepAliveTimeout((int) keepAliveTimeout.toMillis());
|
||||
}
|
||||
});
|
||||
@ -166,8 +164,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
private void customizeMaxKeepAliveRequests(ConfigurableTomcatWebServerFactory factory, int maxKeepAliveRequests) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
AbstractHttp11Protocol<?> protocol = (AbstractHttp11Protocol<?>) handler;
|
||||
if (handler instanceof AbstractHttp11Protocol<?> protocol) {
|
||||
protocol.setMaxKeepAliveRequests(maxKeepAliveRequests);
|
||||
}
|
||||
});
|
||||
@ -176,8 +173,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
private void customizeMaxConnections(ConfigurableTomcatWebServerFactory factory, int maxConnections) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
if (handler instanceof AbstractProtocol<?> protocol) {
|
||||
protocol.setMaxConnections(maxConnections);
|
||||
}
|
||||
});
|
||||
@ -186,8 +182,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
private void customizeConnectionTimeout(ConfigurableTomcatWebServerFactory factory, Duration connectionTimeout) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
if (handler instanceof AbstractProtocol<?> protocol) {
|
||||
protocol.setConnectionTimeout((int) connectionTimeout.toMillis());
|
||||
}
|
||||
});
|
||||
@ -204,8 +199,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
private void customizeRejectIllegalHeader(ConfigurableTomcatWebServerFactory factory, boolean rejectIllegalHeader) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
AbstractHttp11Protocol<?> protocol = (AbstractHttp11Protocol<?>) handler;
|
||||
if (handler instanceof AbstractHttp11Protocol<?> protocol) {
|
||||
protocol.setRejectIllegalHeader(rejectIllegalHeader);
|
||||
}
|
||||
});
|
||||
@ -249,15 +243,14 @@ public class TomcatWebServerFactoryCustomizer
|
||||
CloudPlatform platform = CloudPlatform.getActive(this.environment);
|
||||
return platform != null && platform.isUsingForwardHeaders();
|
||||
}
|
||||
return this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
||||
return this.serverProperties.getForwardHeadersStrategy() == ServerProperties.ForwardHeadersStrategy.NATIVE;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void customizeMaxThreads(ConfigurableTomcatWebServerFactory factory, int maxThreads) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
if (handler instanceof AbstractProtocol protocol) {
|
||||
protocol.setMaxThreads(maxThreads);
|
||||
}
|
||||
});
|
||||
@ -267,8 +260,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
private void customizeMinThreads(ConfigurableTomcatWebServerFactory factory, int minSpareThreads) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
if (handler instanceof AbstractProtocol protocol) {
|
||||
protocol.setMinSpareThreads(minSpareThreads);
|
||||
}
|
||||
});
|
||||
@ -279,8 +271,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
int maxHttpRequestHeaderSize) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
|
||||
if (handler instanceof AbstractHttp11Protocol protocol) {
|
||||
protocol.setMaxHttpRequestHeaderSize(maxHttpRequestHeaderSize);
|
||||
}
|
||||
});
|
||||
@ -289,8 +280,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
private void customizeMaxSwallowSize(ConfigurableTomcatWebServerFactory factory, int maxSwallowSize) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
AbstractHttp11Protocol<?> protocol = (AbstractHttp11Protocol<?>) handler;
|
||||
if (handler instanceof AbstractHttp11Protocol<?> protocol) {
|
||||
protocol.setMaxSwallowSize(maxSwallowSize);
|
||||
}
|
||||
});
|
||||
|
@ -962,8 +962,7 @@ public class TestRestTemplate {
|
||||
}
|
||||
|
||||
private URI resolveUri(RequestEntity<?> entity) {
|
||||
if (entity instanceof UriTemplateRequestEntity) {
|
||||
UriTemplateRequestEntity<?> templatedUriEntity = (UriTemplateRequestEntity<?>) entity;
|
||||
if (entity instanceof UriTemplateRequestEntity<?> templatedUriEntity) {
|
||||
if (templatedUriEntity.getVars() != null) {
|
||||
return this.restTemplate.getUriTemplateHandler().expand(templatedUriEntity.getUriTemplate(),
|
||||
templatedUriEntity.getVars());
|
||||
|
@ -29,8 +29,7 @@ class JSON {
|
||||
if (value instanceof Boolean) {
|
||||
return (Boolean) value;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
String stringValue = (String) value;
|
||||
if (value instanceof String stringValue) {
|
||||
if ("true".equalsIgnoreCase(stringValue)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -311,8 +311,7 @@ public class JSONObject {
|
||||
JSON.checkDouble(((Number) value).doubleValue());
|
||||
}
|
||||
|
||||
if (current instanceof JSONArray) {
|
||||
JSONArray array = (JSONArray) current;
|
||||
if (current instanceof JSONArray array) {
|
||||
array.put(value);
|
||||
}
|
||||
else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@ -61,8 +61,7 @@ class NotConstructorBoundInjectionFailureAnalyzer
|
||||
}
|
||||
|
||||
private boolean isConstructorBindingConfigurationProperties(InjectionPoint injectionPoint) {
|
||||
if (injectionPoint != null && injectionPoint.getMember() instanceof Constructor) {
|
||||
Constructor<?> constructor = (Constructor<?>) injectionPoint.getMember();
|
||||
if (injectionPoint != null && injectionPoint.getMember() instanceof Constructor<?> constructor) {
|
||||
Class<?> declaringClass = constructor.getDeclaringClass();
|
||||
MergedAnnotation<ConfigurationProperties> configurationProperties = MergedAnnotations.from(declaringClass)
|
||||
.get(ConfigurationProperties.class);
|
||||
|
Loading…
Reference in New Issue
Block a user