Skip to content

Commit

Permalink
#25 split Netty3 and Netty4 to separate modules
Browse files Browse the repository at this point in the history
* users need to add dependency either `replay-netty3` or `replay-netty4`
* each module has its own `play.server.Server` class
* replay own integration tests run on Netty4

implementation details:
* class `NettyInvocation` was not really needed anymore; now we just extend `Invocation`.
* I had to find a replacement for `Server.httpPort` which was only used in PDF module.
I hope `request.getBase()` is as good as `"http://localhost:" + Server.httpPort`. :)
  • Loading branch information
asolntsev committed Jan 13, 2023
1 parent abc010a commit ded653f
Show file tree
Hide file tree
Showing 35 changed files with 120 additions and 63 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ You may find some warnings for "illegal reflective access" when running the appl

With this flag `--add-opens java.base/java.lang=ALL-UNNAMED` these warnings from `guice` may be suppressed (this will be fixed in a future version of `guice`).

To suppress the "illegal reflective access" warnings from `netty` RePlay should upgrade it's `netty`
dependency from `3.10.6.Final` to `io.netty:netty-all:4.1.43.Final` or greater.
A [pull request for this exists](https://github.com/codeborne/replay/pull/25), but still needs some work.
To suppress the "illegal reflective access" warnings from `netty` you could use `replay-netty4` instead of `replay-netty3`.


## Plugins
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ subprojects {
}

ext {
commonsLangVersion = '2.6'
slf4jVersion = '2.0.6'
assertjVersion = '3.24.1'
mockitoVersion = '4.11.0'
Expand Down
2 changes: 1 addition & 1 deletion fastergt/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies {
implementation project(':framework')
implementation('org.eclipse.jdt:org.eclipse.jdt.core:3.32.0') {transitive = false}
implementation('commons-lang:commons-lang:2.6')
implementation("commons-lang:commons-lang:$commonsLangVersion")
testImplementation project(':framework').sourceSets.test.compileClasspath
}

Expand Down
5 changes: 1 addition & 4 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
api('org.apache.commons:commons-email:1.5') {transitive = false}
api('commons-fileupload:commons-fileupload:1.4')
api('commons-io:commons-io:2.11.0')
implementation('commons-lang:commons-lang:2.6')
implementation("commons-lang:commons-lang:$commonsLangVersion")
api('commons-logging:commons-logging:1.2')
api('javax.mail:mail:1.4.7')
api('javax.inject:javax.inject:1')
Expand All @@ -29,9 +29,6 @@ dependencies {
api('org.hibernate:hibernate-validator:7.0.5.Final')
api('javax.persistence:javax.persistence-api:2.2')
implementation('org.hibernate:hibernate-ehcache:5.6.12.Final') {transitive = false}
// Upgrade to Netty4 is WIP: https://github.com/codeborne/replay/pull/25
api('io.netty:netty:3.10.6.Final')
api('io.netty:netty-all:4.1.87.Final')
api("org.slf4j:slf4j-api:$slf4jVersion")
api("org.slf4j:slf4j-reload4j:$slf4jVersion")
api("org.slf4j:jul-to-slf4j:$slf4jVersion")
Expand Down
3 changes: 1 addition & 2 deletions framework/src/play/Invoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
import play.server.NettyInvocation;
import play.utils.PThreadFactory;

import java.util.concurrent.Future;
Expand Down Expand Up @@ -32,7 +31,7 @@ public class Invoker {
* The code to run
* @return The future object, to know when the task is completed
*/
public Future<?> invoke(NettyInvocation invocation) {
public Future<?> invoke(Invocation invocation) {
Monitor monitor = MonitorFactory.getMonitor("Invoker queue size", "elmts.");
monitor.add(executor.getQueue().size());
invocation.onQueued();
Expand Down
6 changes: 0 additions & 6 deletions framework/src/play/server/NettyInvocation.java

This file was deleted.

13 changes: 0 additions & 13 deletions framework/src/play/server/Server.java

This file was deleted.

14 changes: 0 additions & 14 deletions framework/test/play/mvc/CookieDataCodecTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package play.mvc;

import org.jboss.netty.handler.codec.http.cookie.Cookie;
import org.jboss.netty.handler.codec.http.cookie.ServerCookieDecoder;
import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static play.mvc.CookieDataCodec.decode;
Expand Down Expand Up @@ -171,16 +168,5 @@ public void decode_values_with_dollar_in_them2() throws UnsupportedEncodingExcep
Map<String, String> outMap = new HashMap<>(1);
decode(outMap, data);
assertThat(outMap.isEmpty());

Set<Cookie> cookieSet = ServerCookieDecoder.STRICT.decode(data);
if (cookieSet != null) {
for (Cookie cookie : cookieSet) {
Http.Cookie playCookie = new Http.Cookie(cookie.name(), cookie.value());
playCookie.path = cookie.path();
playCookie.domain = cookie.domain();
playCookie.secure = cookie.isSecure();
playCookie.httpOnly = cookie.isHttpOnly();
}
}
}
}
8 changes: 8 additions & 0 deletions netty3/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencies {
api('io.netty:netty:3.10.6.Final')
implementation project(':framework')
testImplementation project(':framework').sourceSets.test.compileClasspath
implementation("commons-lang:commons-lang:$commonsLangVersion")
}

apply from: rootProject.file('gradle/deploy.gradle')
14 changes: 14 additions & 0 deletions netty3/src/play/server/Server.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package play.server;

import play.Play;

public class Server extends play.server.netty3.Server {

public Server(Play play) {
super(play);
}

public Server(Play play, int port) {
super(play, port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.jboss.netty.buffer.ChannelBufferFactory;
import org.jboss.netty.buffer.ChannelBufferIndexFinder;
import org.jboss.netty.buffer.WrappedChannelBuffer;
import play.server.ResettableFileInputStream;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBufferInputStream;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.*;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
import org.jboss.netty.handler.codec.http.*;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMessage;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.jboss.netty.handler.codec.http.cookie.Cookie;
import org.jboss.netty.handler.codec.http.cookie.DefaultCookie;
import org.jboss.netty.handler.codec.http.cookie.ServerCookieDecoder;
Expand All @@ -17,6 +31,7 @@
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.Invocation;
import play.InvocationContext;
import play.Invoker;
import play.Play;
Expand All @@ -35,7 +50,6 @@
import play.mvc.Scope.RenderArgs;
import play.mvc.results.NotFound;
import play.mvc.results.RenderStatic;
import play.server.NettyInvocation;
import play.templates.JavaExtensions;
import play.templates.TemplateLoader;
import play.utils.ErrorsCookieCrypter;
Expand Down Expand Up @@ -63,7 +77,17 @@
import static java.util.Collections.unmodifiableList;
import static org.apache.commons.lang.StringUtils.defaultString;
import static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.*;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CACHE_CONTROL;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.COOKIE;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.DATE;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.ETAG;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.EXPIRES;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.HOST;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.IF_MODIFIED_SINCE;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.IF_NONE_MATCH;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.LAST_MODIFIED;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.SET_COOKIE;

public class PlayHandler extends SimpleChannelUpstreamHandler {
private static final Logger logger = LoggerFactory.getLogger(PlayHandler.class);
Expand Down Expand Up @@ -138,7 +162,7 @@ public void messageReceived(final ChannelHandlerContext ctx, MessageEvent messag

private static final Map<String, RenderStatic> staticPathsCache = new HashMap<>();

private class Netty3Invocation extends NettyInvocation {
private class Netty3Invocation extends Invocation {
private final ChannelHandlerContext ctx;
private final Request request;
private final Response response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package play.server;
package play.server.netty3;

import java.io.File;
import java.io.FileInputStream;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package play.server;
package play.server.netty3;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
Expand Down
9 changes: 9 additions & 0 deletions netty4/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies {
api('io.netty:netty-all:4.1.87.Final')

implementation project(':framework')
testImplementation project(':framework').sourceSets.test.compileClasspath
implementation("commons-lang:commons-lang:$commonsLangVersion")
}

apply from: rootProject.file('gradle/deploy.gradle')
14 changes: 14 additions & 0 deletions netty4/src/play/server/Server.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package play.server;

import play.Play;

public class Server extends play.server.netty4.Server {

public Server(Play play) {
super(play);
}

public Server(Play play, int port) {
super(play, port);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
package play.server.netty4;

import io.netty.buffer.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.TooLongFrameException;
import org.apache.commons.lang.StringUtils;
import io.netty.channel.*;
import io.netty.handler.codec.http.*;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.DefaultHttpResponse;
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.http.HttpMessage;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.cookie.Cookie;
import io.netty.handler.codec.http.cookie.DefaultCookie;
import io.netty.handler.codec.http.cookie.ServerCookieDecoder;
import io.netty.handler.codec.http.cookie.ServerCookieEncoder;
import io.netty.handler.stream.ChunkedInput;
import io.netty.handler.stream.ChunkedStream;
import io.netty.handler.stream.ChunkedWriteHandler;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.Invocation;
import play.InvocationContext;
import play.Invoker;
import play.Play;
Expand All @@ -32,20 +52,26 @@
import play.mvc.Scope.RenderArgs;
import play.mvc.results.NotFound;
import play.mvc.results.RenderStatic;
import play.server.NettyInvocation;
import play.templates.JavaExtensions;
import play.templates.TemplateLoader;
import play.utils.Utils;
import play.vfs.VirtualFile;

import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;

import static io.netty.buffer.Unpooled.wrappedBuffer;
import static io.netty.handler.codec.http.HttpHeaders.Names.CACHE_CONTROL;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
Expand All @@ -62,7 +88,6 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.unmodifiableList;
import static org.apache.commons.lang.StringUtils.defaultString;
import static io.netty.buffer.Unpooled.wrappedBuffer;

public class PlayHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
private static final Logger logger = LoggerFactory.getLogger(PlayHandler.class);
Expand Down Expand Up @@ -128,7 +153,7 @@ protected void channelRead0(final ChannelHandlerContext ctx, final FullHttpReque

private static final Map<String, RenderStatic> staticPathsCache = new HashMap<>();

private class Netty4Invocation extends NettyInvocation {
private class Netty4Invocation extends Invocation {
private final ChannelHandlerContext ctx;
private final Request request;
private final Response response;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pdf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
testImplementation project(':framework').sourceSets.test.compileClasspath
testImplementation("org.mockito:mockito-core:$mockitoVersion")

implementation('commons-lang:commons-lang:2.6')
implementation("commons-lang:commons-lang:$commonsLangVersion")
thirdParty("org.xhtmlrenderer:flying-saucer-core:$FLYING_SOURCER_VERSION")
implementation("org.xhtmlrenderer:flying-saucer-pdf:$FLYING_SOURCER_VERSION") {
exclude group: 'org.xhtmlrenderer', module: 'flying-saucer-core'
Expand Down
3 changes: 1 addition & 2 deletions pdf/src/play/modules/pdf/PdfHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import play.mvc.Http;
import play.mvc.Scope;
import play.mvc.TemplateNameResolver;
import play.server.Server;
import play.templates.Template;
import play.templates.TemplateLoader;

Expand Down Expand Up @@ -41,7 +40,7 @@ public boolean isIE(Http.Request request) {
public void renderPDF(PDFDocument document, OutputStream out, @Nullable Http.Request request) {
try {
Map<?, ?> properties = new HashMap<>(Play.configuration);
String uri = request == null ? "" : ("http://localhost:" + Server.httpPort + request.url);
String uri = request == null ? "" : (request.getBase() + request.url);
renderDoc(document, uri, properties, out);
}
catch (Exception e) {
Expand Down
1 change: 1 addition & 0 deletions replay-tests/replay-tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sourceSets {
dependencies {
implementation project(':framework')
implementation project(':fastergt')
implementation project(':netty4')

testImplementation("org.assertj:assertj-core:$assertjVersion")
testImplementation('com.codeborne:selenide:6.9.0')
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rootProject.name = 'replay'
include 'framework'
include 'guice'
include 'liquibase'
include 'netty3'
include 'netty4'
include 'fastergt'
include 'pdf'
include 'excel'
Expand Down

0 comments on commit ded653f

Please sign in to comment.