Skip to content

Commit

Permalink
put nosto changes on top play master
Browse files Browse the repository at this point in the history
  • Loading branch information
renat-nosto committed Feb 7, 2019
1 parent 41f821f commit 55c3292
Show file tree
Hide file tree
Showing 27 changed files with 317 additions and 210 deletions.
8 changes: 4 additions & 4 deletions framework/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ require: &allDependencies
- org.hamcrest -> hamcrest-all 1.3
- junit 4.12
- jregex 1.2_01
- log4j 1.2.17
- net.sf.ehcache -> ehcache 2.10.6
- net.sf.ezmorph -> ezmorph 1.0.6
- net.sf.jsr107cache -> jsr107cache 1.1
Expand All @@ -57,7 +56,7 @@ require: &allDependencies
- javax.persistence -> javax.persistence-api 2.2
- org.hibernate.common -> hibernate-commons-annotations 5.0.1.Final
- org.hibernate -> hibernate-validator 5.4.1.Final
- org.jboss.logging -> jboss-logging 3.3.0.Final
- org.jboss.logging -> jboss-logging 3.3.0.Final
- org.jboss.spec.javax.transaction -> jboss-transaction-api_1.2_spec 1.0.1.Final
- javax.persistence -> javax.persistence-api 2.2
- javax.xml.bind -> jaxb-api 2.3.1
Expand All @@ -69,12 +68,13 @@ require: &allDependencies
- org.javassist -> javassist 3.24.0-GA
- io.netty -> netty 3.10.6.Final
- org.postgresql -> postgresql 42.2.4
- org.slf4j -> slf4j-api 1.7.22
- org.slf4j -> slf4j-log4j12 1.7.22
- org.yaml -> snakeyaml 1.17
- net.spy -> spymemcached 2.12.1
- com.thoughtworks.xstream -> xstream 1.4.9
- xmlpull 1.1.3.4d_b4_min
- org.apache.logging.log4j -> log4j-core 2.8.2
- org.apache.logging.log4j -> log4j-api 2.8.2
- org.apache.logging.log4j -> log4j-slf4j-impl 2.8.2

# Default repositories, used for all projects
repositories:
Expand Down
Binary file removed framework/lib/log4j-1.2.17.jar
Binary file not shown.
Binary file added framework/lib/log4j-api-2.8.2.jar
Binary file not shown.
Binary file added framework/lib/log4j-core-2.8.2.jar
Binary file not shown.
Binary file added framework/lib/log4j-slf4j-impl-2.8.2.jar
Binary file not shown.
Binary file removed framework/lib/slf4j-api-1.7.22.jar
Binary file not shown.
Binary file removed framework/lib/slf4j-log4j12-1.7.22.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion framework/pym/play/commands/autotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def autotest(app, args):
sys.exit(-1)

