diff --git a/gradle.properties b/gradle.properties index c518716..91f0e9e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = netty-http -version = 4.1.38.0 +version = 4.1.38.1 # main packages netty.version = 4.1.38.Final diff --git a/netty-http-client-rest/build.gradle b/netty-http-client-rest/build.gradle new file mode 100644 index 0000000..e04c2a3 --- /dev/null +++ b/netty-http-client-rest/build.gradle @@ -0,0 +1,3 @@ +dependencies { + compile project(':netty-http-client') +} \ No newline at end of file diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/rest/RestClient.java b/netty-http-client-rest/src/main/java/org/xbib/netty/http/client/rest/RestClient.java similarity index 84% rename from netty-http-client/src/main/java/org/xbib/netty/http/client/rest/RestClient.java rename to netty-http-client-rest/src/main/java/org/xbib/netty/http/client/rest/RestClient.java index e64aea6..6406d61 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/rest/RestClient.java +++ b/netty-http-client-rest/src/main/java/org/xbib/netty/http/client/rest/RestClient.java @@ -1,12 +1,12 @@ package org.xbib.netty.http.client.rest; import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpMethod; import org.xbib.net.URL; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.Request; +import org.xbib.netty.http.common.HttpResponse; import java.io.IOException; import java.nio.charset.Charset; @@ -16,16 +16,16 @@ public class RestClient { private static final Client client = new Client(); - private FullHttpResponse response; + private HttpResponse response; private RestClient() { } - public void setResponse(FullHttpResponse response) { - this.response = response.copy(); + public void setResponse(HttpResponse response) { + this.response = response; } - public FullHttpResponse getResponse() { + public HttpResponse getResponse() { return response; } @@ -34,14 +34,8 @@ public class RestClient { } public String asString(Charset charset) { - ByteBuf byteBuf = response != null ? response.content() : null; - try { - return byteBuf != null && byteBuf.isReadable() ? response.content().toString(charset) : null; - } finally { - if (byteBuf != null) { - byteBuf.release(); - } - } + ByteBuf byteBuf = response != null ? response.getBody() : null; + return byteBuf != null && byteBuf.isReadable() ? byteBuf.toString(charset) : null; } public void close() throws IOException { diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/rest/RestClientTest.java b/netty-http-client-rest/src/test/java/org/xbib/netty/http/client/rest/RestClientTest.java similarity index 79% rename from netty-http-client/src/test/java/org/xbib/netty/http/client/test/rest/RestClientTest.java rename to netty-http-client-rest/src/test/java/org/xbib/netty/http/client/rest/RestClientTest.java index 0ef8145..f566aa7 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/rest/RestClientTest.java +++ b/netty-http-client-rest/src/test/java/org/xbib/netty/http/client/rest/RestClientTest.java @@ -1,7 +1,6 @@ -package org.xbib.netty.http.client.test.rest; +package org.xbib.netty.http.client.rest; import org.junit.jupiter.api.Test; -import org.xbib.netty.http.client.rest.RestClient; import java.io.IOException; import java.util.logging.Logger; diff --git a/netty-http-client/build.gradle b/netty-http-client/build.gradle index 10ff3ac..7d5d0b8 100644 --- a/netty-http-client/build.gradle +++ b/netty-http-client/build.gradle @@ -1,12 +1,10 @@ dependencies { - implementation project(":netty-http-common") - implementation "io.netty:netty-handler-proxy:${project.property('netty.version')}" - implementation "io.netty:netty-transport-native-epoll:${project.property('netty.version')}" - implementation "io.netty:netty-codec-http2:${project.property('netty.version')}" - implementation "org.xbib:net-url:${project.property('xbib-net-url.version')}" - testImplementation "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative.version')}" - testImplementation "org.bouncycastle:bcpkix-jdk15on:${project.property('bouncycastle.version')}" - testImplementation "org.conscrypt:conscrypt-openjdk-uber:${project.property('conscrypt.version')}" - testImplementation "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" + compile project(":netty-http-common") + compile "io.netty:netty-handler-proxy:${project.property('netty.version')}" + compile "io.netty:netty-transport-native-epoll:${project.property('netty.version')}" + testCompile "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative.version')}" + testCompile "org.bouncycastle:bcpkix-jdk15on:${project.property('bouncycastle.version')}" + testCompile "org.conscrypt:conscrypt-openjdk-uber:${project.property('conscrypt.version')}" + testCompile "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java index 9bfe22c..6705588 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java @@ -13,7 +13,6 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.pool.ChannelPoolHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http2.Http2Settings; import io.netty.handler.proxy.HttpProxyHandler; @@ -33,6 +32,7 @@ import org.xbib.netty.http.client.transport.Http2Transport; import org.xbib.netty.http.client.transport.HttpTransport; import org.xbib.netty.http.client.transport.Transport; import org.xbib.netty.http.common.HttpAddress; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.NetworkUtils; import org.xbib.netty.http.common.security.SecurityUtil; @@ -261,7 +261,7 @@ public final class Client { } public CompletableFuture execute(Request request, - Function supplier) throws IOException { + Function supplier) throws IOException { return newTransport(HttpAddress.of(request.url(), request.httpVersion())) .execute(request, supplier); } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/Request.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/Request.java index 5d45e5b..598e253 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/Request.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/Request.java @@ -25,6 +25,7 @@ import org.xbib.netty.http.client.listener.StatusListener; import org.xbib.netty.http.client.retry.BackOff; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.common.HttpParameters; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.cookie.Cookie; import java.nio.charset.MalformedInputException; @@ -73,7 +74,7 @@ public class Request { private CompletableFuture completableFuture; - private ResponseListener responseListener; + private ResponseListener responseListener; private CookieListener cookieListener; @@ -208,12 +209,12 @@ public class Request { return statusListener; } - public Request setResponseListener(ResponseListener responseListener) { + public Request setResponseListener(ResponseListener responseListener) { this.responseListener = responseListener; return this; } - public ResponseListener getResponseListener() { + public ResponseListener getResponseListener() { return responseListener; } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http/HttpResponseHandler.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http/HttpResponseHandler.java index 6ee0e15..a197613 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http/HttpResponseHandler.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/handler/http/HttpResponseHandler.java @@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.FullHttpResponse; import org.xbib.netty.http.client.transport.Transport; +import org.xbib.netty.http.common.DefaultHttpResponse; @ChannelHandler.Sharable public class HttpResponseHandler extends SimpleChannelInboundHandler { @@ -12,7 +13,8 @@ public class HttpResponseHandler extends SimpleChannelInboundHandler { @@ -14,7 +15,8 @@ public class Http2ResponseHandler extends SimpleChannelInboundHandler { - void onResponse(FullHttpResponse fullHttpResponse); + void onResponse(R response); } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/listener/StatusListener.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/listener/StatusListener.java index afe5ef6..a26ffec 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/listener/StatusListener.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/listener/StatusListener.java @@ -1,9 +1,10 @@ package org.xbib.netty.http.client.listener; -import io.netty.handler.codec.http.HttpResponseStatus; + +import org.xbib.netty.http.common.HttpStatus; @FunctionalInterface public interface StatusListener { - void onStatus(HttpResponseStatus httpResponseStatus); + void onStatus(HttpStatus httpStatus); } diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/BaseTransport.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/BaseTransport.java index ba9f901..06aadd5 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/BaseTransport.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/BaseTransport.java @@ -1,7 +1,6 @@ package org.xbib.netty.http.client.transport; import io.netty.channel.Channel; -import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.ssl.SslHandler; @@ -12,6 +11,7 @@ import org.xbib.netty.http.client.Client; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.retry.BackOff; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.cookie.Cookie; import org.xbib.netty.http.common.cookie.CookieBox; @@ -65,6 +65,11 @@ abstract class BaseTransport implements Transport { this.requests = new ConcurrentSkipListMap<>(); } + @Override + public HttpAddress getHttpAddress() { + return httpAddress; + } + /** * Experimental method for executing in a wrapping completable future. * @param request request @@ -74,7 +79,7 @@ abstract class BaseTransport implements Transport { */ @Override public CompletableFuture execute(Request request, - Function supplier) throws IOException { + Function supplier) throws IOException { Objects.requireNonNull(supplier); final CompletableFuture completableFuture = new CompletableFuture<>(); request.setResponseListener(response -> { @@ -237,7 +242,7 @@ abstract class BaseTransport implements Transport { return channel; } - protected Request continuation(Request request, FullHttpResponse httpResponse) throws URLSyntaxException { + protected Request continuation(Request request, HttpResponse httpResponse) throws URLSyntaxException { if (httpResponse == null) { return null; } @@ -247,7 +252,7 @@ abstract class BaseTransport implements Transport { } try { if (request.canRedirect()) { - int status = httpResponse.status().code(); + int status = httpResponse.getStatus().getCode(); switch (status) { case 300: case 301: @@ -256,12 +261,12 @@ abstract class BaseTransport implements Transport { case 305: case 307: case 308: - String location = httpResponse.headers().get(HttpHeaderNames.LOCATION); + String location = httpResponse.getHeaders().getHeader(HttpHeaderNames.LOCATION); location = new PercentDecoder(StandardCharsets.UTF_8.newDecoder()).decode(location); if (location != null) { logger.log(Level.FINE, "found redirect location: " + location); URL redirUrl = URL.base(request.url()).resolve(location); - HttpMethod method = httpResponse.status().code() == 303 ? HttpMethod.GET : request.httpMethod(); + HttpMethod method = httpResponse.getStatus().getCode() == 303 ? HttpMethod.GET : request.httpMethod(); Request.Builder newHttpRequestBuilder = Request.builder(method) .url(redirUrl) .setVersion(request.httpVersion()) @@ -297,7 +302,7 @@ abstract class BaseTransport implements Transport { return null; } - protected Request retry(Request request, FullHttpResponse httpResponse) { + protected Request retry(Request request, HttpResponse httpResponse) { if (httpResponse == null) { return null; } @@ -308,7 +313,7 @@ abstract class BaseTransport implements Transport { if (request.isBackOff()) { BackOff backOff = request.getBackOff() != null ? request.getBackOff() : client.getClientConfig().getBackOff(); - int status = httpResponse.status().code(); + int status = httpResponse.getStatus ().getCode(); switch (status) { case 403: case 404: diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/Http2Transport.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/Http2Transport.java index 5643337..b02f824 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/Http2Transport.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/Http2Transport.java @@ -3,7 +3,6 @@ package org.xbib.netty.http.client.transport; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; -import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http2.DefaultHttp2DataFrame; @@ -26,6 +25,7 @@ import org.xbib.netty.http.client.listener.StatusListener; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.cookie.Cookie; import java.io.IOException; @@ -134,13 +134,13 @@ public class Http2Transport extends BaseTransport { } @Override - public void responseReceived(Channel channel, Integer streamId, FullHttpResponse fullHttpResponse) { + public void responseReceived(Channel channel, Integer streamId, HttpResponse httpResponse) { if (throwable != null) { - logger.log(Level.WARNING, "throwable not null for response " + fullHttpResponse, throwable); + logger.log(Level.WARNING, "throwable not null for response " + httpResponse, throwable); return; } if (streamId == null) { - logger.log(Level.WARNING, "stream ID is null for response " + fullHttpResponse); + logger.log(Level.WARNING, "stream ID is null for response " + httpResponse); return; } // format of childchan channel ID is "/" @@ -160,9 +160,9 @@ public class Http2Transport extends BaseTransport { } else { StatusListener statusListener = request.getStatusListener(); if (statusListener != null) { - statusListener.onStatus(fullHttpResponse.status()); + statusListener.onStatus(httpResponse.getStatus()); } - for (String cookieString : fullHttpResponse.headers().getAll(HttpHeaderNames.SET_COOKIE)) { + for (String cookieString : httpResponse.getHeaders().getAllHeaders(HttpHeaderNames.SET_COOKIE)) { Cookie cookie = ClientCookieDecoder.STRICT.decode(cookieString); addCookie(cookie); CookieListener cookieListener = request.getCookieListener(); @@ -170,17 +170,17 @@ public class Http2Transport extends BaseTransport { cookieListener.onCookie(cookie); } } - ResponseListener responseListener = request.getResponseListener(); + ResponseListener responseListener = request.getResponseListener(); if (responseListener != null) { - responseListener.onResponse(fullHttpResponse); + responseListener.onResponse(httpResponse); } try { - Request retryRequest = retry(request, fullHttpResponse); + Request retryRequest = retry(request, httpResponse); if (retryRequest != null) { // retry transport, wait for completion client.retry(this, retryRequest); } else { - Request continueRequest = continuation(request, fullHttpResponse); + Request continueRequest = continuation(request, httpResponse); if (continueRequest != null) { // continue with new transport, synchronous call here, wait for completion client.continuation(this, continueRequest); diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/HttpTransport.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/HttpTransport.java index 35688c9..aa0ab91 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/HttpTransport.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/HttpTransport.java @@ -3,7 +3,6 @@ package org.xbib.netty.http.client.transport; import io.netty.channel.Channel; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http2.Http2Headers; import io.netty.handler.codec.http2.Http2Settings; @@ -17,6 +16,7 @@ import org.xbib.netty.http.client.listener.StatusListener; import org.xbib.netty.http.common.HttpAddress; import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.cookie.Cookie; import java.io.IOException; @@ -75,9 +75,9 @@ public class HttpTransport extends BaseTransport { } @Override - public void responseReceived(Channel channel, Integer streamId, FullHttpResponse fullHttpResponse) { + public void responseReceived(Channel channel, Integer streamId, HttpResponse httpResponse) { if (throwable != null) { - logger.log(Level.WARNING, "throwable not null for response " + fullHttpResponse, throwable); + logger.log(Level.WARNING, "throwable not null for response " + httpResponse, throwable); return; } if (requests.isEmpty()) { @@ -89,9 +89,9 @@ public class HttpTransport extends BaseTransport { if (request != null) { StatusListener statusListener = request.getStatusListener(); if (statusListener != null) { - statusListener.onStatus(fullHttpResponse.status()); + statusListener.onStatus(httpResponse.getStatus()); } - for (String cookieString : fullHttpResponse.headers().getAll(HttpHeaderNames.SET_COOKIE)) { + for (String cookieString : httpResponse.getHeaders().getAllHeaders(HttpHeaderNames.SET_COOKIE)) { Cookie cookie = ClientCookieDecoder.STRICT.decode(cookieString); addCookie(cookie); CookieListener cookieListener = request.getCookieListener(); @@ -99,18 +99,18 @@ public class HttpTransport extends BaseTransport { cookieListener.onCookie(cookie); } } - ResponseListener responseListener = request.getResponseListener(); + ResponseListener responseListener = request.getResponseListener(); if (responseListener != null) { - responseListener.onResponse(fullHttpResponse); + responseListener.onResponse(httpResponse); } } try { - Request retryRequest = retry(request, fullHttpResponse); + Request retryRequest = retry(request, httpResponse); if (retryRequest != null) { // retry transport, wait for completion client.retry(this, retryRequest); } else { - Request continueRequest = continuation(request, fullHttpResponse); + Request continueRequest = continuation(request, httpResponse); if (continueRequest != null) { // continue with new transport, synchronous call here, wait for completion client.continuation(this, continueRequest); diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/Transport.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/Transport.java index 05cfe12..3f2143a 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/Transport.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/transport/Transport.java @@ -1,11 +1,12 @@ package org.xbib.netty.http.client.transport; import io.netty.channel.Channel; -import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http2.Http2Headers; import io.netty.handler.codec.http2.Http2Settings; import io.netty.util.AttributeKey; import org.xbib.netty.http.client.Request; +import org.xbib.netty.http.common.HttpAddress; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.common.cookie.CookieBox; import javax.net.ssl.SSLSession; @@ -18,15 +19,17 @@ public interface Transport { AttributeKey TRANSPORT_ATTRIBUTE_KEY = AttributeKey.valueOf("transport"); + HttpAddress getHttpAddress(); + Transport execute(Request request) throws IOException; - CompletableFuture execute(Request request, Function supplier) throws IOException; + CompletableFuture execute(Request request, Function supplier) throws IOException; void waitForSettings(); void settingsReceived(Http2Settings http2Settings) throws IOException; - void responseReceived(Channel channel, Integer streamId, FullHttpResponse fullHttpResponse) throws IOException; + void responseReceived(Channel channel, Integer streamId, HttpResponse fullHttpResponse) throws IOException; void pushPromiseReceived(Channel channel, Integer streamId, Integer promisedStreamId, Http2Headers headers); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CompletableFutureTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CompletableFutureTest.java index ae50f04..7b8cce7 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CompletableFutureTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CompletableFutureTest.java @@ -1,9 +1,9 @@ package org.xbib.netty.http.client.test; -import io.netty.handler.codec.http.FullHttpResponse; import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; +import org.xbib.netty.http.common.HttpResponse; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -23,12 +23,12 @@ class CompletableFutureTest { void testComposeCompletableFutures() throws IOException { Client client = Client.builder().build(); try { - final Function httpResponseStringFunction = response -> - response.content().toString(StandardCharsets.UTF_8); + final Function stringFunction = response -> + response.getBodyAsString(StandardCharsets.UTF_8); Request request = Request.get() .url("http://repo.maven.apache.org/maven2/org/xbib/netty-http-client/maven-metadata.xml.sha1") .build(); - CompletableFuture completableFuture = client.execute(request, httpResponseStringFunction) + CompletableFuture completableFuture = client.execute(request, stringFunction) .exceptionally(Throwable::getMessage) .thenCompose(content -> { logger.log(Level.INFO, content); @@ -37,7 +37,7 @@ class CompletableFutureTest { return client.execute(Request.post() .url("http://google.com/") .addParameter("query", content) - .build(), httpResponseStringFunction); + .build(), stringFunction); } catch (IOException e) { logger.log(Level.WARNING, e.getMessage(), e); return null; diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ConscryptTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ConscryptTest.java index 1b0a474..0737465 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ConscryptTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/ConscryptTest.java @@ -28,10 +28,9 @@ class ConscryptTest { .url("https://google.com") .setVersion("HTTP/1.1") .build() - .setResponseListener(fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "status = " + fullHttpResponse.status() - + " response body = " + response); + .setResponseListener(resp -> { + logger.log(Level.INFO, "status = " + resp.getStatus() + + " response body = " + resp.getBodyAsString(StandardCharsets.UTF_8)); }); client.execute(request).get(); } finally { diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CookieSetterHttpBinTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CookieSetterHttpBinTest.java index 6c78fe9..d3c7b14 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CookieSetterHttpBinTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/CookieSetterHttpBinTest.java @@ -36,9 +36,9 @@ class CookieSetterHttpBinTest { .url("http://httpbin.org/cookies/set?name=value") .build() .setCookieListener(cookie -> logger.log(Level.INFO, "this is the cookie: " + cookie.toString())) - .setResponseListener(fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); + .setResponseListener(resp -> { + logger.log(Level.INFO, "status = " + resp.getStatus() + + " response body = " + resp.getBodyAsString(StandardCharsets.UTF_8)); }); client.execute(request).get(); } finally { diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http1Test.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http1Test.java index 039acab..387c0be 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http1Test.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/Http1Test.java @@ -22,10 +22,10 @@ class Http1Test { .build(); try { Request request = Request.get().url("http://xbib.org").build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, + "got response: " + resp.getHeaders() + + resp.getBodyAsString(StandardCharsets.UTF_8) + + " status=" + resp.getStatus())); client.execute(request).get(); } finally { client.shutdownGracefully(); @@ -38,13 +38,13 @@ class Http1Test { .build(); try { Request request1 = Request.get().url("http://xbib.org").build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.content().toString(StandardCharsets.UTF_8))); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getBodyAsString(StandardCharsets.UTF_8))); client.execute(request1).get(); Request request2 = Request.get().url("http://google.com").setVersion("HTTP/1.1").build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.content().toString(StandardCharsets.UTF_8))); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getBodyAsString(StandardCharsets.UTF_8))); client.execute(request2).get(); } finally { client.shutdownGracefully(); @@ -59,17 +59,13 @@ class Http1Test { Request request1 = Request.builder(HttpMethod.GET) .url("http://xbib.org").setVersion("HTTP/1.1") .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - //msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getHeaders() + " status=" +resp.getStatus())); Request request2 = Request.builder(HttpMethod.GET) .url("http://xbib.org").setVersion("HTTP/1.1") .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - //msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getHeaders() + " status=" +resp.getStatus())); for (int i = 0; i < 10; i++) { client.execute(request1); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttpTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttpTest.java index 582f6c9..f2883f0 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttpTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/SecureHttpTest.java @@ -22,10 +22,9 @@ class SecureHttpTest { .build(); try { Request request = Request.get().url("https://www.google.com/").build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getHeaders() + resp.getBodyAsString(StandardCharsets.UTF_8) + + " status=" + resp.getStatus())); client.execute(request).get(); } finally { client.shutdownGracefully(); @@ -38,13 +37,13 @@ class SecureHttpTest { .build(); try { Request request1 = Request.get().url("https://google.com").build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.content().toString(StandardCharsets.UTF_8))); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getBodyAsString(StandardCharsets.UTF_8))); client.execute(request1).get(); Request request2 = Request.get().url("https://google.com").setVersion("HTTP/2.0").build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.content().toString(StandardCharsets.UTF_8))); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getBodyAsString(StandardCharsets.UTF_8))); client.execute(request2).get(); } finally { client.shutdownGracefully(); @@ -59,15 +58,15 @@ class SecureHttpTest { Request request1 = Request.builder(HttpMethod.GET) .url("https://google.com").setVersion("HTTP/1.1") .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getHeaders() + + " status=" + resp.getStatus())); Request request2 = Request.builder(HttpMethod.GET) .url("https://google.com").setVersion("HTTP/1.1") .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getHeaders() + + " status=" + resp.getStatus())); for (int i = 0; i < 10; i++) { client.execute(request1); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/XbibTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/XbibTest.java index e824a56..06b45c3 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/XbibTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/XbibTest.java @@ -1,10 +1,10 @@ package org.xbib.netty.http.client.test; -import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.proxy.HttpProxyHandler; import org.junit.jupiter.api.Test; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Request; +import org.xbib.netty.http.common.HttpResponse; import java.io.IOException; import java.net.InetSocketAddress; @@ -24,9 +24,9 @@ class XbibTest { try { Request request = Request.get().url("http://xbib.org") .build() - .setResponseListener(fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); + .setResponseListener(resp -> { + logger.log(Level.INFO, "status = " + resp.getStatus() + + " response = " + resp.getBodyAsString(StandardCharsets.UTF_8)); }); client.execute(request); } finally { @@ -40,18 +40,18 @@ class XbibTest { .setTcpNodelay(true) .build(); try { - final Function httpResponseStringFunction = - response -> response.content().toString(StandardCharsets.UTF_8); + final Function stringFunction = + response -> response.getBodyAsString(StandardCharsets.UTF_8); Request request = Request.get().url("http://xbib.org") .build(); - final CompletableFuture completableFuture = httpClient.execute(request, httpResponseStringFunction) + final CompletableFuture completableFuture = httpClient.execute(request, stringFunction) .exceptionally(Throwable::getMessage) .thenCompose(content -> { try { return httpClient.execute(Request.post() .url("http://google.de") .addParameter("query", content.substring(0, 15)) - .build(), httpResponseStringFunction); + .build(), stringFunction); } catch (IOException e) { logger.log(Level.WARNING, e.getMessage(), e); return null; @@ -75,10 +75,8 @@ class XbibTest { httpClient.execute(Request.get() .url("http://xbib.org") .build() - .setResponseListener(fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); - })) + .setResponseListener(resp -> logger.log(Level.INFO, "status = " + resp.getStatus() + + " response body = " + resp.getBodyAsString(StandardCharsets.UTF_8)))) .get(); } finally { httpClient.shutdownGracefully(); @@ -94,10 +92,10 @@ class XbibTest { .url("http://xbib.org") .setTimeoutInMillis(10) .build() - .setResponseListener(fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); - })) + .setResponseListener(resp -> + logger.log(Level.INFO, "status = " + resp.getStatus() + + " response body = " + resp.getBodyAsString(StandardCharsets.UTF_8)) + )) .get(); } finally { httpClient.shutdownGracefully(); @@ -112,9 +110,9 @@ class XbibTest { .setVersion("HTTP/1.1") .url("http://xbib.org") .build() - .setResponseListener(fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); + .setResponseListener(resp -> { + logger.log(Level.INFO, "status = " + resp.getStatus() + + " response body = " + resp.getBodyAsString(StandardCharsets.UTF_8)); })) .get(); @@ -122,9 +120,9 @@ class XbibTest { .setVersion("HTTP/1.1") .url("http://xbib.org") .build() - .setResponseListener(fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); + .setResponseListener(resp -> { + logger.log(Level.INFO, "status = " + resp.getStatus() + + " response body = " + resp.getBodyAsString(StandardCharsets.UTF_8)); })) .get(); } finally { diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/akamai/AkamaiTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/akamai/AkamaiTest.java index c8c0ad1..365d1fc 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/akamai/AkamaiTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/akamai/AkamaiTest.java @@ -39,10 +39,9 @@ public class AkamaiTest { //.url("https://http2.akamai.com/") .setVersion("HTTP/2.0") .build() - .setResponseListener(msg -> { - String response = msg.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "status = " + msg.status() + - msg.headers().entries() + " " + response); + .setResponseListener(resp -> { + logger.log(Level.INFO, "status = " + resp.getStatus().getCode() + + resp.getHeaders() + " " + resp.getBodyAsString(StandardCharsets.UTF_8)); }); client.execute(request).get(); } finally { diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/htt2push/Http2PushTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/htt2push/Http2PushTest.java index 0b15a72..648f9b1 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/htt2push/Http2PushTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/htt2push/Http2PushTest.java @@ -26,10 +26,8 @@ class Http2PushTest { Request request = Request.builder(HttpMethod.GET) .url(url).setVersion("HTTP/2.0") .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - //msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, + "got response: " + resp.getHeaders() + " status=" + resp.getStatus())); client.execute(request).get(); } finally { diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PooledClientTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PooledClientTest.java index 93ffcb3..db62dc7 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PooledClientTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/pool/PooledClientTest.java @@ -35,9 +35,8 @@ class PooledClientTest { .setPoolNodeConnectionLimit(threads) .build(); AtomicInteger count = new AtomicInteger(); - ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); + ResponseListener responseListener = resp -> { + String response = resp.getBodyAsString(StandardCharsets.UTF_8); count.getAndIncrement(); }; try { @@ -49,7 +48,6 @@ class PooledClientTest { for (int i = 0; i < loop; i++) { Request request = Request.get().setVersion(httpAddress.getVersion()) .url(url.toString()) - //.setTimeoutInMillis(25000L) .build() .setResponseListener(responseListener); client.newTransport().execute(request).get(); diff --git a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/webtide/WebtideTest.java b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/webtide/WebtideTest.java index e22c842..5c469a9 100644 --- a/netty-http-client/src/test/java/org/xbib/netty/http/client/test/webtide/WebtideTest.java +++ b/netty-http-client/src/test/java/org/xbib/netty/http/client/test/webtide/WebtideTest.java @@ -36,18 +36,14 @@ class WebtideTest { Request request1 = Request.builder(HttpMethod.GET) .url("https://webtide.com").setVersion("HTTP/2.0") .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - //msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getHeaders() + " status=" + resp.getStatus())); Request request2 = Request.builder(HttpMethod.GET) .url("https://webtide.com/why-choose-jetty/").setVersion("HTTP/2.0") .build() - .setResponseListener(msg -> logger.log(Level.INFO, "got response: " + - msg.headers().entries() + - //msg.content().toString(StandardCharsets.UTF_8) + - " status=" + msg.status().code())); + .setResponseListener(resp -> logger.log(Level.INFO, "got response: " + + resp.getHeaders() + " status=" +resp.getStatus())); client.execute(request1).execute(request2); } finally { diff --git a/netty-http-common/src/main/java/org/xbib/netty/http/common/DefaultHttpHeaders.java b/netty-http-common/src/main/java/org/xbib/netty/http/common/DefaultHttpHeaders.java new file mode 100644 index 0000000..8623744 --- /dev/null +++ b/netty-http-common/src/main/java/org/xbib/netty/http/common/DefaultHttpHeaders.java @@ -0,0 +1,34 @@ +package org.xbib.netty.http.common; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public class DefaultHttpHeaders implements HttpHeaders { + + private final io.netty.handler.codec.http.HttpHeaders httpHeaders; + + public DefaultHttpHeaders(io.netty.handler.codec.http.HttpHeaders headers) { + this.httpHeaders = headers; + } + + @Override + public String getHeader(CharSequence header) { + return httpHeaders.get(header); + } + + @Override + public List getAllHeaders(CharSequence header) { + return httpHeaders.getAll(header); + } + + @Override + public Iterator> iterator() { + return httpHeaders.iteratorCharSequence(); + } + + @Override + public String toString() { + return httpHeaders.entries().toString(); + } +} diff --git a/netty-http-common/src/main/java/org/xbib/netty/http/common/DefaultHttpResponse.java b/netty-http-common/src/main/java/org/xbib/netty/http/common/DefaultHttpResponse.java new file mode 100644 index 0000000..4818b34 --- /dev/null +++ b/netty-http-common/src/main/java/org/xbib/netty/http/common/DefaultHttpResponse.java @@ -0,0 +1,56 @@ +package org.xbib.netty.http.common; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.handler.codec.http.FullHttpResponse; + +import java.io.InputStream; +import java.nio.charset.Charset; + +public class DefaultHttpResponse implements HttpResponse { + + private final HttpAddress httpAddress; + + private final FullHttpResponse fullHttpResponse; + + private final HttpStatus httpStatus; + + private final HttpHeaders httpHeaders; + + public DefaultHttpResponse(HttpAddress httpAddress, FullHttpResponse fullHttpResponse) { + this.httpAddress = httpAddress; + this.fullHttpResponse = fullHttpResponse; + this.httpStatus = new HttpStatus(fullHttpResponse.status()); + this.httpHeaders = new DefaultHttpHeaders(fullHttpResponse.headers()); + } + + @Override + public HttpAddress getAddress() { + return httpAddress; + } + + @Override + public HttpStatus getStatus() { + return httpStatus; + } + + @Override + public HttpHeaders getHeaders() { + return httpHeaders; + } + + @Override + public ByteBuf getBody() { + return fullHttpResponse.content().asReadOnly(); + } + + @Override + public InputStream getBodyAsStream() { + return new ByteBufInputStream(getBody()); + } + + @Override + public String getBodyAsString(Charset charset) { + return getBody().toString(charset); + } +} diff --git a/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpHeaders.java b/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpHeaders.java new file mode 100644 index 0000000..fe19c76 --- /dev/null +++ b/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpHeaders.java @@ -0,0 +1,14 @@ +package org.xbib.netty.http.common; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public interface HttpHeaders { + + String getHeader(CharSequence header); + + List getAllHeaders(CharSequence header); + + Iterator> iterator(); +} diff --git a/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpRequest.java b/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpRequest.java index 2180663..3bd1c2b 100644 --- a/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpRequest.java +++ b/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpRequest.java @@ -1,6 +1,5 @@ package org.xbib.netty.http.common; -import java.io.IOException; import java.io.InputStream; import java.util.Map; @@ -21,7 +20,7 @@ public interface HttpRequest { Map getHeaders(); - InputStream getContent() throws IOException; + InputStream getContent(); String getContentType(); diff --git a/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpResponse.java b/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpResponse.java index 01778c7..95766ec 100644 --- a/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpResponse.java +++ b/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpResponse.java @@ -1,13 +1,21 @@ package org.xbib.netty.http.common; -import java.io.IOException; +import io.netty.buffer.ByteBuf; + import java.io.InputStream; +import java.nio.charset.Charset; public interface HttpResponse { - int getStatusCode() throws IOException; + HttpAddress getAddress(); - String getReason() throws Exception; + HttpStatus getStatus(); - InputStream getContent() throws IOException; + HttpHeaders getHeaders(); + + ByteBuf getBody(); + + InputStream getBodyAsStream(); + + String getBodyAsString(Charset charset); } diff --git a/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpStatus.java b/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpStatus.java new file mode 100644 index 0000000..8265cf1 --- /dev/null +++ b/netty-http-common/src/main/java/org/xbib/netty/http/common/HttpStatus.java @@ -0,0 +1,30 @@ +package org.xbib.netty.http.common; + +import io.netty.handler.codec.http.HttpResponseStatus; + +public class HttpStatus { + + private final HttpResponseStatus httpResponseStatus; + + public HttpStatus(HttpResponseStatus httpResponseStatus) { + this.httpResponseStatus = httpResponseStatus; + } + + public int getCode() { + return httpResponseStatus.code(); + } + + public String getMessage() { + return httpResponseStatus.codeAsText().toString(); + } + + public String getReasonPhrase() { + return httpResponseStatus.reasonPhrase(); + } + + @Override + public String toString() { + return httpResponseStatus.toString(); + } + +} diff --git a/netty-http-server-reactive/build.gradle b/netty-http-server-reactive/build.gradle index 9fe5889..6f5430a 100644 --- a/netty-http-server-reactive/build.gradle +++ b/netty-http-server-reactive/build.gradle @@ -1,7 +1,7 @@ dependencies { compile project(':netty-http-server') - implementation "org.reactivestreams:reactive-streams:${project.property('reactivestreams.version')}" - testImplementation("org.reactivestreams:reactive-streams-tck:${project.property('reactivestreams.version')}") { + compile "org.reactivestreams:reactive-streams:${project.property('reactivestreams.version')}" + testCompile("org.reactivestreams:reactive-streams-tck:${project.property('reactivestreams.version')}") { exclude module: 'testng' } } \ No newline at end of file diff --git a/netty-http-server-rest/build.gradle b/netty-http-server-rest/build.gradle index ac8651f..971f929 100644 --- a/netty-http-server-rest/build.gradle +++ b/netty-http-server-rest/build.gradle @@ -1,6 +1,4 @@ dependencies { - implementation project(":netty-http-server") - implementation "io.netty:netty-codec-http2:${project.property('netty.version')}" - implementation "org.xbib:net-url:${project.property('xbib-net-url.version')}" - implementation "org.xbib:guice:${project.property('xbib-guice.version')}" + compile project(":netty-http-server") + compile "org.xbib:guice:${project.property('xbib-guice.version')}" } diff --git a/netty-http-server/build.gradle b/netty-http-server/build.gradle index dacb50e..660b2e2 100644 --- a/netty-http-server/build.gradle +++ b/netty-http-server/build.gradle @@ -1,9 +1,7 @@ dependencies { compile project(":netty-http-common") - compile "io.netty:netty-handler:${project.property('netty.version')}" compile "io.netty:netty-transport-native-epoll:${project.property('netty.version')}" compile "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative.version')}" - compile "io.netty:netty-codec-http2:${project.property('netty.version')}" compile "org.bouncycastle:bcpkix-jdk15on:${project.property('bouncycastle.version')}" - testImplementation project(":netty-http-client") + testCompile project(":netty-http-client") } diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ClassloaderServiceTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ClassloaderServiceTest.java index fe4260a..642c8e2 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ClassloaderServiceTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/ClassloaderServiceTest.java @@ -43,9 +43,9 @@ class ClassloaderServiceTest { Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/classloader/test.txt")) .build() - .setResponseListener(r -> { - if (r.status().equals(HttpResponseStatus.OK)) { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); count.incrementAndGet(); } }); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp1Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp1Test.java index 4dc39f9..a1a6b21 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp1Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp1Test.java @@ -9,10 +9,10 @@ import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; import org.xbib.netty.http.client.transport.Transport; import org.xbib.netty.http.common.HttpAddress; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Domain; -import java.nio.charset.StandardCharsets; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -41,10 +41,8 @@ class CleartextHttp1Test { Client client = Client.builder() .build(); AtomicInteger counter = new AtomicInteger(); - final ResponseListener responseListener = fullHttpResponse -> { - if (fullHttpResponse.status().equals(HttpResponseStatus.OK)) { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); + final ResponseListener responseListener = resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { counter.incrementAndGet(); } }; @@ -79,10 +77,8 @@ class CleartextHttp1Test { .setPoolNodeConnectionLimit(2) .build(); AtomicInteger counter = new AtomicInteger(); - final ResponseListener responseListener = fullHttpResponse -> { - if (fullHttpResponse.status().equals(HttpResponseStatus.OK)) { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); + final ResponseListener responseListener = resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { counter.incrementAndGet(); } }; @@ -126,11 +122,8 @@ class CleartextHttp1Test { .setPoolNodeConnectionLimit(threads) .build(); AtomicInteger counter = new AtomicInteger(); - final ResponseListener responseListener = fullHttpResponse -> { - if (fullHttpResponse.status().equals(HttpResponseStatus.OK)) { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "status = " + fullHttpResponse.status() + - // " response=" + response + " payload=" + payload); + final ResponseListener responseListener = resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { counter.incrementAndGet(); } }; diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp2Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp2Test.java index 53c556f..2c160dd 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp2Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/CleartextHttp2Test.java @@ -8,6 +8,7 @@ import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; import org.xbib.netty.http.client.transport.Transport; import org.xbib.netty.http.common.HttpAddress; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.ServerResponse; import org.xbib.netty.http.server.Domain; @@ -43,10 +44,9 @@ class CleartextHttp2Test { .build(); AtomicInteger counter = new AtomicInteger(); // a single instance of HTTP/2 response listener, always receives responses out-of-order - ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "response listener: headers = " + fullHttpResponse.headers().entries() + - " response body = " + response); + ResponseListener responseListener = resp -> { + logger.log(Level.INFO, "response listener: headers = " + resp.getHeaders() + + " response body = " + resp.getBodyAsString(StandardCharsets.UTF_8)); counter.incrementAndGet(); }; try { @@ -87,17 +87,12 @@ class CleartextHttp2Test { .build(); AtomicInteger counter = new AtomicInteger(); // a single instance of HTTP/2 response listener, always receives responses out-of-order - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "response listener: headers = " + fullHttpResponse.headers().entries() + - // " response body = " + response); - counter.incrementAndGet(); - }; + final ResponseListener responseListener = resp -> counter.incrementAndGet(); try { // single transport, single thread Transport transport = client.newTransport(); for (int i = 0; i < loop; i++) { - String payload = Integer.toString(0) + "/" + Integer.toString(i); + String payload = 0 + "/" + i; Request request = Request.get().setVersion("HTTP/2.0") .url(server.getServerConfig().getAddress().base()) .content(payload, "text/plain") @@ -136,12 +131,7 @@ class CleartextHttp2Test { .build(); AtomicInteger counter = new AtomicInteger(); // a HTTP/2 listener always receives responses out-of-order - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "response listener: headers = " + fullHttpResponse.headers().entries() + - // " response body = " + response); - counter.incrementAndGet(); - }; + final ResponseListener responseListener = resp -> counter.incrementAndGet(); try { // note: for HTTP/2 only, we can use a single shared transport final Transport transport = client.newTransport(); @@ -214,12 +204,7 @@ class CleartextHttp2Test { .build(); AtomicInteger counter = new AtomicInteger(); // a single instance of HTTP/2 response listener, always receives responses out-of-order - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "response listener: headers = " + fullHttpResponse.headers().entries() + - // " response body = " + response); - counter.incrementAndGet(); - }; + final ResponseListener responseListener = resp -> counter.incrementAndGet(); try { // note: for HTTP/2 only, we can use a single shared transport final Transport transport = client.newTransport(); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/EndpointTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/EndpointTest.java index 4367624..0c2fee9 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/EndpointTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/EndpointTest.java @@ -59,8 +59,8 @@ class EndpointTest { Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/test.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); }); client.execute(request).get(); @@ -99,8 +99,8 @@ class EndpointTest { Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/test.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); }); client.execute(request).get(); @@ -146,24 +146,24 @@ class EndpointTest { Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/static/test.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); }); client.execute(request).get(); Request request1 = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/static1/test1.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg 1", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg 1",resp.getBodyAsString(StandardCharsets.UTF_8)); success1.set(true); }); client.execute(request1).get(); Request request2 = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/static2/test2.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg 2", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg 2", resp.getBodyAsString(StandardCharsets.UTF_8)); success2.set(true); }); client.execute(request2).get(); @@ -214,12 +214,12 @@ class EndpointTest { .url(server.getServerConfig().getAddress().base().resolve("/static/test.txt")) .addParameter("a", "b") .build() - .setResponseListener(r -> { - if (r.status().equals(HttpResponseStatus.OK)) { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); } else { - logger.log(Level.WARNING, r.toString()); + logger.log(Level.WARNING, resp.getStatus().getReasonPhrase()); } }); client.execute(request).get(); @@ -227,12 +227,12 @@ class EndpointTest { .url(server.getServerConfig().getAddress().base() .resolve("/static1/test1.txt").newBuilder().fragment("frag").build()) .build() - .setResponseListener(r -> { - if (r.status().equals(HttpResponseStatus.OK)) { - assertEquals("Hello Jörg 1", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { + assertEquals("Hello Jörg 1", resp.getBodyAsString(StandardCharsets.UTF_8)); success1.set(true); } else { - logger.log(Level.WARNING, r.toString()); + logger.log(Level.WARNING, resp.getStatus().getReasonPhrase()); } }); client.execute(request1).get(); @@ -240,12 +240,12 @@ class EndpointTest { .url(server.getServerConfig().getAddress().base().resolve("/static2/test2.txt")) .content("{\"a\":\"b\"}","application/json") .build() - .setResponseListener(r -> { - if (r.status().equals(HttpResponseStatus.OK)) { - assertEquals("Hello Jörg 2", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { + assertEquals("Hello Jörg 2",resp.getBodyAsString(StandardCharsets.UTF_8)); success2.set(true); } else { - logger.log(Level.WARNING, r.toString()); + logger.log(Level.WARNING, resp.getStatus().getReasonPhrase()); } }); client.execute(request2).get(); @@ -288,11 +288,11 @@ class EndpointTest { Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/static/" + i + "/test.txt")) .build() - .setResponseListener(r -> { - if (r.status().equals(HttpResponseStatus.OK)) { + .setResponseListener(resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { count.incrementAndGet(); } else { - logger.log(Level.WARNING, r.status().reasonPhrase()); + logger.log(Level.WARNING, resp.getStatus().getReasonPhrase()); } }); client.execute(request).get(); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/FileServiceTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/FileServiceTest.java index dcd33db..b95bc76 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/FileServiceTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/FileServiceTest.java @@ -44,8 +44,8 @@ class FileServiceTest { Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/static/test.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); }); logger.log(Level.INFO, request.toString()); @@ -79,8 +79,8 @@ class FileServiceTest { .setVersion(HttpVersion.valueOf("HTTP/2.0")) .url(server.getServerConfig().getAddress().base().resolve("/static/test.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); }); logger.log(Level.INFO, request.toString()); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/PostTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/PostTest.java index 21679a5..665a901 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/PostTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/PostTest.java @@ -45,8 +45,8 @@ class PostTest { .addParameter("a", "b") .addFormParameter("name", "Jörg") .build() - .setResponseListener(r -> { - if (r.status().equals(HttpResponseStatus.OK)) { + .setResponseListener(resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { success.set(true); } }); @@ -83,8 +83,8 @@ class PostTest { .addParameter("a", "b") .addFormParameter("name", "Jörg") .build() - .setResponseListener(r -> { - if (r.status().equals(HttpResponseStatus.OK)) { + .setResponseListener(resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { success.set(true); } }); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureFileServiceTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureFileServiceTest.java index 91a8d96..728e4d5 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureFileServiceTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureFileServiceTest.java @@ -53,8 +53,8 @@ class SecureFileServiceTest { .setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/static/test.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); }); logger.log(Level.INFO, request.toString()); @@ -94,8 +94,8 @@ class SecureFileServiceTest { .setVersion(HttpVersion.valueOf("HTTP/2.0")) .url(server.getServerConfig().getAddress().base().resolve("/static/test.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); }); logger.log(Level.INFO, request.toString()); @@ -136,8 +136,8 @@ class SecureFileServiceTest { .setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base().resolve("/static/test.txt")) .build() - .setResponseListener(r -> { - assertEquals("Hello Jörg", r.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + assertEquals("Hello Jörg", resp.getBodyAsString(StandardCharsets.UTF_8)); success.set(true); }); logger.log(Level.INFO, request.toString()); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp1Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp1Test.java index f30637d..800dff7 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp1Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp1Test.java @@ -9,11 +9,11 @@ import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; import org.xbib.netty.http.client.transport.Transport; import org.xbib.netty.http.common.HttpAddress; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Domain; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -43,11 +43,7 @@ class SecureHttp1Test { .trustInsecure() .build(); AtomicInteger counter = new AtomicInteger(); - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); - counter.getAndIncrement(); - }; + final ResponseListener responseListener = resp -> counter.getAndIncrement(); try { server.accept(); Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) @@ -81,11 +77,7 @@ class SecureHttp1Test { .setPoolNodeConnectionLimit(2) .build(); AtomicInteger counter = new AtomicInteger(); - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "status = " + fullHttpResponse.status() + " response body = " + response); - counter.incrementAndGet(); - }; + final ResponseListener responseListener = resp -> counter.incrementAndGet(); try { for (int i = 0; i < loop; i++) { Request request = Request.get().setVersion(HttpVersion.HTTP_1_1) @@ -129,12 +121,7 @@ class SecureHttp1Test { .setPoolNodeConnectionLimit(threads) .build(); AtomicInteger counter = new AtomicInteger(); - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "response listener: headers = " + fullHttpResponse.headers().entries() + - // " response body = " + response); - counter.incrementAndGet(); - }; + final ResponseListener responseListener = resp -> counter.incrementAndGet(); try { ExecutorService executorService = Executors.newFixedThreadPool(threads); for (int n = 0; n < threads; n++) { diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp2Test.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp2Test.java index 3ca90a8..5a04aa1 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp2Test.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/SecureHttp2Test.java @@ -8,6 +8,7 @@ import org.xbib.netty.http.client.Request; import org.xbib.netty.http.client.listener.ResponseListener; import org.xbib.netty.http.client.transport.Transport; import org.xbib.netty.http.common.HttpAddress; +import org.xbib.netty.http.common.HttpResponse; import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Domain; @@ -44,10 +45,9 @@ class SecureHttp2Test { .build(); AtomicInteger counter = new AtomicInteger(); // a single instance of HTTP/2 response listener, always receives responses out-of-order - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - logger.log(Level.INFO, "response listener: headers = " + fullHttpResponse.headers().entries() + - " response body = " + response); + final ResponseListener responseListener = resp -> { + logger.log(Level.INFO, "response listener: headers = " + resp.getHeaders() + + " response body = " + resp.getBodyAsString(StandardCharsets.UTF_8)); counter.incrementAndGet(); }; try { @@ -89,17 +89,12 @@ class SecureHttp2Test { .build(); AtomicInteger counter = new AtomicInteger(); // a single instance of HTTP/2 response listener, always receives responses out-of-order - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "response listener: headers = " + fullHttpResponse.headers().entries() + - // " response body = " + response); - counter.incrementAndGet(); - }; + final ResponseListener responseListener = resp -> counter.incrementAndGet(); try { // single transport, single thread Transport transport = client.newTransport(); for (int i = 0; i < loop; i++) { - String payload = Integer.toString(0) + "/" + Integer.toString(i); + String payload = 0 + "/" + i; Request request = Request.get().setVersion("HTTP/2.0") .url(server.getServerConfig().getAddress().base()) .content(payload, "text/plain") @@ -141,12 +136,7 @@ class SecureHttp2Test { .build(); AtomicInteger counter = new AtomicInteger(); // a HTTP/2 listener always receives responses out-of-order - final ResponseListener responseListener = fullHttpResponse -> { - String response = fullHttpResponse.content().toString(StandardCharsets.UTF_8); - //logger.log(Level.INFO, "response listener: headers = " + fullHttpResponse.headers().entries() + - // " response body = " + response); - counter.incrementAndGet(); - }; + final ResponseListener responseListener = resp -> counter.incrementAndGet(); try { // note: for HTTP/2 only, we can use a single shared transport final Transport transport = client.newTransport(); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/StreamTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/StreamTest.java index 481c5e8..88ab8fa 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/StreamTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/StreamTest.java @@ -47,9 +47,9 @@ class StreamTest { .url(server.getServerConfig().getAddress().base().resolve("/")) .content("my body parameter", "text/plain") .build() - .setResponseListener(response -> { - if (response.status().equals(HttpResponseStatus.OK)) { - assertEquals("Hello World", response.content().toString(StandardCharsets.UTF_8)); + .setResponseListener(resp -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { + assertEquals("Hello World", resp.getBodyAsString(StandardCharsets.UTF_8)); count.incrementAndGet(); } }); diff --git a/settings.gradle b/settings.gradle index 1c653e4..3d44af8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,6 @@ include 'netty-http-common' include 'netty-http-client' +include 'netty-http-client-rest' include 'netty-http-server' include 'netty-http-server-reactive' include 'netty-http-server-rest'