Skip to content

Instantly share code, notes, and snippets.

@marcospereira
Last active May 4, 2017 18:12
Show Gist options
  • Save marcospereira/086ad3e065ef1c04f74e8f99d707a4fa to your computer and use it in GitHub Desktop.
Save marcospereira/086ad3e065ef1c04f74e8f99d707a4fa to your computer and use it in GitHub Desktop.
Play internals to handle a request.
public class Foo {
public static void main(String[] args) {
play.Environment env = play.Environment.simple();
play.ApplicationLoader.Context context = play.ApplicationLoader.create(env);
// Keep in mind that plays expects that configuration
// play.application.loader is defined. Otherwise an error
// is raised.
play.api.ApplicationLoader loader = play.api.ApplicationLoader$.MODULE$.apply(context.underlying());
play.api.Application application = loader.load(context.underlying());
play.core.ApplicationProvider applicationProvider = play.core.ApplicationProvider$.MODULE$.apply(application);
scala.Option<play.api.mvc.Result> resultOption = applicationProvider.handleWebCommand(fromAwsRequestToPlayRequest());
if (resultOption.isDefined()) {
// application was able to handle the result
play.api.mvc.Result result = resultOption.get();
} else {
// no handler was found
play.api.mvc.Result result = play.api.mvc.Results$.MODULE$.NotFound();
}
}
// This would translate from AWS Lambda request to a Play request.
private static play.api.mvc.RequestHeader fromAwsRequestToPlayRequest() {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment