public abstract class LaunchConfigEmbeddedApplication extends EmbeddedApplicationSupport
EmbeddedApplication
that starts a server based on a subclass provided LaunchConfig
.
import ratpack.handling.Context; import ratpack.handling.Handler; import ratpack.launch.HandlerFactory; import ratpack.launch.LaunchConfig; import ratpack.launch.LaunchConfigBuilder; import ratpack.test.embed.EmbeddedApplication; import ratpack.test.embed.LaunchConfigEmbeddedApplication; import java.io.File; import java.net.HttpURLConnection; import java.net.URI; import java.net.URLConnection; import java.nio.file.Files; EmbeddedApplication application = new LaunchConfigEmbeddedApplication() { protected LaunchConfig createLaunchConfig() { return LaunchConfigBuilder. baseDir(Files.createTempDirectory("ratpack-test")). port(0). build(new HandlerFactory() { public Handler create(LaunchConfig launchConfig) { return new Handler() { public void handle(Context context) { context.getResponse().status(200).send(); } }; } }); } }; URI address = application.getAddress(); HttpURLConnection urlConnection = (HttpURLConnection) address.toURL().openConnection(); urlConnection.connect(); assert urlConnection.getResponseCode() == 200; application.close();
Constructor and Description |
---|
LaunchConfigEmbeddedApplication() |
Modifier and Type | Method and Description |
---|---|
protected abstract LaunchConfig |
createLaunchConfig()
Creates a launch config that defines the application.
|
protected RatpackServer |
createServer()
Creates a server using
RatpackServerBuilder.build(LaunchConfig) , using the launch config returned by createLaunchConfig() . |
close, getAddress, getHttpClient, getServer
protected RatpackServer createServer()
RatpackServerBuilder.build(LaunchConfig)
, using the launch config returned by createLaunchConfig()
.createServer
in class EmbeddedApplicationSupport
protected abstract LaunchConfig createLaunchConfig()
Will be called only once.