Skip to content

Commit c418768

Browse files
committed
Add @HTTPRequest and HttpServiceProxyFactory
See gh-28386
1 parent 5378572 commit c418768

File tree

16 files changed

+1660
-0
lines changed

16 files changed

+1660
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
*
30+
* @author Rossen Stoyanchev
31+
* @since 6.0
32+
*/
33+
@Target(ElementType.METHOD)
34+
@Retention(RetentionPolicy.RUNTIME)
35+
@Documented
36+
@HttpRequest(method = "GET")
37+
public @interface GetRequest {
38+
39+
/**
40+
* Alias for {@link HttpRequest#value}.
41+
*/
42+
@AliasFor(annotation = HttpRequest.class)
43+
String value() default "";
44+
45+
/**
46+
* Alias for {@link HttpRequest#url()}.
47+
*/
48+
@AliasFor(annotation = HttpRequest.class)
49+
String url() default "";
50+
51+
/**
52+
* Alias for {@link HttpRequest#accept()}.
53+
*/
54+
@AliasFor(annotation = HttpRequest.class)
55+
String[] accept() default {};
56+
57+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
import org.springframework.web.bind.annotation.Mapping;
27+
28+
/**
29+
* Supported method parameters:
30+
* <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>...
36+
* </ul>
37+
*
38+
* @author Rossen Stoyanchev
39+
* @since 6.0
40+
*/
41+
@Target({ElementType.TYPE, ElementType.METHOD})
42+
@Retention(RetentionPolicy.RUNTIME)
43+
@Documented
44+
@Mapping
45+
public @interface HttpRequest {
46+
47+
/**
48+
* This is an alias for {@link #url}.
49+
*/
50+
@AliasFor("url")
51+
String value() default "";
52+
53+
/**
54+
* The URL for the request, either a full URL or a path only that is relative
55+
* to a URL declared in a type-level {@code @HttpRequest}, and/or a globally
56+
* configured base URL.
57+
* <p>By default, this is empty.
58+
*/
59+
@AliasFor("value")
60+
String url() default "";
61+
62+
/**
63+
* The HTTP method to use.
64+
* <p>Supported at the type level as well as at the method level.
65+
* When used at the type level, all method-level mappings inherit this value.
66+
* <p>By default, this is empty.
67+
*/
68+
String method() default "";
69+
70+
71+
/**
72+
* The media type for the {@code "Content-Type"} header.
73+
* <p>Supported at the type level as well as at the method level, in which
74+
* case the method-level values override type-level values.
75+
* <p>By default, this is empty.
76+
*/
77+
String contentType() default "";
78+
79+
/**
80+
* The media types for the {@code "Accept"} header.
81+
* <p>Supported at the type level as well as at the method level, in which
82+
* case the method-level values override type-level values.
83+
* <p>By default, this is empty.
84+
*/
85+
String[] accept() default {};
86+
87+
88+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
* @author Rossen Stoyanchev
30+
* @since 6.0
31+
*/
32+
@Target(ElementType.METHOD)
33+
@Retention(RetentionPolicy.RUNTIME)
34+
@Documented
35+
@HttpRequest(method = "POST")
36+
public @interface PostRequest {
37+
38+
/**
39+
* Alias for {@link HttpRequest#value}.
40+
*/
41+
@AliasFor(annotation = HttpRequest.class)
42+
String value() default "";
43+
44+
/**
45+
* Alias for {@link HttpRequest#url()}.
46+
*/
47+
@AliasFor(annotation = HttpRequest.class)
48+
String url() default "";
49+
50+
/**
51+
* Alias for {@link HttpRequest#contentType()}.
52+
*/
53+
@AliasFor(annotation = HttpRequest.class)
54+
String contentType() default "";
55+
56+
/**
57+
* Alias for {@link HttpRequest#accept()}.
58+
*/
59+
@AliasFor(annotation = HttpRequest.class)
60+
String[] accept() default {};
61+
62+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
* @author Rossen Stoyanchev
30+
* @since 6.0
31+
*/
32+
@Target(ElementType.METHOD)
33+
@Retention(RetentionPolicy.RUNTIME)
34+
@Documented
35+
@HttpRequest(method = "PUT")
36+
public @interface PutRequest {
37+
38+
/**
39+
* Alias for {@link HttpRequest#value}.
40+
*/
41+
@AliasFor(annotation = HttpRequest.class)
42+
String[] value() default {};
43+
44+
/**
45+
* Alias for {@link HttpRequest#url()}.
46+
*/
47+
@AliasFor(annotation = HttpRequest.class)
48+
String[] url() default {};
49+
50+
/**
51+
* Alias for {@link HttpRequest#contentType()}.
52+
*/
53+
@AliasFor(annotation = HttpRequest.class)
54+
String contentType() default "";
55+
56+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Annotations to declare HTTP service, request methods.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.web.service.annotation;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.invoker;
18+
19+
import reactor.core.publisher.Flux;
20+
import reactor.core.publisher.Mono;
21+
22+
import org.springframework.core.ParameterizedTypeReference;
23+
import org.springframework.http.HttpHeaders;
24+
import org.springframework.http.ResponseEntity;
25+
26+
27+
/**
28+
* Decouple an {@link HttpServiceProxyFactory#createService(Class) HTTP Service proxy}
29+
* from the underlying HTTP client.
30+
*
31+
* @author Rossen Stoyanchev
32+
* @since 6.0
33+
*/
34+
public interface HttpClientAdapter {
35+
36+
Mono<Void> requestToVoid(HttpRequestDefinition requestDefinition);
37+
38+
Mono<HttpHeaders> requestToHeaders(HttpRequestDefinition requestDefinition);
39+
40+
<T> Mono<T> requestToBody(HttpRequestDefinition requestDefinition, ParameterizedTypeReference<T> bodyType);
41+
42+
<T> Flux<T> requestToBodyFlux(HttpRequestDefinition requestDefinition, ParameterizedTypeReference<T> bodyType);
43+
44+
Mono<ResponseEntity<Void>> requestToBodilessEntity(HttpRequestDefinition requestDefinition);
45+
46+
<T> Mono<ResponseEntity<T>> requestToEntity(HttpRequestDefinition requestDefinition, ParameterizedTypeReference<T> bodyType);
47+
48+
<T> Mono<ResponseEntity<Flux<T>>> requestToEntityFlux(HttpRequestDefinition requestDefinition, ParameterizedTypeReference<T> bodyType);
49+
50+
}

0 commit comments

Comments
 (0)