Skip to content

Commit 8a46e96

Browse files
committed
Add remaining HttpExchange annotations
See gh-28386
1 parent d7ab5b4 commit 8a46e96

File tree

7 files changed

+318
-8
lines changed

7 files changed

+318
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.service.annotation;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
import org.springframework.core.annotation.AliasFor;
26+
27+
28+
/**
29+
* Shortcut for {@link HttpExchange} for HTTP DELETE requests.
30+
*
31+
* @author Rossen Stoyanchev
32+
* @since 6.0
33+
*/
34+
@Target(ElementType.METHOD)
35+
@Retention(RetentionPolicy.RUNTIME)
36+
@Documented
37+
@HttpExchange(method = "DELETE")
38+
public @interface DeleteExchange {
39+
40+
/**
41+
* Alias for {@link HttpExchange#value}.
42+
*/
43+
@AliasFor(annotation = HttpExchange.class)
44+
String[] value() default {};
45+
46+
/**
47+
* Alias for {@link HttpExchange#url()}.
48+
*/
49+
@AliasFor(annotation = HttpExchange.class)
50+
String[] url() default {};
51+
52+
/**
53+
* Alias for {@link HttpExchange#contentType()}.
54+
*/
55+
@AliasFor(annotation = HttpExchange.class)
56+
String contentType() default "";
57+
58+
/**
59+
* Alias for {@link HttpExchange#accept()}.
60+
*/
61+
@AliasFor(annotation = HttpExchange.class)
62+
String[] accept() default {};
63+
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.service.annotation;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
import org.springframework.core.annotation.AliasFor;
26+
27+
28+
/**
29+
* Shortcut for {@link HttpExchange} for HTTP HEAD requests.
30+
*
31+
* @author Rossen Stoyanchev
32+
* @since 6.0
33+
*/
34+
@Target(ElementType.METHOD)
35+
@Retention(RetentionPolicy.RUNTIME)
36+
@Documented
37+
@HttpExchange(method = "HEAD")
38+
public @interface HeadExchange {
39+
40+
/**
41+
* Alias for {@link HttpExchange#value}.
42+
*/
43+
@AliasFor(annotation = HttpExchange.class)
44+
String value() default "";
45+
46+
/**
47+
* Alias for {@link HttpExchange#url()}.
48+
*/
49+
@AliasFor(annotation = HttpExchange.class)
50+
String url() default "";
51+
52+
/**
53+
* Alias for {@link HttpExchange#accept()}.
54+
*/
55+
@AliasFor(annotation = HttpExchange.class)
56+
String[] accept() default {};
57+
58+
}

spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchange.java

+34-8
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,47 @@
2525
import org.springframework.core.annotation.AliasFor;
2626
import org.springframework.web.bind.annotation.Mapping;
2727

28+
2829
/**
29-
* Supported method parameters:
30+
* Annotation that declares an HTTP service method as an HTTP endpoint defined
31+
* through attributes of the annotation and method argument values.
32+
*
33+
* <p>The annotation may only be used at the type level for example to specify
34+
* a base URL path. At the method level, use one of the HTTP method specific,
35+
* shortcut annotations, each of which is <em>meta-annotated</em> with
36+
* {@link HttpExchange}:
3037
* <ul>
31-
* <li>{@link java.net.URI} -- dynamic URL
32-
* <li>{@link org.springframework.http.HttpMethod} - dynamic HTTP method
33-
* <li>{@link org.springframework.http.HttpHeaders} - request headers
34-
* <li>{@link org.springframework.http.HttpCookie} - request headers
35-
* <li>...
38+
* <li>{@link GetExchange}
39+
* <li>{@link PostExchange}
40+
* <li>{@link PutExchange}
41+
* <li>{@link PatchExchange}
42+
* <li>{@link DeleteExchange}
43+
* <li>{@link OptionsExchange}
44+
* <li>{@link HeadExchange}
3645
* </ul>
3746
*
47+
* <p>Supported method arguments:
48+
* <table>
49+
* <tr>
50+
* <th>Method Argument</th>
51+
* <th>Description</th>
52+
* </tr>
53+
* <tr>
54+
* <td>{@link org.springframework.http.HttpMethod}</td>
55+
* <td>Set the HTTP method for the request, overriding the annotation
56+
* {@link #method()} attribute value</td>
57+
* </tr>
58+
* <tr>
59+
* <td>{@link org.springframework.web.bind.annotation.PathVariable @PathVariable}</td>
60+
* <td>Provide a path variable to expand the URI template with. This may be an
61+
* individual value or a Map of values.</td>
62+
* </tr>
63+
* </table>
64+
*
3865
* @author Rossen Stoyanchev
3966
* @since 6.0
4067
*/
41-
@Target({ElementType.TYPE, ElementType.METHOD})
68+
@Target(ElementType.TYPE)
4269
@Retention(RetentionPolicy.RUNTIME)
4370
@Documented
4471
@Mapping
@@ -83,5 +110,4 @@
83110
*/
84111
String[] accept() default {};
85112

86-
87113
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.service.annotation;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
import org.springframework.core.annotation.AliasFor;
26+
27+
28+
/**
29+
* Shortcut for {@link HttpExchange} for HTTP OPTIONS requests.
30+
*
31+
* @author Rossen Stoyanchev
32+
* @since 6.0
33+
*/
34+
@Target(ElementType.METHOD)
35+
@Retention(RetentionPolicy.RUNTIME)
36+
@Documented
37+
@HttpExchange(method = "OPTIONS")
38+
public @interface OptionsExchange {
39+
40+
/**
41+
* Alias for {@link HttpExchange#value}.
42+
*/
43+
@AliasFor(annotation = HttpExchange.class)
44+
String value() default "";
45+
46+
/**
47+
* Alias for {@link HttpExchange#url()}.
48+
*/
49+
@AliasFor(annotation = HttpExchange.class)
50+
String url() default "";
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.service.annotation;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
import org.springframework.core.annotation.AliasFor;
26+
27+
28+
/**
29+
* Shortcut for {@link HttpExchange} for HTTP PATCH requests.
30+
*
31+
* @author Rossen Stoyanchev
32+
* @since 6.0
33+
*/
34+
@Target(ElementType.METHOD)
35+
@Retention(RetentionPolicy.RUNTIME)
36+
@Documented
37+
@HttpExchange(method = "PATCH")
38+
public @interface PatchExchange {
39+
40+
/**
41+
* Alias for {@link HttpExchange#value}.
42+
*/
43+
@AliasFor(annotation = HttpExchange.class)
44+
String[] value() default {};
45+
46+
/**
47+
* Alias for {@link HttpExchange#url()}.
48+
*/
49+
@AliasFor(annotation = HttpExchange.class)
50+
String[] url() default {};
51+
52+
/**
53+
* Alias for {@link HttpExchange#contentType()}.
54+
*/
55+
@AliasFor(annotation = HttpExchange.class)
56+
String contentType() default "";
57+
58+
/**
59+
* Alias for {@link HttpExchange#accept()}.
60+
*/
61+
@AliasFor(annotation = HttpExchange.class)
62+
String[] accept() default {};
63+
64+
}

spring-web/src/main/java/org/springframework/web/service/annotation/PutExchange.java

+6
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,10 @@
5555
@AliasFor(annotation = HttpExchange.class)
5656
String contentType() default "";
5757

58+
/**
59+
* Alias for {@link HttpExchange#accept()}.
60+
*/
61+
@AliasFor(annotation = HttpExchange.class)
62+
String[] accept() default {};
63+
5864
}

spring-web/src/main/java/org/springframework/web/service/invoker/HttpClientAdapter.java

+40
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,58 @@
3333
*/
3434
public interface HttpClientAdapter {
3535

36+
/**
37+
* Perform the given request, and release the response content, if any.
38+
* @param requestValues the request to perform
39+
* @return {@code Mono} that completes when the request is fully executed
40+
* and the response content is released.
41+
*/
3642
Mono<Void> requestToVoid(HttpRequestValues requestValues);
3743

44+
/**
45+
* Perform the given request, release the response content, and return the
46+
* response headers.
47+
* @param requestValues the request to perform
48+
* @return {@code Mono} that returns the response headers the request is
49+
* fully executed and the response content released.
50+
*/
3851
Mono<HttpHeaders> requestToHeaders(HttpRequestValues requestValues);
3952

53+
/**
54+
* Perform the given request and decode the response content to the given type.
55+
* @param requestValues the request to perform
56+
* @param bodyType the target type to decode to
57+
* @return {@code Mono} that returns the decoded response.
58+
* @param <T> the type the response is decoded to
59+
*/
4060
<T> Mono<T> requestToBody(HttpRequestValues requestValues, ParameterizedTypeReference<T> bodyType);
4161

62+
/**
63+
* Perform the given request and decode the response content to a stream with
64+
* elements of the given type.
65+
* @param requestValues the request to perform
66+
* @param bodyType the target stream element type to decode to
67+
* @return {@code Flux} with decoded stream elements.
68+
* @param <T> the type the response is decoded to
69+
*/
4270
<T> Flux<T> requestToBodyFlux(HttpRequestValues requestValues, ParameterizedTypeReference<T> bodyType);
4371

72+
/**
73+
* Variant of {@link #requestToVoid(HttpRequestValues)} with additional
74+
* access to the response status and headers.
75+
*/
4476
Mono<ResponseEntity<Void>> requestToBodilessEntity(HttpRequestValues requestValues);
4577

78+
/**
79+
* Variant of {@link #requestToBody(HttpRequestValues, ParameterizedTypeReference)}
80+
* with additional access to the response status and headers.
81+
*/
4682
<T> Mono<ResponseEntity<T>> requestToEntity(HttpRequestValues requestValues, ParameterizedTypeReference<T> bodyType);
4783

84+
/**
85+
* Variant of {@link #requestToBodyFlux(HttpRequestValues, ParameterizedTypeReference)}
86+
* with additional access to the response status and headers.
87+
*/
4888
<T> Mono<ResponseEntity<Flux<T>>> requestToEntityFlux(HttpRequestValues requestValues, ParameterizedTypeReference<T> bodyType);
4989

5090
}

0 commit comments

Comments
 (0)