Refine search
/** * Provides an instance from the application. * * @param clazz the type's class. * @param <T> the type to return, using `app.injector.instanceOf` * @return an instance of type T. */ protected <T> T instanceOf(Class<T> clazz) { return app.injector().instanceOf(clazz); }
/** * Starts a new application. * * @param application the application to start. */ public static void start(Application application) { play.api.Play.start(application.asScala()); }
@Deprecated public static Result route(Application app, RequestBuilder requestBuilder, byte[] body, long timeout) { return wrapScalaResult(Scala.orNull(play.api.test.Helpers.jRoute(app.getWrappedApplication(), requestBuilder.build()._underlyingRequest(), body)), timeout); }
/** * Retrieve Lang availables from the application configuration. * * @param app the current application. * @return the list of available Lang. */ public static List<Lang> availables(Application app) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables()); return availableLangs.stream().map(Lang::new).collect(toList()); }
/** * Guess the preferred lang in the langs set passed as argument. * The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application. * * @param app the currept application * @param availableLangs the set of langs from which to guess the preferred * @return the preferred lang. */ public static Lang preferred(Application app, List<Lang> availableLangs) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); Stream<Lang> stream = availableLangs.stream(); List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList()); return new Lang(langs.preferred(Scala.toSeq(langSeq))); } }
/** * Executes a block of code in a running application. * * @param application the application context. * @param block the block to run after the Play app is started. */ public static void running(Application application, final Runnable block) { Helpers$.MODULE$.running(application.asScala(), asScala(() -> { block.run(); return null; })); }
/** * Route the request considering the given timeout. * * @param app The application used while routing and executing the request * @param requestBuilder the request builder * @param timeout the amount of time, in milliseconds, to wait for the body to be produced. * @return the result */ @SuppressWarnings("unchecked") public static Result route(Application app, RequestBuilder requestBuilder, long timeout) { final scala.Option<scala.concurrent.Future<play.api.mvc.Result>> opt = play.api.test.Helpers.jRoute( app.asScala(), requestBuilder.build().asScala(), requestBuilder.body() ); return wrapScalaResult(Scala.orNull(opt), timeout); }
IoCApplication(final Map<ApplicationLoader, Application> values, final Map<String, String> routing) { this.delegates = new ArrayList<>(values.values()); this.injector = new IoCInjector( values.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.getValue().injector(), (a, b) -> { throw new IllegalStateException("Conflicting keys for " + a + "/" + b); }, LinkedHashMap::new)), routing); this.scalaRef = delegates.iterator().next().asScala(); this.java = new DefaultApplication(this, injector.asJava()); playxIntegration(); }
public void onStart(Application app) { super.onStart(app); String value = app.configuration().getString("my.thing"); // do something with value }
/** * A test Netty web server. * * @param port HTTP port to bind on. * @param application The Application to load in this server. */ public TestServer(int port, Application application) { super(port, application.getWrappedApplication(), play.libs.Scala.<Object>None(), play.libs.Scala.<ServerProvider>None()); }
/** * Starts a new application. */ public static void start(Application application) { play.api.Play.start(application.getWrappedApplication()); }
config.addClass(Class.forName(clazz, true, application.classloader())); } catch(Throwable e) { throw ebeanConf.reportError( if(!application.isProd()) { boolean evolutionsEnabled = !"disabled".equals(application.configuration().getString("evolutionplugin")); if(evolutionsEnabled) { String evolutionScript = generateEvolutionScript(servers.get(key), config); if(evolutionScript != null) { File evolutions = application.getFile("conf/evolutions/" + key + "/1.sql"); if(!evolutions.exists() || Files.readFile(evolutions).startsWith("# --- Created by Ebean DDL")) { Files.createDirectory(application.getFile("conf/evolutions/" + key)); Files.writeFileIfChanged(evolutions, evolutionScript);
/** * Load a Yaml file from the classpath. */ public static Object load(String resourceName) { return load( play.Play.application().resourceAsStream(resourceName), play.Play.application().classloader() ); }
private static Reflections getReflections(Application app, String packageName) { if (app.isTest()) { return ReflectionsCache$.MODULE$.getReflections(app.classloader(), packageName); } else { return new Reflections(getReflectionsConfiguration(packageName, app.classloader())); } }
@Override public Object apply(String s) { try { return Play.application().classloader().loadClass(s).newInstance(); } catch (Exception e) { throw new RuntimeException("Could not instantiate class '" + s + "'.", e); } }
public Result showVersion() throws IOException { final Application application = injector.instanceOf(Application.class); final InputStream versionAsStream = application.resourceAsStream("internal/version.json"); final String versionAsString = IOUtils.toString(versionAsStream, StandardCharsets.UTF_8); return ok(versionAsString).as(Http.MimeTypes.JSON); }
/** * Retrieve Lang availables from the application configuration. * * @param app the current application. * @return the list of available Lang. */ public static List<Lang> availables(Application app) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables()); return availableLangs.stream().map(Lang::new).collect(toList()); }
/** * Guess the preferred lang in the langs set passed as argument. * The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application. * * @param app the currept application * @param availableLangs the set of langs from which to guess the preferred * @return the preferred lang. */ public static Lang preferred(Application app, List<Lang> availableLangs) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); Stream<Lang> stream = availableLangs.stream(); List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList()); return new Lang(langs.preferred(Scala.toSeq(langSeq))); } }
/** * Executes a block of code in a running application. * * @param application the application context. * @param block the block to run after the Play app is started. */ public static void running(Application application, final Runnable block) { Helpers$.MODULE$.running(application.asScala(), asScala(() -> { block.run(); return null; })); }