diff --git a/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java b/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java index ec4e63c1927..fb6b06150b7 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java @@ -16,6 +16,8 @@ package org.springframework.http; +import java.util.function.Supplier; + import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -31,6 +33,12 @@ import org.springframework.core.io.buffer.DataBuffer; */ public interface ReactiveHttpOutputMessage extends HttpMessage { + /** + * Register an action to be applied just before the message is committed. + * @param action the action + */ + void beforeCommit(Supplier> action); + /** * Set the body of the message to the given {@link Publisher} which will be * used to write to the underlying HTTP layer. diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/package-info.java b/spring-web-reactive/src/main/java/org/springframework/http/client/package-info.java deleted file mode 100644 index 418d5045f87..00000000000 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Core package of the client-side web support. - * Provides a {@code RestTemplate} class and various callback interfaces. - */ -package org.springframework.http.client; diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpRequest.java new file mode 100644 index 00000000000..32c38940aef --- /dev/null +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpRequest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2002-2016 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 + * + * http://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.http.client.reactive; + +import java.net.URI; + +import reactor.core.publisher.Mono; + +import org.springframework.http.HttpMethod; +import org.springframework.http.ReactiveHttpOutputMessage; + +/** + * Represents a reactive client-side HTTP request. + * + * @author Arjen Poutsma + * @author Brian Clozel + */ +public interface ClientHttpRequest extends ReactiveHttpOutputMessage { + + /** + * Return the HTTP method of the request. + */ + HttpMethod getMethod(); + + /** + * Return the URI of the request. + */ + URI getURI(); + + /** + * Execute this request, resulting in a reactive stream of a single + * {@link org.springframework.http.client.ClientHttpResponse}. + * + * @return a {@code Mono} that signals when the the response + * status and headers have been received. The response body is made available with + * a separate Publisher within the {@code ClientHttpResponse}. + */ + Mono execute(); + +} diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpRequestFactory.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpRequestFactory.java new file mode 100644 index 00000000000..4eea06aeecc --- /dev/null +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpRequestFactory.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2016 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 + * + * http://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.http.client.reactive; + +import java.net.URI; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; + +/** + * Factory for {@link ClientHttpRequest} objects. + * + * @author Brian Clozel + */ +public interface ClientHttpRequestFactory { + + /** + * Create a new {@link ClientHttpRequest} for the specified HTTP method, URI and headers + * + * @param httpMethod the HTTP method to execute + * @param uri the URI to create a request for + * @param headers the HTTP request headers + */ + ClientHttpRequest createRequest(HttpMethod httpMethod, URI uri, HttpHeaders headers); + +} diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/ReactiveClientHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpResponse.java similarity index 60% rename from spring-web-reactive/src/main/java/org/springframework/http/client/ReactiveClientHttpResponse.java rename to spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpResponse.java index ae4b7fa0de3..34cad69c105 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/ReactiveClientHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -14,34 +14,21 @@ * limitations under the License. */ -package org.springframework.http.client; +package org.springframework.http.client.reactive; import org.springframework.http.HttpStatus; import org.springframework.http.ReactiveHttpInputMessage; /** - * Represents a "reactive" client-side HTTP response. + * Represents a reactive client-side HTTP response. * * @author Arjen Poutsma */ -public interface ReactiveClientHttpResponse extends ReactiveHttpInputMessage { +public interface ClientHttpResponse extends ReactiveHttpInputMessage { /** - * Return the HTTP status code of the response. * @return the HTTP status as an {@link HttpStatus} enum value */ HttpStatus getStatusCode(); - /** - * Return the HTTP status code of the response as integer - * @return the HTTP status as an integer - */ - int getRawStatusCode(); - - /** - * Return the HTTP status text of the response. - * @return the HTTP status text - */ - String getStatusText(); - } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/ReactiveClientHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/package-info.java similarity index 60% rename from spring-web-reactive/src/main/java/org/springframework/http/client/ReactiveClientHttpRequest.java rename to spring-web-reactive/src/main/java/org/springframework/http/client/reactive/package-info.java index 591a0177275..64e63d30de9 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/ReactiveClientHttpRequest.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -14,16 +14,10 @@ * limitations under the License. */ -package org.springframework.http.client; - -import org.springframework.http.HttpRequest; -import org.springframework.http.ReactiveHttpOutputMessage; - /** - * Represents a "reactive" client-side HTTP request. - * - * @author Arjen Poutsma + * Core package of the reactive client HTTP support. + * Provides {@link org.springframework.http.client.reactive.ClientHttpRequest} + * and {@link org.springframework.http.client.reactive.ClientHttpResponse} + * interfaces and their implementations */ -public interface ReactiveClientHttpRequest extends HttpRequest, ReactiveHttpOutputMessage { - -} +package org.springframework.http.client.reactive; diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java index 1cbbfbfb000..90a52dd13c8 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -20,7 +20,7 @@ import org.springframework.http.HttpRequest; import org.springframework.http.ReactiveHttpInputMessage; /** - * Represents a "reactive" server-side HTTP request + * Represents a reactive server-side HTTP request * * @author Arjen Poutsma */ diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java index d6c830641a0..c7449eca342 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -16,16 +16,13 @@ package org.springframework.http.server.reactive; -import java.util.function.Supplier; - -import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.http.HttpStatus; import org.springframework.http.ReactiveHttpOutputMessage; /** - * Represents a "reactive" server-side HTTP response. + * Represents a reactive server-side HTTP response. * * @author Arjen Poutsma */ @@ -37,12 +34,6 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage { */ void setStatusCode(HttpStatus status); - /** - * Register an action to be applied just before the response is committed. - * @param action the action - */ - void beforeCommit(Supplier> action); - /** * Indicate that request handling is complete, allowing for any cleanup or * end-of-processing tasks to be performed such as applying header changes diff --git a/spring-web-reactive/src/main/java/org/springframework/web/client/HttpRequestBuilder.java b/spring-web-reactive/src/main/java/org/springframework/web/client/HttpRequestBuilder.java new file mode 100644 index 00000000000..a9717445b9b --- /dev/null +++ b/spring-web-reactive/src/main/java/org/springframework/web/client/HttpRequestBuilder.java @@ -0,0 +1,34 @@ +/* + * Copyright 2002-2016 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 + * + * http://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.client; + +import org.springframework.http.client.reactive.ClientHttpRequest; +import org.springframework.http.client.reactive.ClientHttpRequestFactory; + +/** + * Build {@link ClientHttpRequest} using a {@link ClientHttpRequestFactory} + * which wraps an HTTP client implementation. + * + * @author Brian Clozel + */ +public interface HttpRequestBuilder { + + /** + * Build a {@link ClientHttpRequest} + */ + ClientHttpRequest build(ClientHttpRequestFactory factory); +}