Skip to content

Commit

Permalink
Switch to Reactor Netty 2 snapshots
Browse files Browse the repository at this point in the history
Update to Reactor BOM 2022.0.0-SNAPSHOT.
Process package changes.
Adapt to new `HttpHeaders` API.
Adapt to new cookies API.

See gh-29247
  • Loading branch information
violetagg authored and rstoyanchev committed Oct 3, 2022
1 parent 1b1682e commit b5adae2
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 90 deletions.
4 changes: 2 additions & 2 deletions framework-platform/framework-platform.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ dependencies {
api(platform("com.fasterxml.jackson:jackson-bom:2.13.4"))
api(platform("io.micrometer:micrometer-bom:1.10.0-M6"))
api(platform("io.netty:netty-bom:4.1.82.Final"))
api(platform("io.netty:netty5-bom:5.0.0.Alpha3"))
api(platform("io.projectreactor:reactor-bom:2022.0.0-M6"))
api(platform("io.netty:netty5-bom:5.0.0.Alpha5"))
api(platform("io.projectreactor:reactor-bom:2022.0.0-SNAPSHOT"))
api(platform("io.rsocket:rsocket-bom:1.1.3"))
api(platform("org.apache.groovy:groovy-bom:4.0.5"))
api(platform("org.apache.logging.log4j:log4j-bom:2.19.0"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.util.Map;

import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.api.DefaultBufferAllocators;
import io.netty5.buffer.Buffer;
import io.netty5.buffer.DefaultBufferAllocators;

import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Map;

import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.Buffer;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.nio.charset.StandardCharsets;
import java.util.function.IntPredicate;

import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.Buffer;
import io.netty5.util.AsciiString;

import org.springframework.lang.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import java.nio.ByteBuffer;
import java.util.List;

import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.api.BufferAllocator;
import io.netty5.buffer.api.CompositeBuffer;
import io.netty5.buffer.api.DefaultBufferAllocators;
import io.netty5.buffer.Buffer;
import io.netty5.buffer.BufferAllocator;
import io.netty5.buffer.CompositeBuffer;
import io.netty5.buffer.DefaultBufferAllocators;

import org.springframework.util.Assert;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;

import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.api.DefaultBufferAllocators;
import io.netty5.buffer.Buffer;
import io.netty5.buffer.DefaultBufferAllocators;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.nio.charset.StandardCharsets;

import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.api.DefaultBufferAllocators;
import io.netty5.buffer.Buffer;
import io.netty5.buffer.DefaultBufferAllocators;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.PooledByteBufAllocatorMetric;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty5.buffer.api.BufferAllocator;
import io.netty5.buffer.BufferAllocator;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down
2 changes: 1 addition & 1 deletion spring-messaging/spring-messaging.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
optional(project(":spring-context"))
optional(project(":spring-oxm"))
optional("io.projectreactor.netty:reactor-netty-http")
optional("io.projectreactor.netty:reactor-netty5-http:2.0.0-M1")
optional("io.projectreactor.netty:reactor-netty5-http")
optional("io.rsocket:rsocket-core")
optional("io.rsocket:rsocket-transport-netty")
optional("com.fasterxml.jackson.core:jackson-databind")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.function.BiFunction;
import java.util.function.Function;

import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.Buffer;
import io.netty5.channel.ChannelHandlerContext;
import io.netty5.channel.group.ChannelGroup;
import io.netty5.channel.group.DefaultChannelGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;

import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.Buffer;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;
import reactor.netty5.NettyInbound;
Expand Down
2 changes: 1 addition & 1 deletion spring-web/spring-web.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
optional("io.netty:netty5-handler")
optional("io.netty:netty5-codec-http")
optional("io.netty:netty5-transport")
optional("io.projectreactor.netty:reactor-netty5-http:2.0.0-M1")
optional("io.projectreactor.netty:reactor-netty5-http")
optional("io.undertow:undertow-core")
optional("org.apache.tomcat.embed:tomcat-embed-core")
optional("org.eclipse.jetty:jetty-server") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
package org.springframework.http.client.reactive;

import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.StreamSupport;

import io.netty5.handler.codec.http.HttpHeaders;
import io.netty5.handler.codec.http.headers.HttpHeaders;

import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -52,7 +56,8 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
@Override
@Nullable
public String getFirst(String key) {
return this.headers.get(key);
CharSequence value = this.headers.get(key);
return value != null ? value.toString() : null;
}

@Override
Expand Down Expand Up @@ -87,12 +92,11 @@ public void setAll(Map<String, String> values) {
@Override
public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
this.headers.entries()
.forEach(entry -> {
if (!singleValueMap.containsKey(entry.getKey())) {
singleValueMap.put(entry.getKey(), entry.getValue());
}
});
this.headers.forEach(entry -> {
if (!singleValueMap.containsKey(entry.getKey())) {
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString());
}
});
return singleValueMap;
}

Expand All @@ -114,23 +118,24 @@ public boolean containsKey(Object key) {
@Override
public boolean containsValue(Object value) {
return (value instanceof String &&
this.headers.entries().stream()
StreamSupport.stream(
Spliterators.spliteratorUnknownSize(this.headers.iterator(), Spliterator.ORDERED), false)
.anyMatch(entry -> value.equals(entry.getValue())));
}

@Override
@Nullable
public List<String> get(Object key) {
if (containsKey(key)) {
return this.headers.getAll((String) key);
return getAll(this.headers.valuesIterator((CharSequence) key));
}
return null;
}

@Nullable
@Override
public List<String> put(String key, @Nullable List<String> value) {
List<String> previousValues = this.headers.getAll(key);
List<String> previousValues = getAll(this.headers.valuesIterator(key));
this.headers.set(key, value);
return previousValues;
}
Expand All @@ -139,7 +144,7 @@ public List<String> put(String key, @Nullable List<String> value) {
@Override
public List<String> remove(Object key) {
if (key instanceof String headerName) {
List<String> previousValues = this.headers.getAll(headerName);
List<String> previousValues = getAll(this.headers.valuesIterator(headerName));
this.headers.remove(headerName);
return previousValues;
}
Expand All @@ -164,7 +169,7 @@ public Set<String> keySet() {
@Override
public Collection<List<String>> values() {
return this.headers.names().stream()
.map(this.headers::getAll).toList();
.map(key -> getAll(this.headers.valuesIterator(key))).toList();
}

@Override
Expand All @@ -189,9 +194,22 @@ public String toString() {
}


@Nullable
private static List<String> getAll(Iterator<CharSequence> valuesIterator) {
if (!valuesIterator.hasNext()) {
return null;
}
List<String> result = new ArrayList<>();
while (valuesIterator.hasNext()) {
result.add(valuesIterator.next().toString());
}
return result;
}


private class EntryIterator implements Iterator<Entry<String, List<String>>> {

private final Iterator<String> names = headers.names().iterator();
private final Iterator<CharSequence> names = headers.names().iterator();

@Override
public boolean hasNext() {
Expand All @@ -207,25 +225,30 @@ public Entry<String, List<String>> next() {

private class HeaderEntry implements Entry<String, List<String>> {

private final String key;
private final CharSequence key;

HeaderEntry(String key) {
HeaderEntry(CharSequence key) {
this.key = key;
}

@Override
public String getKey() {
return this.key;
return this.key.toString();
}

@Override
public List<String> getValue() {
return headers.getAll(this.key);
List<String> result = new ArrayList<>();
Iterator<CharSequence> valuesIterator = headers.valuesIterator(this.key);
while (valuesIterator.hasNext()) {
result.add(valuesIterator.next().toString());
}
return result;
}

@Override
public List<String> setValue(List<String> value) {
List<String> previousValues = headers.getAll(this.key);
List<String> previousValues = getValue();
headers.set(this.key, value);
return previousValues;
}
Expand All @@ -247,12 +270,12 @@ public int size() {

private final class HeaderNamesIterator implements Iterator<String> {

private final Iterator<String> iterator;
private final Iterator<CharSequence> iterator;

@Nullable
private String currentName;
private CharSequence currentName;

private HeaderNamesIterator(Iterator<String> iterator) {
private HeaderNamesIterator(Iterator<CharSequence> iterator) {
this.iterator = iterator;
}

Expand All @@ -264,7 +287,7 @@ public boolean hasNext() {
@Override
public String next() {
this.currentName = this.iterator.next();
return this.currentName;
return this.currentName.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.nio.file.Path;
import java.util.Collection;

import io.netty5.buffer.api.Buffer;
import io.netty5.handler.codec.http.cookie.DefaultCookie;
import io.netty5.buffer.Buffer;
import io.netty5.handler.codec.http.headers.DefaultHttpCookiePair;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -131,7 +131,7 @@ protected void applyHeaders() {
@Override
protected void applyCookies() {
getCookies().values().stream().flatMap(Collection::stream)
.map(cookie -> new DefaultCookie(cookie.getName(), cookie.getValue()))
.map(cookie -> new DefaultHttpCookiePair(cookie.getName(), cookie.getValue()))
.forEach(this.request::addCookie);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;

import io.netty5.handler.codec.http.cookie.Cookie;
import io.netty5.handler.codec.http.cookie.DefaultCookie;
import io.netty5.handler.codec.http.headers.DefaultHttpSetCookie;
import io.netty5.handler.codec.http.headers.HttpSetCookie;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -129,11 +129,11 @@ public MultiValueMap<String, ResponseCookie> getCookies() {
MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>();
this.response.cookies().values().stream()
.flatMap(Collection::stream)
.forEach(cookie -> result.add(cookie.name(),
ResponseCookie.fromClientResponse(cookie.name(), cookie.value())
.domain(cookie.domain())
.path(cookie.path())
.maxAge(cookie.maxAge())
.forEach(cookie -> result.add(cookie.name().toString(),
ResponseCookie.fromClientResponse(cookie.name().toString(), cookie.value().toString())
.domain(cookie.domain() != null ? cookie.domain().toString() : null)
.path(cookie.path() != null ? cookie.path().toString() : null)
.maxAge(cookie.maxAge() != null ? cookie.maxAge() : -1L)
.secure(cookie.isSecure())
.httpOnly(cookie.isHttpOnly())
.sameSite(getSameSite(cookie))
Expand All @@ -142,8 +142,8 @@ public MultiValueMap<String, ResponseCookie> getCookies() {
}

@Nullable
private static String getSameSite(Cookie cookie) {
if (cookie instanceof DefaultCookie defaultCookie) {
private static String getSameSite(HttpSetCookie cookie) {
if (cookie instanceof DefaultHttpSetCookie defaultCookie) {
if (defaultCookie.sameSite() != null) {
return defaultCookie.sameSite().name();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
protobufPresent = ClassUtils.isPresent("com.google.protobuf.Message", classLoader);
synchronossMultipartPresent = ClassUtils.isPresent("org.synchronoss.cloud.nio.multipart.NioMultipartParser", classLoader);
nettyByteBufPresent = ClassUtils.isPresent("io.netty.buffer.ByteBuf", classLoader);
netty5BufferPresent = ClassUtils.isPresent("io.netty5.buffer.api.Buffer", classLoader);
netty5BufferPresent = ClassUtils.isPresent("io.netty5.buffer.Buffer", classLoader);
kotlinSerializationJsonPresent = ClassUtils.isPresent("kotlinx.serialization.json.Json", classLoader);
}

Expand Down
Loading

0 comments on commit b5adae2

Please sign in to comment.