Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
// Use request configuration given by the user, when available
RequestConfig config = null;
if (httpRequest instanceof Configurable) {
config = ((Configurable) httpRequest).getConfig();
if (httpRequest instanceof Configurable configurable) {
config = configurable.getConfig();
}
if (config == null) {
config = createRequestConfig(client);
Expand Down Expand Up @@ -328,8 +328,8 @@ protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
@Override
public void destroy() throws Exception {
HttpClient httpClient = getHttpClient();
if (httpClient instanceof Closeable) {
((Closeable) httpClient).close();
if (httpClient instanceof Closeable closeable) {
closeable.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ public void completed(Message<HttpResponse, Publisher<ByteBuffer>> result) {
@Override
public void failed(Exception ex) {
Throwable t = ex;
if (t instanceof HttpStreamResetException) {
HttpStreamResetException httpStreamResetException = (HttpStreamResetException) ex;
t = httpStreamResetException.getCause();
if (t instanceof HttpStreamResetException hsre) {
t = hsre.getCause();
}
this.sink.error(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,25 @@ public void afterPropertiesSet() throws Exception {
}
if (this.byteBufferPool == null) {
this.byteBufferPool = new MappedByteBufferPool(2048,
this.executor instanceof ThreadPool.SizedThreadPool
? ((ThreadPool.SizedThreadPool) this.executor).getMaxThreads() / 2
this.executor instanceof ThreadPool.SizedThreadPool sizedThreadPool
? sizedThreadPool.getMaxThreads() / 2
: ProcessorUtils.availableProcessors() * 2);
}
if (this.scheduler == null) {
this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false);
}

if (this.executor instanceof LifeCycle) {
((LifeCycle)this.executor).start();
if (this.executor instanceof LifeCycle lifeCycle) {
lifeCycle.start();
}
this.scheduler.start();
}

@Override
public void destroy() throws Exception {
try {
if (this.executor instanceof LifeCycle) {
((LifeCycle)this.executor).stop();
if (this.executor instanceof LifeCycle lifeCycle) {
lifeCycle.stop();
}
}
catch (Throwable ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public DecoderHttpMessageReader(Decoder<T> decoder) {
}

private static void initLogger(Decoder<?> decoder) {
if (decoder instanceof AbstractDecoder &&
if (decoder instanceof AbstractDecoder<?> abstractDecoder &&
decoder.getClass().getName().startsWith("org.springframework.core.codec")) {
Log logger = HttpLogging.forLog(((AbstractDecoder<?>) decoder).getLogger());
((AbstractDecoder<?>) decoder).setLogger(logger);
Log logger = HttpLogging.forLog(abstractDecoder.getLogger());
abstractDecoder.setLogger(logger);
}
}

Expand Down Expand Up @@ -163,9 +163,8 @@ public Mono<T> readMono(ResolvableType actualType, ResolvableType elementType,
protected Map<String, Object> getReadHints(ResolvableType actualType,
ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response) {

if (this.decoder instanceof HttpMessageDecoder) {
HttpMessageDecoder<?> decoder = (HttpMessageDecoder<?>) this.decoder;
return decoder.getDecodeHints(actualType, elementType, request, response);
if (this.decoder instanceof HttpMessageDecoder<?> httpMethodDecoder) {
return httpMethodDecoder.getDecodeHints(actualType, elementType, request, response);
}
return Hints.none();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public EncoderHttpMessageWriter(Encoder<T> encoder) {
}

private static void initLogger(Encoder<?> encoder) {
if (encoder instanceof AbstractEncoder &&
if (encoder instanceof AbstractEncoder<?> abstractEncoder &&
encoder.getClass().getName().startsWith("org.springframework.core.codec")) {
Log logger = HttpLogging.forLog(((AbstractEncoder<?>) encoder).getLogger());
((AbstractEncoder<?>) encoder).setLogger(logger);
Log logger = HttpLogging.forLog(abstractEncoder.getLogger());
abstractEncoder.setLogger(logger);
}
}

Expand Down Expand Up @@ -224,9 +224,8 @@ public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType actua
protected Map<String, Object> getWriteHints(ResolvableType streamType, ResolvableType elementType,
@Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response) {

if (this.encoder instanceof HttpMessageEncoder) {
HttpMessageEncoder<?> encoder = (HttpMessageEncoder<?>) this.encoder;
return encoder.getEncodeHints(streamType, elementType, mediaType, request, response);
if (this.encoder instanceof HttpMessageEncoder<?> httpMessageEncoder) {
return httpMessageEncoder.getEncodeHints(streamType, elementType, mediaType, request, response);
}
return Hints.none();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private static long lengthOf(Resource resource) {
private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region,
ReactiveHttpOutputMessage message, Map<String, Object> hints) {

if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) {
if (message instanceof ZeroCopyHttpOutputMessage zeroCopyHttpOutputMessage && resource.isFile()) {
try {
File file = resource.getFile();
long pos = region != null ? region.getPosition() : 0;
Expand All @@ -188,7 +188,7 @@ private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable Resour
String formatted = region != null ? "region " + pos + "-" + (count) + " of " : "";
logger.debug(Hints.getLogPrefix(hints) + "Zero-copy " + formatted + "[" + resource + "]");
}
return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
return Optional.of(zeroCopyHttpOutputMessage.writeWith(file, pos, count));
}
catch (IOException ex) {
// should not happen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ private Flux<Publisher<DataBuffer>> encode(Publisher<?> input, ResolvableType el

return Flux.from(input).map(element -> {

ServerSentEvent<?> sse = (element instanceof ServerSentEvent ?
(ServerSentEvent<?>) element : ServerSentEvent.builder().data(element).build());
ServerSentEvent<?> sse = (element instanceof ServerSentEvent<?> serverSentEvent ?
serverSentEvent : ServerSentEvent.builder().data(element).build());

StringBuilder sb = new StringBuilder();
String id = sse.id();
Expand Down Expand Up @@ -150,9 +150,9 @@ private Flux<Publisher<DataBuffer>> encode(Publisher<?> input, ResolvableType el
if (data == null) {
result = Flux.just(encodeText(sb + "\n", mediaType, factory));
}
else if (data instanceof String) {
data = StringUtils.replace((String) data, "\n", "\ndata:");
result = Flux.just(encodeText(sb + (String) data + "\n\n", mediaType, factory));
else if (data instanceof String dataString) {
dataString = StringUtils.replace(dataString, "\n", "\ndata:");
result = Flux.just(encodeText(sb + dataString + "\n\n", mediaType, factory));
}
else {
result = encodeEvent(sb, data, dataType, mediaType, factory, hints);
Expand Down Expand Up @@ -203,9 +203,8 @@ public Mono<Void> write(Publisher<?> input, ResolvableType actualType, Resolvabl
private Map<String, Object> getEncodeHints(ResolvableType actualType, ResolvableType elementType,
@Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response) {

if (this.encoder instanceof HttpMessageEncoder) {
HttpMessageEncoder<?> encoder = (HttpMessageEncoder<?>) this.encoder;
return encoder.getEncodeHints(actualType, elementType, mediaType, request, response);
if (this.encoder instanceof HttpMessageEncoder<?> httpMessageEncoder) {
return httpMessageEncoder.getEncodeHints(actualType, elementType, mediaType, request, response);
}
return Hints.none();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ private void logValue(@Nullable Object value, @Nullable Map<String, Object> hint
}

private CodecException processException(IOException ex) {
if (ex instanceof InvalidDefinitionException) {
JavaType type = ((InvalidDefinitionException) ex).getType();
if (ex instanceof InvalidDefinitionException ide) {
JavaType type = ide.getType();
return new CodecException("Type definition error: " + type, ex);
}
if (ex instanceof JsonProcessingException) {
String originalMessage = ((JsonProcessingException) ex).getOriginalMessage();
if (ex instanceof JsonProcessingException jpe) {
String originalMessage = jpe.getOriginalMessage();
return new DecodingException("JSON decoding error: " + originalMessage, ex);
}
return new DecodingException("I/O error while parsing input stream", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected Map<String, Object> getHints(ResolvableType resolvableType) {

@Nullable
protected MethodParameter getParameter(ResolvableType type) {
return (type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null);
return (type.getSource() instanceof MethodParameter methodParameter ? methodParameter : null);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private LinkedMultiValueMap<String, Part> toMultiValueMap(Map<String, Collection
}

private List<Part> toList(Collection<Part> collection) {
return collection instanceof List ? (List<Part>) collection : new ArrayList<>(collection);
return collection instanceof List<Part> partList ? partList : new ArrayList<>(collection);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private <T> Flux<DataBuffer> encodePart(byte[] boundary, Part part, DataBufferFa
String name = part.name();
if (!headers.containsKey(HttpHeaders.CONTENT_DISPOSITION)) {
headers.setContentDispositionFormData(name,
(part instanceof FilePart ? ((FilePart) part).filename() : null));
(part instanceof FilePart filePart ? filePart.filename() : null));
}

return Flux.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,18 @@ public void withDefaultCodecConfig(Consumer<DefaultCodecConfig> codecsConfigCons

private void addCodec(Object codec, boolean applyDefaultConfig) {

if (codec instanceof Decoder) {
codec = new DecoderHttpMessageReader<>((Decoder<?>) codec);
if (codec instanceof Decoder<?> decoder) {
codec = new DecoderHttpMessageReader<>(decoder);
}
else if (codec instanceof Encoder) {
codec = new EncoderHttpMessageWriter<>((Encoder<?>) codec);
else if (codec instanceof Encoder<?> encoder) {
codec = new EncoderHttpMessageWriter<>(encoder);
}

if (codec instanceof HttpMessageReader) {
HttpMessageReader<?> reader = (HttpMessageReader<?>) codec;
if (codec instanceof HttpMessageReader<?> reader) {
boolean canReadToObject = reader.canRead(ResolvableType.forClass(Object.class), null);
(canReadToObject ? this.objectReaders : this.typedReaders).put(reader, applyDefaultConfig);
}
else if (codec instanceof HttpMessageWriter) {
HttpMessageWriter<?> writer = (HttpMessageWriter<?>) codec;
else if (codec instanceof HttpMessageWriter<?> writer) {
boolean canWriteObject = writer.canWrite(ResolvableType.forClass(Object.class), null);
(canWriteObject ? this.objectWriters : this.typedWriters).put(writer, applyDefaultConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,12 @@ protected <T> void addCodec(List<T> codecs, T codec) {
* if configured by the application, to the given codec , including any
* codec it contains.
*/
@SuppressWarnings("rawtypes")
private void initCodec(@Nullable Object codec) {
if (codec instanceof DecoderHttpMessageReader) {
codec = ((DecoderHttpMessageReader) codec).getDecoder();
if (codec instanceof DecoderHttpMessageReader<?> decoderHttpMessageReader) {
codec = decoderHttpMessageReader.getDecoder();
}
else if (codec instanceof EncoderHttpMessageWriter) {
codec = ((EncoderHttpMessageWriter<?>) codec).getEncoder();
else if (codec instanceof EncoderHttpMessageWriter<?> encoderHttpMessageWriter) {
codec = encoderHttpMessageWriter.getEncoder();
}

if (codec == null) {
Expand All @@ -439,72 +438,72 @@ else if (codec instanceof EncoderHttpMessageWriter) {

Integer size = this.maxInMemorySize;
if (size != null) {
if (codec instanceof AbstractDataBufferDecoder) {
((AbstractDataBufferDecoder<?>) codec).setMaxInMemorySize(size);
if (codec instanceof AbstractDataBufferDecoder<?> abstractDataBufferDecoder) {
abstractDataBufferDecoder.setMaxInMemorySize(size);
}
if (protobufPresent) {
if (codec instanceof ProtobufDecoder) {
((ProtobufDecoder) codec).setMaxMessageSize(size);
if (codec instanceof ProtobufDecoder protobufDecoderCodec) {
protobufDecoderCodec.setMaxMessageSize(size);
}
}
if (kotlinSerializationCborPresent) {
if (codec instanceof KotlinSerializationCborDecoder) {
((KotlinSerializationCborDecoder) codec).setMaxInMemorySize(size);
if (codec instanceof KotlinSerializationCborDecoder kotlinSerializationCborDecoderCodec) {
kotlinSerializationCborDecoderCodec.setMaxInMemorySize(size);
}
}
if (kotlinSerializationJsonPresent) {
if (codec instanceof KotlinSerializationJsonDecoder) {
((KotlinSerializationJsonDecoder) codec).setMaxInMemorySize(size);
if (codec instanceof KotlinSerializationJsonDecoder kotlinSerializationJsonDecoderCodec) {
kotlinSerializationJsonDecoderCodec.setMaxInMemorySize(size);
}
}
if (kotlinSerializationProtobufPresent) {
if (codec instanceof KotlinSerializationProtobufDecoder) {
((KotlinSerializationProtobufDecoder) codec).setMaxInMemorySize(size);
if (codec instanceof KotlinSerializationProtobufDecoder kotlinSerializationProtobufDecoderCodec) {
kotlinSerializationProtobufDecoderCodec.setMaxInMemorySize(size);
}
}
if (jackson2Present) {
if (codec instanceof AbstractJackson2Decoder) {
((AbstractJackson2Decoder) codec).setMaxInMemorySize(size);
if (codec instanceof AbstractJackson2Decoder abstractJackson2Decoder) {
abstractJackson2Decoder.setMaxInMemorySize(size);
}
}
if (jaxb2Present) {
if (codec instanceof Jaxb2XmlDecoder) {
((Jaxb2XmlDecoder) codec).setMaxInMemorySize(size);
if (codec instanceof Jaxb2XmlDecoder jaxb2XmlDecoder) {
jaxb2XmlDecoder.setMaxInMemorySize(size);
}
}
if (codec instanceof FormHttpMessageReader) {
((FormHttpMessageReader) codec).setMaxInMemorySize(size);
if (codec instanceof FormHttpMessageReader formHttpMessageReader) {
formHttpMessageReader.setMaxInMemorySize(size);
}
if (codec instanceof ServerSentEventHttpMessageReader) {
((ServerSentEventHttpMessageReader) codec).setMaxInMemorySize(size);
if (codec instanceof ServerSentEventHttpMessageReader serverSentEventHttpMessageReader) {
serverSentEventHttpMessageReader.setMaxInMemorySize(size);
}
if (codec instanceof DefaultPartHttpMessageReader) {
((DefaultPartHttpMessageReader) codec).setMaxInMemorySize(size);
if (codec instanceof DefaultPartHttpMessageReader defaultPartHttpMessageReader) {
defaultPartHttpMessageReader.setMaxInMemorySize(size);
}
if (codec instanceof PartEventHttpMessageReader) {
((PartEventHttpMessageReader) codec).setMaxInMemorySize(size);
if (codec instanceof PartEventHttpMessageReader partEventHttpMessageReader) {
partEventHttpMessageReader.setMaxInMemorySize(size);
}
}

Boolean enable = this.enableLoggingRequestDetails;
if (enable != null) {
if (codec instanceof FormHttpMessageReader) {
((FormHttpMessageReader) codec).setEnableLoggingRequestDetails(enable);
if (codec instanceof FormHttpMessageReader formHttpMessageReader) {
formHttpMessageReader.setEnableLoggingRequestDetails(enable);
}
if (codec instanceof MultipartHttpMessageReader) {
((MultipartHttpMessageReader) codec).setEnableLoggingRequestDetails(enable);
if (codec instanceof MultipartHttpMessageReader multipartHttpMessageReader) {
multipartHttpMessageReader.setEnableLoggingRequestDetails(enable);
}
if (codec instanceof DefaultPartHttpMessageReader) {
((DefaultPartHttpMessageReader) codec).setEnableLoggingRequestDetails(enable);
if (codec instanceof DefaultPartHttpMessageReader defaultPartHttpMessageReader) {
defaultPartHttpMessageReader.setEnableLoggingRequestDetails(enable);
}
if (codec instanceof PartEventHttpMessageReader) {
((PartEventHttpMessageReader) codec).setEnableLoggingRequestDetails(enable);
if (codec instanceof PartEventHttpMessageReader partEventHttpMessageReader) {
partEventHttpMessageReader.setEnableLoggingRequestDetails(enable);
}
if (codec instanceof FormHttpMessageWriter) {
((FormHttpMessageWriter) codec).setEnableLoggingRequestDetails(enable);
if (codec instanceof FormHttpMessageWriter formHttpMessageWriter) {
formHttpMessageWriter.setEnableLoggingRequestDetails(enable);
}
if (codec instanceof MultipartHttpMessageWriter) {
((MultipartHttpMessageWriter) codec).setEnableLoggingRequestDetails(enable);
if (codec instanceof MultipartHttpMessageWriter multipartHttpMessageWriter) {
multipartHttpMessageWriter.setEnableLoggingRequestDetails(enable);
}
}

Expand All @@ -513,17 +512,17 @@ else if (codec instanceof EncoderHttpMessageWriter) {
}

// Recurse for nested codecs
if (codec instanceof MultipartHttpMessageReader) {
initCodec(((MultipartHttpMessageReader) codec).getPartReader());
if (codec instanceof MultipartHttpMessageReader multipartHttpMessageReader) {
initCodec(multipartHttpMessageReader.getPartReader());
}
else if (codec instanceof MultipartHttpMessageWriter) {
initCodec(((MultipartHttpMessageWriter) codec).getFormWriter());
else if (codec instanceof MultipartHttpMessageWriter multipartHttpMessageWriter) {
initCodec(multipartHttpMessageWriter.getFormWriter());
}
else if (codec instanceof ServerSentEventHttpMessageReader) {
initCodec(((ServerSentEventHttpMessageReader) codec).getDecoder());
else if (codec instanceof ServerSentEventHttpMessageReader serverSentEventHttpMessageReader) {
initCodec(serverSentEventHttpMessageReader.getDecoder());
}
else if (codec instanceof ServerSentEventHttpMessageWriter) {
initCodec(((ServerSentEventHttpMessageWriter) codec).getEncoder());
else if (codec instanceof ServerSentEventHttpMessageWriter serverSentEventHttpMessageWriter) {
initCodec(serverSentEventHttpMessageWriter.getEncoder());
}
}

Expand Down
Loading