Add base contracts for the Web client

This commit adds the base contracts for the Web client.
The "Reactive" prefixes of the previously commited contracts has been
removed to match the server ones.

Both the `ClientHttpRequest` and the `ServerHttpResponse` extend
`ReactiveHttpOutputMessage`, which now has a `beforeCommit` method,
necessary in both client and server implementations.

`HttpRequestBuilder` will be used by the developers to create requests
with a nice builder API. `ClientHttpRequestFactory` will provide support
for many HTTP client libraries in this new client.
This commit is contained in:
Brian Clozel 2016-02-01 15:37:52 +01:00
parent a4be950e37
commit 0983d302c7
9 changed files with 149 additions and 47 deletions

View File

@ -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<? extends Mono<Void>> action);
/**
* Set the body of the message to the given {@link Publisher} which will be
* used to write to the underlying HTTP layer.

View File

@ -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;

View File

@ -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<ClientHttpResponse>} 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<ClientHttpResponse> execute();
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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;

View File

@ -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
*/

View File

@ -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<? extends Mono<Void>> action);
/**
* Indicate that request handling is complete, allowing for any cleanup or
* end-of-processing tasks to be performed such as applying header changes

View File

@ -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);
}