Example usage for org.apache.wicket.protocol.ws.javax WicketServerApplicationConfig WicketServerApplicationConfig

List of usage examples for org.apache.wicket.protocol.ws.javax WicketServerApplicationConfig WicketServerApplicationConfig

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.ws.javax WicketServerApplicationConfig WicketServerApplicationConfig.

Prototype

WicketServerApplicationConfig

Source Link

Usage

From source file:org.efaps.maven.jetty.JettyRunMojo.java

License:Apache License

/**
 * Runs the eFaps Jetty server./*from w w w  . j  a  va 2  s  .  c om*/
 *
 * @throws MojoExecutionException if Jetty web server could not be started
 */
@Override
public void execute() throws MojoExecutionException {
    init();

    final Server server = new Server();

    try {
        if (this.envFile != null) {
            final File file = new File(this.envFile);
            if (file.exists()) {
                final EnvConfiguration envConfiguration = new EnvConfiguration();
                envConfiguration.setJettyEnvXml(file.toURI().toURL());
                final WebAppContext webcontext = new WebAppContext();
                envConfiguration.configure(webcontext);
            }
        }
    } catch (final MalformedURLException e) {
        throw new MojoExecutionException("Could not read the Jetty env", e);
    } catch (final SAXException e) {
        throw new MojoExecutionException("Could not read the Jetty env", e);
    } catch (final IOException e) {
        throw new MojoExecutionException("Could not read the Jetty env", e);
    } catch (final Exception e) {
        throw new MojoExecutionException("Could not read the Jetty env", e);
    }

    getLog().info("Starting jetty Version " + server.getClass().getPackage().getImplementationVersion());

    server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", this.maxFormContentSize);
    server.setAttribute("org.eclipse.jetty.server.Request.maxFormKeys", this.maxFormKeys);

    final HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setRequestHeaderSize(131072);
    final ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
    http.setPort(this.port);
    http.setHost(this.host);

    server.addConnector(http);

    final ContextHandlerCollection contexts = new ContextHandlerCollection();
    server.setHandler(contexts);

    System.setProperty("java.security.auth.login.config", this.jaasConfigFile);
    final ServerDefinition serverDef = ServerDefinition.read(this.configFile);
    //needed as default, must be loaded ad least
    new WebAppContext();

    final ServletContextHandler context = new ServletContextHandler(contexts, "/eFaps",
            ServletContextHandler.SESSIONS);
    serverDef.updateServer(context);

    try {
        if (serverDef.isWebsocket()) {
            final Set<Class<? extends Endpoint>> discoveredExtendedEndpoints = new HashSet<>();

            // Initialize javax.websocket layer
            final ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);

            final WicketServerApplicationConfig appConfig = new WicketServerApplicationConfig();
            final Set<ServerEndpointConfig> seconfigs = appConfig
                    .getEndpointConfigs(discoveredExtendedEndpoints);

            if (seconfigs != null) {
                for (final ServerEndpointConfig seconfig : seconfigs) {
                    wscontainer.addEndpoint(seconfig);
                }
            }
            new SocketInitializer().onStartup(null, context.getServletContext());
        }
        getLog().info("Starting Server");
        server.start();
        getLog().info("Server Started");
        server.join();
    } catch (final Exception e) {
        throw new MojoExecutionException("Could not Start Jetty Server", e);
    }
}