use of org.glassfish.grizzly.http.server.ServerConfiguration in project jersey by jersey.
the class App method startServer.
/**
* Starts Grizzly HTTP server exposing static content, JAX-RS resources
* and web sockets defined in this application.
*
* @param webRootPath static content root path.
* @return Grizzly HTTP server.
*/
public static HttpServer startServer(String webRootPath) {
final HttpServer server = new HttpServer();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
server.shutdownNow();
}
}));
final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT);
server.addListener(listener);
final ServerConfiguration config = server.getServerConfiguration();
// add handler for serving static content
config.addHttpHandler(new StaticContentHandler(webRootPath), APP_PATH);
// add handler for serving JAX-RS resources
config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class), API_PATH);
try {
// Start the server.
server.start();
} catch (Exception ex) {
throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
}
return server;
}
use of org.glassfish.grizzly.http.server.ServerConfiguration in project jersey by jersey.
the class GrizzlyHttpServerFactory method createHttpServer.
/**
* Create new {@link HttpServer} instance.
*
* @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path
* segment will be used as context path, the rest will be ignored.
* @param handler {@link HttpHandler} instance.
* @param secure used for call {@link NetworkListener#setSecure(boolean)}.
* @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}.
* @param start if set to false, server will not get started, this allows end users to set
* additional properties on the underlying listener.
* @return newly created {@code HttpServer}.
* @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
* @see GrizzlyHttpContainer
*/
public static HttpServer createHttpServer(final URI uri, final GrizzlyHttpContainer handler, final boolean secure, final SSLEngineConfigurator sslEngineConfigurator, final boolean start) {
final String host = (uri.getHost() == null) ? NetworkListener.DEFAULT_NETWORK_HOST : uri.getHost();
final int port = (uri.getPort() == -1) ? (secure ? Container.DEFAULT_HTTPS_PORT : Container.DEFAULT_HTTP_PORT) : uri.getPort();
final NetworkListener listener = new NetworkListener("grizzly", host, port);
listener.getTransport().getWorkerThreadPoolConfig().setThreadFactory(new ThreadFactoryBuilder().setNameFormat("grizzly-http-server-%d").setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());
listener.setSecure(secure);
if (sslEngineConfigurator != null) {
listener.setSSLEngineConfig(sslEngineConfigurator);
}
final HttpServer server = new HttpServer();
server.addListener(listener);
// Map the path to the processor.
final ServerConfiguration config = server.getServerConfiguration();
if (handler != null) {
final String path = uri.getPath().replaceAll("/{2,}", "/");
final String contextPath = path.endsWith("/") ? path.substring(0, path.length() - 1) : path;
config.addHttpHandler(handler, HttpHandlerRegistration.bulder().contextPath(contextPath).build());
}
config.setPassTraceRequest(true);
config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);
if (start) {
try {
// Start the server.
server.start();
} catch (final IOException ex) {
server.shutdownNow();
throw new ProcessingException(LocalizationMessages.FAILED_TO_START_SERVER(ex.getMessage()), ex);
}
}
return server;
}
use of org.glassfish.grizzly.http.server.ServerConfiguration in project dukescript-presenters by dukescript.
the class KoBrowserTest method compatibilityTests.
@Factory
public static Object[] compatibilityTests() throws Exception {
Browser.LOG.setLevel(Level.FINE);
Browser.LOG.addHandler(new ConsoleHandler());
final BrowserBuilder bb = BrowserBuilder.newBrowser(new Browser("KoBrowserTest")).loadClass(KoBrowserTest.class).loadPage("empty.html").invoke("initialized");
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
bb.showAndWait();
}
});
List<Object> res = new ArrayList<Object>();
Class<? extends Annotation> test = loadClass().getClassLoader().loadClass(KOTest.class.getName()).asSubclass(Annotation.class);
Class[] arr = (Class[]) loadClass().getDeclaredMethod("tests").invoke(null);
final HttpServer s = Browser.findServer(browserPresenter);
ServerConfiguration conf = s.getServerConfiguration();
conf.addHttpHandler(new DynamicHTTP(s), "/dynamic");
for (Class c : arr) {
for (Method m : c.getMethods()) {
if (m.getAnnotation(test) != null) {
res.add(new KOScript(browserPresenter, m));
}
}
}
return res.toArray();
}
use of org.glassfish.grizzly.http.server.ServerConfiguration in project jersey by jersey.
the class Main method startServer.
public static HttpServer startServer(String webRootPath) {
final HttpServer server = new HttpServer();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
server.shutdownNow();
}
}));
final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT);
server.addListener(listener);
final ServerConfiguration config = server.getServerConfiguration();
// add handler for serving static content
config.addHttpHandler(new CLStaticHttpHandler(Main.class.getClassLoader(), WEB_ROOT), APP_PATH);
// add handler for serving JAX-RS resources
config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class), APP_PATH);
try {
// Start the server.
server.start();
} catch (Exception ex) {
throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
}
return server;
}
use of org.glassfish.grizzly.http.server.ServerConfiguration in project jersey by jersey.
the class Main method startServer.
public static HttpServer startServer(String webRootPath) {
final HttpServer server = new HttpServer();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
server.shutdownNow();
}
}));
final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT);
server.addListener(listener);
final ServerConfiguration config = server.getServerConfiguration();
// add handler for serving static content
config.addHttpHandler(new CLStaticHttpHandler(Main.class.getClassLoader(), WEB_ROOT), APP_PATH);
// add handler for serving JAX-RS resources
config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class), APP_PATH);
try {
// Start the server.
server.start();
} catch (Exception ex) {
throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
}
return server;
}
Aggregations