diff --git a/spring-web/src/main/java/org/springframework/web/service/annotation/DeleteExchange.java b/spring-web/src/main/java/org/springframework/web/service/annotation/DeleteExchange.java new file mode 100644 index 0000000000..80c9c66b01 --- /dev/null +++ b/spring-web/src/main/java/org/springframework/web/service/annotation/DeleteExchange.java @@ -0,0 +1,64 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.web.service.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.core.annotation.AliasFor; + + +/** + * Shortcut for {@link HttpExchange} for HTTP DELETE requests. + * + * @author Rossen Stoyanchev + * @since 6.0 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@HttpExchange(method = "DELETE") +public @interface DeleteExchange { + + /** + * Alias for {@link HttpExchange#value}. + */ + @AliasFor(annotation = HttpExchange.class) + String[] value() default {}; + + /** + * Alias for {@link HttpExchange#url()}. + */ + @AliasFor(annotation = HttpExchange.class) + String[] url() default {}; + + /** + * Alias for {@link HttpExchange#contentType()}. + */ + @AliasFor(annotation = HttpExchange.class) + String contentType() default ""; + + /** + * Alias for {@link HttpExchange#accept()}. + */ + @AliasFor(annotation = HttpExchange.class) + String[] accept() default {}; + +} diff --git a/spring-web/src/main/java/org/springframework/web/service/annotation/HeadExchange.java b/spring-web/src/main/java/org/springframework/web/service/annotation/HeadExchange.java new file mode 100644 index 0000000000..5c51fd26c0 --- /dev/null +++ b/spring-web/src/main/java/org/springframework/web/service/annotation/HeadExchange.java @@ -0,0 +1,58 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.web.service.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.core.annotation.AliasFor; + + +/** + * Shortcut for {@link HttpExchange} for HTTP HEAD requests. + * + * @author Rossen Stoyanchev + * @since 6.0 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@HttpExchange(method = "HEAD") +public @interface HeadExchange { + + /** + * Alias for {@link HttpExchange#value}. + */ + @AliasFor(annotation = HttpExchange.class) + String value() default ""; + + /** + * Alias for {@link HttpExchange#url()}. + */ + @AliasFor(annotation = HttpExchange.class) + String url() default ""; + + /** + * Alias for {@link HttpExchange#accept()}. + */ + @AliasFor(annotation = HttpExchange.class) + String[] accept() default {}; + +} diff --git a/spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchange.java b/spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchange.java index 4fc74c4304..304e32cb6f 100644 --- a/spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchange.java +++ b/spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchange.java @@ -25,20 +25,47 @@ import java.lang.annotation.Target; import org.springframework.core.annotation.AliasFor; import org.springframework.web.bind.annotation.Mapping; + /** - * Supported method parameters: + * Annotation that declares an HTTP service method as an HTTP endpoint defined + * through attributes of the annotation and method argument values. + * + *

The annotation may only be used at the type level for example to specify + * a base URL path. At the method level, use one of the HTTP method specific, + * shortcut annotations, each of which is meta-annotated with + * {@link HttpExchange}: *

* + *

Supported method arguments: + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Method ArgumentDescription
{@link org.springframework.http.HttpMethod}Set the HTTP method for the request, overriding the annotation + * {@link #method()} attribute value
{@link org.springframework.web.bind.annotation.PathVariable @PathVariable}Provide a path variable to expand the URI template with. This may be an + * individual value or a Map of values.
+ * * @author Rossen Stoyanchev * @since 6.0 */ -@Target({ElementType.TYPE, ElementType.METHOD}) +@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Mapping @@ -83,5 +110,4 @@ public @interface HttpExchange { */ String[] accept() default {}; - } diff --git a/spring-web/src/main/java/org/springframework/web/service/annotation/OptionsExchange.java b/spring-web/src/main/java/org/springframework/web/service/annotation/OptionsExchange.java new file mode 100644 index 0000000000..4753e30c58 --- /dev/null +++ b/spring-web/src/main/java/org/springframework/web/service/annotation/OptionsExchange.java @@ -0,0 +1,52 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.web.service.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.core.annotation.AliasFor; + + +/** + * Shortcut for {@link HttpExchange} for HTTP OPTIONS requests. + * + * @author Rossen Stoyanchev + * @since 6.0 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@HttpExchange(method = "OPTIONS") +public @interface OptionsExchange { + + /** + * Alias for {@link HttpExchange#value}. + */ + @AliasFor(annotation = HttpExchange.class) + String value() default ""; + + /** + * Alias for {@link HttpExchange#url()}. + */ + @AliasFor(annotation = HttpExchange.class) + String url() default ""; + +} diff --git a/spring-web/src/main/java/org/springframework/web/service/annotation/PatchExchange.java b/spring-web/src/main/java/org/springframework/web/service/annotation/PatchExchange.java new file mode 100644 index 0000000000..c26058745e --- /dev/null +++ b/spring-web/src/main/java/org/springframework/web/service/annotation/PatchExchange.java @@ -0,0 +1,64 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.web.service.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.core.annotation.AliasFor; + + +/** + * Shortcut for {@link HttpExchange} for HTTP PATCH requests. + * + * @author Rossen Stoyanchev + * @since 6.0 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@HttpExchange(method = "PATCH") +public @interface PatchExchange { + + /** + * Alias for {@link HttpExchange#value}. + */ + @AliasFor(annotation = HttpExchange.class) + String[] value() default {}; + + /** + * Alias for {@link HttpExchange#url()}. + */ + @AliasFor(annotation = HttpExchange.class) + String[] url() default {}; + + /** + * Alias for {@link HttpExchange#contentType()}. + */ + @AliasFor(annotation = HttpExchange.class) + String contentType() default ""; + + /** + * Alias for {@link HttpExchange#accept()}. + */ + @AliasFor(annotation = HttpExchange.class) + String[] accept() default {}; + +} diff --git a/spring-web/src/main/java/org/springframework/web/service/annotation/PutExchange.java b/spring-web/src/main/java/org/springframework/web/service/annotation/PutExchange.java index c17c031b23..9df4927eed 100644 --- a/spring-web/src/main/java/org/springframework/web/service/annotation/PutExchange.java +++ b/spring-web/src/main/java/org/springframework/web/service/annotation/PutExchange.java @@ -55,4 +55,10 @@ public @interface PutExchange { @AliasFor(annotation = HttpExchange.class) String contentType() default ""; + /** + * Alias for {@link HttpExchange#accept()}. + */ + @AliasFor(annotation = HttpExchange.class) + String[] accept() default {}; + } diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpClientAdapter.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpClientAdapter.java index 9d57856042..dd2f42ed41 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpClientAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpClientAdapter.java @@ -33,18 +33,58 @@ import org.springframework.http.ResponseEntity; */ public interface HttpClientAdapter { + /** + * Perform the given request, and release the response content, if any. + * @param requestValues the request to perform + * @return {@code Mono} that completes when the request is fully executed + * and the response content is released. + */ Mono requestToVoid(HttpRequestValues requestValues); + /** + * Perform the given request, release the response content, and return the + * response headers. + * @param requestValues the request to perform + * @return {@code Mono} that returns the response headers the request is + * fully executed and the response content released. + */ Mono requestToHeaders(HttpRequestValues requestValues); + /** + * Perform the given request and decode the response content to the given type. + * @param requestValues the request to perform + * @param bodyType the target type to decode to + * @return {@code Mono} that returns the decoded response. + * @param the type the response is decoded to + */ Mono requestToBody(HttpRequestValues requestValues, ParameterizedTypeReference bodyType); + /** + * Perform the given request and decode the response content to a stream with + * elements of the given type. + * @param requestValues the request to perform + * @param bodyType the target stream element type to decode to + * @return {@code Flux} with decoded stream elements. + * @param the type the response is decoded to + */ Flux requestToBodyFlux(HttpRequestValues requestValues, ParameterizedTypeReference bodyType); + /** + * Variant of {@link #requestToVoid(HttpRequestValues)} with additional + * access to the response status and headers. + */ Mono> requestToBodilessEntity(HttpRequestValues requestValues); + /** + * Variant of {@link #requestToBody(HttpRequestValues, ParameterizedTypeReference)} + * with additional access to the response status and headers. + */ Mono> requestToEntity(HttpRequestValues requestValues, ParameterizedTypeReference bodyType); + /** + * Variant of {@link #requestToBodyFlux(HttpRequestValues, ParameterizedTypeReference)} + * with additional access to the response status and headers. + */ Mono>> requestToEntityFlux(HttpRequestValues requestValues, ParameterizedTypeReference bodyType); }