Browse Source

Polishing

pull/1460/head
Juergen Hoeller 9 years ago
parent
commit
137fc48cc2
  1. 4
      spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java
  2. 6
      spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java
  3. 3
      spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpRequestDecorator.java
  4. 4
      spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpResponseDecorator.java
  5. 6
      spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java
  6. 11
      spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java
  7. 11
      spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java

4
spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java

@ -55,7 +55,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
private final MultiValueMap<String, HttpCookie> cookies; private final MultiValueMap<String, HttpCookie> cookies;
private AtomicReference<State> state = new AtomicReference<>(State.NEW); private final AtomicReference<State> state = new AtomicReference<>(State.NEW);
private final List<Supplier<? extends Mono<Void>>> commitActions = new ArrayList<>(4); private final List<Supplier<? extends Mono<Void>>> commitActions = new ArrayList<>(4);
@ -95,7 +95,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
@Override @Override
public boolean isCommitted() { public boolean isCommitted() {
return this.state.get() != State.NEW; return (this.state.get() != State.NEW);
} }
/** /**

6
spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.http.client.reactive; package org.springframework.http.client.reactive;
import java.net.URI; import java.net.URI;
@ -37,7 +38,6 @@ public interface ClientHttpConnector {
* {@code URI}, then apply the given {@code requestCallback} on the * {@code URI}, then apply the given {@code requestCallback} on the
* {@link ClientHttpRequest} once the connection has been established. * {@link ClientHttpRequest} once the connection has been established.
* <p>Return a publisher of the {@link ClientHttpResponse}. * <p>Return a publisher of the {@link ClientHttpResponse}.
*
* @param method the HTTP request method * @param method the HTTP request method
* @param uri the HTTP request URI * @param uri the HTTP request URI
* @param requestCallback a function that prepares and writes the request, * @param requestCallback a function that prepares and writes the request,
@ -49,4 +49,4 @@ public interface ClientHttpConnector {
Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
Function<? super ClientHttpRequest, Mono<Void>> requestCallback); Function<? super ClientHttpRequest, Mono<Void>> requestCallback);
} }

3
spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpRequestDecorator.java

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.http.client.reactive; package org.springframework.http.client.reactive;
import java.net.URI; import java.net.URI;
@ -42,7 +43,7 @@ public class ClientHttpRequestDecorator implements ClientHttpRequest {
public ClientHttpRequestDecorator(ClientHttpRequest delegate) { public ClientHttpRequestDecorator(ClientHttpRequest delegate) {
Assert.notNull(delegate, "ClientHttpRequest delegate is required."); Assert.notNull(delegate, "Delegate is required");
this.delegate = delegate; this.delegate = delegate;
} }

4
spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpResponseDecorator.java

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.http.client.reactive; package org.springframework.http.client.reactive;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
@ -37,7 +38,7 @@ public class ClientHttpResponseDecorator implements ClientHttpResponse {
public ClientHttpResponseDecorator(ClientHttpResponse delegate) { public ClientHttpResponseDecorator(ClientHttpResponse delegate) {
Assert.notNull(delegate, "ClientHttpResponse delegate is required."); Assert.notNull(delegate, "Delegate is required");
this.delegate = delegate; this.delegate = delegate;
} }
@ -49,7 +50,6 @@ public class ClientHttpResponseDecorator implements ClientHttpResponse {
// ServerHttpResponse delegation methods... // ServerHttpResponse delegation methods...
@Override @Override
public HttpStatus getStatusCode() { public HttpStatus getStatusCode() {
return this.delegate.getStatusCode(); return this.delegate.getStatusCode();

6
spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java

@ -21,14 +21,14 @@ import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.ipc.netty.http.client.HttpClient;
import reactor.ipc.netty.http.client.HttpClientOptions; import reactor.ipc.netty.http.client.HttpClientOptions;
import reactor.ipc.netty.options.ClientOptions; import reactor.ipc.netty.options.ClientOptions;
import reactor.ipc.netty.http.client.HttpClient;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
/** /**
* Reactor-Netty implementation of {@link ClientHttpConnector} * Reactor-Netty implementation of {@link ClientHttpConnector}.
* *
* @author Brian Clozel * @author Brian Clozel
* @see HttpClient * @see HttpClient
@ -59,7 +59,7 @@ public class ReactorClientHttpConnector implements ClientHttpConnector {
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
Function<? super ClientHttpRequest, Mono<Void>> requestCallback) { Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
return httpClient return this.httpClient
.request(io.netty.handler.codec.http.HttpMethod.valueOf(method.name()), .request(io.netty.handler.codec.http.HttpMethod.valueOf(method.name()),
uri.toString(), uri.toString(),
httpClientRequest -> requestCallback httpClientRequest -> requestCallback

11
spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java

@ -81,14 +81,12 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest {
@Override @Override
public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) { public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) {
Publisher<Publisher<ByteBuf>> byteBufs = Flux.from(body). Publisher<Publisher<ByteBuf>> byteBufs = Flux.from(body).map(ReactorClientHttpRequest::toByteBufs);
map(ReactorClientHttpRequest::toByteBufs);
return doCommit(() -> this.httpRequest.sendGroups(byteBufs).then()); return doCommit(() -> this.httpRequest.sendGroups(byteBufs).then());
} }
private static Publisher<ByteBuf> toByteBufs(Publisher<? extends DataBuffer> dataBuffers) { private static Publisher<ByteBuf> toByteBufs(Publisher<? extends DataBuffer> dataBuffers) {
return Flux.from(dataBuffers). return Flux.from(dataBuffers).map(NettyDataBufferFactory::toByteBuf);
map(NettyDataBufferFactory::toByteBuf);
} }
@Override @Override
@ -98,8 +96,7 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest {
@Override @Override
protected void applyHeaders() { protected void applyHeaders() {
getHeaders().entrySet() getHeaders().entrySet().forEach(e -> this.httpRequest.requestHeaders().set(e.getKey(), e.getValue()));
.forEach(e -> this.httpRequest.requestHeaders().set(e.getKey(), e.getValue()));
} }
@Override @Override
@ -109,4 +106,4 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest {
.forEach(this.httpRequest::addCookie); .forEach(this.httpRequest::addCookie);
} }
} }

11
spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -62,8 +62,7 @@ public class ReactorClientHttpResponse implements ClientHttpResponse {
@Override @Override
public HttpHeaders getHeaders() { public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
this.response.responseHeaders() this.response.responseHeaders().entries()
.entries()
.forEach(e -> headers.add(e.getKey(), e.getValue())); .forEach(e -> headers.add(e.getKey(), e.getValue()));
return headers; return headers;
} }
@ -90,12 +89,12 @@ public class ReactorClientHttpResponse implements ClientHttpResponse {
return CollectionUtils.unmodifiableMultiValueMap(result); return CollectionUtils.unmodifiableMultiValueMap(result);
} }
@Override @Override
public String toString() { public String toString() {
return "ReactorClientHttpResponse{" + return "ReactorClientHttpResponse{" +
"request=" + this.response.method().name() + " " + this.response.uri() + "," + "request=[" + this.response.method().name() + " " + this.response.uri() + "]," +
"status=" + getStatusCode() + "status=" + getStatusCode() + '}';
'}';
} }
} }

Loading…
Cancel
Save