Add Nullability support into Java DSL

This commit is contained in:
abilan
2023-04-14 14:16:36 -04:00
parent 053cc00484
commit d5181bf0d7
105 changed files with 514 additions and 366 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-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.
@@ -112,7 +112,7 @@ public abstract class BaseHttpMessageHandlerSpec<S extends BaseHttpMessageHandle
/**
* Specify whether the outbound message's payload should be extracted
* when preparing the request body.
* Otherwise the Message instance itself is serialized.
* Otherwise, the Message instance itself is serialized.
* The default value is {@code true}.
* @param extractPayload true if the payload should be extracted.
* @return the spec
@@ -174,6 +174,7 @@ public abstract class BaseHttpMessageHandlerSpec<S extends BaseHttpMessageHandle
*/
public <P> S expectedResponseTypeFunction(
Function<Message<P>, ?> expectedResponseTypeFunction) {
return expectedResponseTypeExpression(new FunctionExpression<>(expectedResponseTypeFunction));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-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.
@@ -24,6 +24,7 @@ import org.springframework.expression.common.LiteralExpression;
import org.springframework.integration.expression.FunctionExpression;
import org.springframework.integration.http.inbound.HttpRequestHandlingController;
import org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;
@@ -84,7 +85,7 @@ public final class Http {
* @param restTemplate {@link RestTemplate} to use.
* @return the HttpMessageHandlerSpec instance
*/
public static HttpMessageHandlerSpec outboundChannelAdapter(URI uri, RestTemplate restTemplate) {
public static HttpMessageHandlerSpec outboundChannelAdapter(URI uri, @Nullable RestTemplate restTemplate) {
return new HttpMessageHandlerSpec(uri, restTemplate).expectReply(false);
}
@@ -95,7 +96,7 @@ public final class Http {
* @param restTemplate {@link RestTemplate} to use.
* @return the HttpMessageHandlerSpec instance
*/
public static HttpMessageHandlerSpec outboundChannelAdapter(String uri, RestTemplate restTemplate) {
public static HttpMessageHandlerSpec outboundChannelAdapter(String uri, @Nullable RestTemplate restTemplate) {
return new HttpMessageHandlerSpec(uri, restTemplate).expectReply(false);
}
@@ -122,7 +123,9 @@ public final class Http {
* @param restTemplate {@link RestTemplate} to use.
* @return the HttpMessageHandlerSpec instance
*/
public static HttpMessageHandlerSpec outboundChannelAdapter(Expression uriExpression, RestTemplate restTemplate) {
public static HttpMessageHandlerSpec outboundChannelAdapter(Expression uriExpression,
@Nullable RestTemplate restTemplate) {
return new HttpMessageHandlerSpec(uriExpression, restTemplate).expectReply(false);
}
@@ -172,7 +175,7 @@ public final class Http {
* @param restTemplate {@link RestTemplate} to use.
* @return the HttpMessageHandlerSpec instance
*/
public static HttpMessageHandlerSpec outboundGateway(URI uri, RestTemplate restTemplate) {
public static HttpMessageHandlerSpec outboundGateway(URI uri, @Nullable RestTemplate restTemplate) {
return new HttpMessageHandlerSpec(uri, restTemplate);
}
@@ -183,7 +186,7 @@ public final class Http {
* @param restTemplate {@link RestTemplate} to use.
* @return the HttpMessageHandlerSpec instance
*/
public static HttpMessageHandlerSpec outboundGateway(String uri, RestTemplate restTemplate) {
public static HttpMessageHandlerSpec outboundGateway(String uri, @Nullable RestTemplate restTemplate) {
return new HttpMessageHandlerSpec(uri, restTemplate);
}
@@ -210,7 +213,9 @@ public final class Http {
* @param restTemplate {@link RestTemplate} to use.
* @return the HttpMessageHandlerSpec instance
*/
public static HttpMessageHandlerSpec outboundGateway(Expression uriExpression, RestTemplate restTemplate) {
public static HttpMessageHandlerSpec outboundGateway(Expression uriExpression,
@Nullable RestTemplate restTemplate) {
return new HttpMessageHandlerSpec(uriExpression, restTemplate);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-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.
@@ -36,6 +36,7 @@ import org.springframework.integration.http.inbound.CrossOrigin;
import org.springframework.integration.http.inbound.RequestMapping;
import org.springframework.integration.http.support.DefaultHttpHeaderMapper;
import org.springframework.integration.mapping.HeaderMapper;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.validation.Validator;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -60,6 +61,7 @@ public abstract class HttpInboundEndpointSupportSpec<S extends HttpInboundEndpoi
protected final HeaderMapper<HttpHeaders> headerMapper = DefaultHttpHeaderMapper.inboundMapper(); // NOSONAR final
@Nullable
private HeaderMapper<HttpHeaders> explicitHeaderMapper;
protected HttpInboundEndpointSupportSpec(E gateway, String... path) {
@@ -216,7 +218,7 @@ public abstract class HttpInboundEndpointSupportSpec<S extends HttpInboundEndpoi
/**
* Specify the type of payload to be generated when the inbound HTTP request content is read by the
* {@link org.springframework.http.converter.HttpMessageConverter}s.
* By default this value is null which means at runtime any "text" Content-Type will
* By default, this value is null which means at runtime any "text" Content-Type will
* result in String while all others default to {@code byte[].class}.
* @param requestPayloadType The payload type.
* @return the current Spec.
@@ -229,7 +231,7 @@ public abstract class HttpInboundEndpointSupportSpec<S extends HttpInboundEndpoi
/**
* Specify the type of payload to be generated when the inbound HTTP request content is read by the
* {@link org.springframework.http.converter.HttpMessageConverter}s.
* By default this value is null which means at runtime any "text" Content-Type will
* By default, this value is null which means at runtime any "text" Content-Type will
* result in String while all others default to {@code byte[].class}.
* @param requestPayloadType The payload type.
* @return the current Spec.
@@ -358,7 +360,7 @@ public abstract class HttpInboundEndpointSupportSpec<S extends HttpInboundEndpoi
/**
* The producible media types of the mapped request, narrowing the primary mapping.
* @param produces the the media types for {@code Accept} header.
* @param produces the media types for {@code Accept} header.
* @return the spec
*/
public RequestMappingSpec produces(String... produces) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-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.
@@ -25,6 +25,7 @@ import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.integration.expression.ValueExpression;
import org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
@@ -43,17 +44,18 @@ import org.springframework.web.client.RestTemplate;
public class HttpMessageHandlerSpec
extends BaseHttpMessageHandlerSpec<HttpMessageHandlerSpec, HttpRequestExecutingMessageHandler> {
@Nullable
private final RestTemplate restTemplate;
protected HttpMessageHandlerSpec(URI uri, RestTemplate restTemplate) {
protected HttpMessageHandlerSpec(URI uri, @Nullable RestTemplate restTemplate) {
this(new ValueExpression<>(uri), restTemplate);
}
protected HttpMessageHandlerSpec(String uri, RestTemplate restTemplate) {
protected HttpMessageHandlerSpec(String uri, @Nullable RestTemplate restTemplate) {
this(new LiteralExpression(uri), restTemplate);
}
protected HttpMessageHandlerSpec(Expression uriExpression, RestTemplate restTemplate) {
protected HttpMessageHandlerSpec(Expression uriExpression, @Nullable RestTemplate restTemplate) {
super(new HttpRequestExecutingMessageHandler(uriExpression, restTemplate));
this.restTemplate = restTemplate;
}

View File

@@ -1,4 +1,6 @@
/**
* Provides HTTP Components support for Spring Integration Java DSL.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.integration.http.dsl;