/**
 * Copyright (C) 2010 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.alpharogroup.wicket.components.examples;

import org.apache.wicket.util.time.Duration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.webapp.WebAppContext;

import de.alpharogroup.wicket.components.examples.application.WicketApplication;

public class StartComponentExamples
{
	public static void main(String[] args) throws Exception
	{
		int timeout = (int)Duration.ONE_HOUR.getMilliseconds();

		Server server = new Server();
		SocketConnector connector = new SocketConnector();

		// Set some timeout options to make debugging easier.
		connector.setMaxIdleTime(timeout);
		connector.setSoLingerTime(-1);
		connector.setPort(WicketApplication.DEFAULT_HTTP_PORT);
		server.addConnector(connector);

		Resource keystore = Resource.newClassPathResource("/keystore");
		if (keystore != null && keystore.exists())
		{
			// if a keystore for a SSL certificate is available, start a SSL
			// connector on port WicketApplication.DEFAULT_HTTPS_PORT.
			// By default, the quickstart comes with a Apache Wicket Quickstart
			// Certificate that expires about half way september 2021. Do not
			// use this certificate anywhere important as the passwords are
			// available in the source.


			SslContextFactory factory = new SslContextFactory();
			factory.setKeyStoreResource(keystore);
			factory.setKeyStorePassword("wicket");
			factory.setTrustStoreResource(keystore);
			factory.setKeyManagerPassword("wicket");
			SslSocketConnector sslConnector = new SslSocketConnector(factory);
			sslConnector.setMaxIdleTime(timeout);
			sslConnector.setPort(WicketApplication.DEFAULT_HTTPS_PORT);
			connector.setConfidentialPort(WicketApplication.DEFAULT_HTTPS_PORT);
			sslConnector.setAcceptors(4);
			server.addConnector(sslConnector);

			System.out.println("SSL access to the quickstart has been enabled on port "
				+ WicketApplication.DEFAULT_HTTPS_PORT);
			System.out.println("You can access the application using SSL on https://localhost:"
				+ WicketApplication.DEFAULT_HTTPS_PORT);
			System.out.println();
		}

		WebAppContext bb = new WebAppContext();
		bb.setServer(server);
		bb.setContextPath("/");
		bb.setWar("src/main/webapp");

		// START JMX SERVER
		// MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
		// MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
		// server.getContainer().addEventListener(mBeanContainer);
		// mBeanContainer.start();

		server.setHandler(bb);

		try
		{
			System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
			server.start();
			System.in.read();
			System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
			server.stop();
			server.join();
		}
		catch (Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}
}

@@ -998,16 +998,420 @@
 ntext;%0A%0A
+import java.io.File;%0Aimport java.util.EnumSet;%0A%0Aimport javax.servlet.DispatcherType;%0A%0Aimport org.apache.wicket.Application;%0Aimport org.apache.wicket.protocol.http.ContextParamWebApplicationFactory;%0Aimport org.apache.wicket.protocol.http.WicketFilter;%0Aimport org.eclipse.jetty.servlet.DefaultServlet;%0Aimport org.eclipse.jetty.servlet.FilterHolder;%0Aimport org.eclipse.jetty.servlet.ServletContextHandler;%0A%0A
 import d
@@ -3983,10 +3983,1365 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09%0A  /**%0A   * Starts the given wicket application with the given parameters.%0A   * @param applicationClass%0A   * @param contextPath%0A   * @param webapp%0A   * @param httpPort%0A   * @param httpsPort%0A   * @param maxInactiveInterval%0A   * @param filterPath%0A   * @throws Exception%0A   */%0A  public static void startWebapp(%0A    final Class%3C? extends Application%3E applicationClass,%0A    String contextPath,%0A    File webapp,%0A    int httpPort,%0A    int httpsPort,%0A    int maxInactiveInterval,%0A    String filterPath) throws Exception %7B%0A%0A    final Server server = new Server(httpPort);%0A%0A    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);%0A    context.setContextPath(contextPath);%0A%0A    context.setResourceBase(webapp.getAbsolutePath());%0A%0A    final FilterHolder filter = new FilterHolder(WicketFilter.class);%0A    filter.setInitParameter(ContextParamWebApplicationFactory.APP_CLASS_PARAM, applicationClass.getName());%0A    filter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, filterPath);%0A    context.addFilter(filter, filterPath, EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));%0A    context.addServlet(DefaultServlet.class, filterPath);%0A%0A    context.getSessionHandler().getSessionManager().setMaxInactiveInterval(maxInactiveInterval);%0A%0A    server.setHandler(context);%0A%0A    server.start();%0A    server.join();%0A%0A  %7D%0A
 %7D%0A

Update StartComponentExamples.java