# read parameters
add_options = []
add_options = []
if args.count('--unit'):
args.remove('--unit')
add_options.append('-DrunUnitTests')
Expand Down Expand Up @@ -90,6 +90,7 @@ def autotest(app, args):
if os.path.exists(test_result):
shutil.rmtree(test_result)
sout = open(os.path.join(app.log_path(), 'system.out'), 'w')
args.append('-Dplay.autotest')
java_cmd = app.java_cmd(args)
try:
play_process = subprocess.Popen(java_cmd, env=os.environ, stdout=sout)
Expand Down
177 changes: 95 additions & 82 deletions framework/src/play/Logger.java

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions framework/src/play/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public boolean isProd() {
* The framework id to use
*/
public static void init(File root, String id) {
long start = System.currentTimeMillis();
Logger.info("Play initializing");

// Simple things
Play.id = id;
Play.started = false;
Expand Down Expand Up @@ -334,6 +337,8 @@ public static void init(File root, String id) {
pluginCollection.onApplicationReady();

Play.initialized = true;
long duration = (System.currentTimeMillis() - start) / 1000;
Logger.info("Play initialized (%s s)", duration);
}

public static void guessFrameworkPath() {
Expand Down Expand Up @@ -469,8 +474,9 @@ private static Properties readOneConfigurationFile(String filename) {
* Start the application. Recall to restart !
*/
public static synchronized void start() {
long start = System.currentTimeMillis();
try {

Logger.info(started ? "Play restarting" : "Play starting");
if (started) {
stop();
}
Expand Down Expand Up @@ -592,19 +598,24 @@ public void run() {
}
throw new UnexpectedException(e);
}
long duration = (System.currentTimeMillis() - start) / 1000;
Logger.info("Play started (%s s)", duration);
}

/**
* Stop the application
*/
public static synchronized void stop() {
if (started) {
long start = System.currentTimeMillis();
Logger.trace("Stopping the play application");
pluginCollection.onApplicationStop();
started = false;
Cache.stop();
Router.lastLoading = 0L;
Invoker.resetClassloaders();
long duration = (System.currentTimeMillis() - start) / 1000;
Logger.info("Play stopped (%s s)", duration);
}
}

Expand Down Expand Up @@ -657,6 +668,9 @@ public static synchronized void detectChanges() {
if (mode == Mode.PROD) {
return;
}
if (runningInTestMode() && System.getProperty("play.autotest") != null) {
return;
}
try {
pluginCollection.beforeDetectingChanges();
if (!pluginCollection.detectClassesChange()) {
Expand Down Expand Up @@ -882,7 +896,7 @@ public static File getFile(String path) {
* @return true if test mode
*/
public static boolean runningInTestMode() {
return id.matches("test|test-?.*");
return id.startsWith("test");
}

/**
Expand Down
11 changes: 7 additions & 4 deletions framework/src/play/classloading/ApplicationClassloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;

import play.Logger;
import play.Play;
import play.cache.Cache;
Expand Down Expand Up @@ -335,9 +334,13 @@ public void detectChanges() throws RestartNeededException {
Play.classes.classes.remove(applicationClass.name);
currentState = new ApplicationClassloaderState();// show others that we have changed..
} else {
int sigChecksum = applicationClass.sigChecksum;
applicationClass.enhance();
if (sigChecksum != applicationClass.sigChecksum) {
if (applicationClass.name.startsWith("controllers.")) {
int sigChecksum = applicationClass.sigChecksum;
applicationClass.enhance();
if (sigChecksum != applicationClass.sigChecksum) {
dirtySig = true;
}
} else {
dirtySig = true;
}
BytecodeCache.cacheBytecode(applicationClass.enhancedByteCode, applicationClass.name, applicationClass.javaSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javassist.CtMethod;
import javassist.CtNewConstructor;
import javassist.NotFoundException;
import javassist.bytecode.AccessFlag;
import javassist.expr.ExprEditor;
import javassist.expr.FieldAccess;
import play.Logger;
Expand All @@ -31,6 +32,9 @@ public class PropertiesEnhancer extends Enhancer {
private boolean enabled = Boolean.parseBoolean(Play.configuration.getProperty("play.propertiesEnhancer.enabled", "true"));
private boolean generateAccessors = Boolean.parseBoolean(Play.configuration.getProperty("play.propertiesEnhancer.generateAccessors", "true"));

private static final boolean constructorsOnly =
Boolean.parseBoolean(Play.configuration.getProperty("play.propertiesEnhancer.constructorsOnly", "false"));

@Override
public void enhanceThisClass(ApplicationClass applicationClass) throws Exception {

Expand All @@ -57,7 +61,8 @@ private void addDefaultConstructor(CtClass ctClass) {
try {
boolean hasDefaultConstructor = hasDefaultConstructor(ctClass);
if (!hasDefaultConstructor && !ctClass.isInterface()) {
CtConstructor defaultConstructor = CtNewConstructor.make("public " + ctClass.getSimpleName() + "() {}", ctClass);
CtConstructor defaultConstructor = CtNewConstructor.make("public " + ctClass.getSimpleName()
+ "() { play.Logger.error(new Throwable(), \"Unexpected constructor call\", new Object[0]); }", ctClass);
ctClass.addConstructor(defaultConstructor);
}
} catch (Exception e) {
Expand Down Expand Up @@ -227,7 +232,7 @@ public static Object invokeReadProperty(Object o, String property, String target
Object result = getterMethod.invoke(o);
return result;
} catch (NoSuchMethodException e) {
return o.getClass().getField(property).get(o);
throw e;
} catch (InvocationTargetException e) {
throw e.getCause();
}
Expand Down
15 changes: 12 additions & 3 deletions framework/src/play/db/jpa/JPAPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package play.db.jpa;

import org.apache.log4j.Level;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;
Expand Down Expand Up @@ -108,14 +111,20 @@ public EntityManager em(String key) {
*/
@Override
public void onApplicationStart() {
org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.OFF);
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig("org.hibernate.SQL");
loggerConfig.setLevel(Level.OFF);
ctx.updateLoggers();

Set<String> dBNames = Configuration.getDbNames();
for (String dbName : dBNames) {
Configuration dbConfig = new Configuration(dbName);

if (dbConfig.getProperty("jpa.debugSQL", "false").equals("true")) {
org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.ALL);
ctx = (LoggerContext) LogManager.getContext(false);
loggerConfig = ctx.getConfiguration().getLoggerConfig("org.hibernate.SQL");
loggerConfig.setLevel(Level.ALL);
ctx.updateLoggers();
}

Thread thread = Thread.currentThread();
Expand Down
1 change: 1 addition & 0 deletions framework/src/play/libs/WS.java
Original file line number Diff line number Diff line change
Expand Up @@ -859,5 +859,6 @@ public JsonElement getJson() {
}
}

public abstract byte[] getBytes();
}
}
9 changes: 9 additions & 0 deletions framework/src/play/libs/ws/WSAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,15 @@ public String getString(String encoding) {
}
}

@Override
public byte[] getBytes() {
try {
return response.getResponseBodyAsBytes();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

/**
* get the response as a stream
*
Expand Down
5 changes: 5 additions & 0 deletions framework/src/play/libs/ws/WSUrlFetch.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ public String getString(String encoding) {
}
}

@Override
public byte[] getBytes() {
return body.getBytes();
}

/**
* get the response as a stream
*
Expand Down
36 changes: 23 additions & 13 deletions framework/src/play/plugins/EnhancerPlugin.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
package play.plugins;

import play.Logger;
import java.util.ArrayList;
import java.util.List;

import play.PlayPlugin;
import play.classloading.ApplicationClasses.ApplicationClass;
import play.classloading.enhancers.*;
import play.classloading.enhancers.ContinuationEnhancer;
import play.classloading.enhancers.ControllersEnhancer;
import play.classloading.enhancers.Enhancer;
import play.classloading.enhancers.LocalvariablesNamesEnhancer;
import play.classloading.enhancers.MailerEnhancer;
import play.classloading.enhancers.SigEnhancer;
import play.exceptions.UnexpectedException;

/**
* Plugin used for core tasks
*/
public class EnhancerPlugin extends PlayPlugin {

protected Enhancer[] defaultEnhancers() {
return new Enhancer[] { new PropertiesEnhancer(), new ContinuationEnhancer(), new SigEnhancer(), new ControllersEnhancer(),
new MailerEnhancer(), new LocalvariablesNamesEnhancer() };
}

@Override
public void enhance(ApplicationClass applicationClass) {
for (Enhancer enhancer : defaultEnhancers()) {
List<Enhancer> enhancers = new ArrayList<Enhancer>(4);
if (applicationClass.name.startsWith("controllers.")) {
enhancers.add(new SigEnhancer());
enhancers.add(new ContinuationEnhancer());
enhancers.add(new ControllersEnhancer());
if (applicationClass.name.endsWith("Mailer")) {
enhancers.add(new MailerEnhancer());
}
enhancers.add(new LocalvariablesNamesEnhancer());
} else if (applicationClass.name.endsWith("Mailer")) {
enhancers.add(new MailerEnhancer());
enhancers.add(new LocalvariablesNamesEnhancer());
}
for (Enhancer enhancer : enhancers) {
try {
long start = System.currentTimeMillis();
enhancer.enhanceThisClass(applicationClass);
if (Logger.isTraceEnabled()) {
Logger.trace("%sms to apply %s to %s", System.currentTimeMillis() - start, enhancer.getClass().getSimpleName(),
applicationClass.name);
}
} catch (Exception e) {
throw new UnexpectedException("While applying " + enhancer + " on " + applicationClass.name, e);
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/server/HttpServerPipelineFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class HttpServerPipelineFactory implements ChannelPipelineFactory {

private String pipelineConfig = Play.configuration.getProperty("play.netty.pipeline", "play.server.FlashPolicyHandler,org.jboss.netty.handler.codec.http.HttpRequestDecoder,play.server.StreamChunkAggregator,org.jboss.netty.handler.codec.http.HttpResponseEncoder,org.jboss.netty.handler.stream.ChunkedWriteHandler,play.server.PlayHandler");
private String pipelineConfig = Play.configuration.getProperty("play.netty.pipeline", "play.server.FlashPolicyHandler,play.server.PlayHttpRequestDecoder,play.server.StreamChunkAggregator,org.jboss.netty.handler.codec.http.HttpResponseEncoder,org.jboss.netty.handler.stream.ChunkedWriteHandler,play.server.PlayHandler");

protected static Map<String, Class> classes = new HashMap<>();

Expand Down
19 changes: 15 additions & 4 deletions framework/src/play/server/PlayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,14 @@ else if (host.contains(":")) {
}

boolean secure = false;

Request request = Request.createRequest(remoteAddress, method, path, querystring, contentType, body, uri, host, isLoopback,
Request request = null;
try {
request = Request.createRequest(remoteAddress, method, path, querystring, contentType, body, uri, host, isLoopback,
port, domain, secure, getHeaders(nettyRequest), getCookies(nettyRequest));
} catch (Exception e) {
Logger.error(e, "Failed to create request for %s", uri);
throw e;
}

if (Logger.isTraceEnabled()) {
Logger.trace("parseRequest: end");
Expand Down Expand Up @@ -642,7 +647,13 @@ protected static Map<String, Http.Cookie> getCookies(HttpRequest nettyRequest) {
Map<String, Http.Cookie> cookies = new HashMap<>(16);
String value = nettyRequest.headers().get(COOKIE);
if (value != null) {
Set<Cookie> cookieSet = ServerCookieDecoder.STRICT.decode(value);
Set<Cookie> cookieSet = null;
try{
cookieSet = ServerCookieDecoder.STRICT.decode(value);
}catch(IllegalArgumentException e){
// Attempt to continue without cookies.
Logger.warn(e, "Failed decoding cookies from %s", value);
}
if (cookieSet != null) {
for (Cookie cookie : cookieSet) {
Http.Cookie playCookie = new Http.Cookie();
Expand All @@ -666,7 +677,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws
// Log this, we can't call serve500()
Throwable t = e.getCause();
if (t instanceof TooLongFrameException) {
Logger.error("Request exceeds 8192 bytes");
Logger.error(t, "Request exceeds 16384 bytes");
}
e.getChannel().close();
} catch (Exception ex) {
Expand Down
10 changes: 10 additions & 0 deletions framework/src/play/server/PlayHttpRequestDecoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package play.server;

import org.jboss.netty.handler.codec.http.HttpRequestDecoder;

public class PlayHttpRequestDecoder extends HttpRequestDecoder {

public PlayHttpRequestDecoder() {
super(16384, 16384, 16384);
}
}
Loading

0 comments on commit 55c3292

Please sign in to comment.