package net.usersource.jettyembed;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.webapp.WebAppClassLoader;
import org.mortbay.jetty.webapp.WebAppContext;

import java.net.URL;
import java.security.ProtectionDomain;


public class Startup {

    private static final int JETTY_PORT = 8080;
    private static final int JETTY_MAX_IDLE = 30000;

    public static void main(String[] args) throws Exception {

        SocketConnector connector = new SocketConnector();
        connector.setPort(Integer.getInteger("jettyPort", JETTY_PORT));
        connector.setMaxIdleTime(Integer.getInteger("jettyMaxIdle", JETTY_MAX_IDLE));

        ProtectionDomain protectionDomain = Startup.class.getProtectionDomain();
        URL location = protectionDomain.getCodeSource().getLocation();

        WebAppContext context = new WebAppContext();
        context.setContextPath("/");
        context.setWar(location.toExternalForm());

        WebAppClassLoader loader = new WebAppClassLoader( Startup.class.getClassLoader(), context );
        context.setClassLoader(loader);

        Server server = new Server();
        server.setConnectors(new Connector[]{connector});
        server.setHandler(context);
        server.setSendServerVersion(false);

        try {
            server.start();
            server.join();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }

    }
}
@@ -127,18 +127,25 @@
 tty.
-b
+n
 io.S
-ocket
+electChannel
 Conn
@@ -248,16 +248,49 @@
 Context;
+%0Aimport org.mortbay.util.URIUtil;
 %0A%0Aimport
@@ -345,16 +345,17 @@
 main;%0A%0A%0A
+%0A
 public c
@@ -544,21 +544,28 @@
        S
-ocket
+electChannel
 Connecto
@@ -587,13 +587,20 @@
 ew S
-ocket
+electChannel
 Conn
@@ -763,24 +763,121 @@
 AX_IDLE));%0A%0A
+        Thread.currentThread().setContextClassLoader(WebAppClassLoader.class.getClassLoader());%0A%0A
         Prot
@@ -1082,98 +1082,27 @@
     
-context.setContextPath(%22/%22);%0A        context.setWar(location.toExternalForm());%0A%0A        W
+WebAppClassLoader w
 ebAp
@@ -1118,15 +1118,8 @@
 der 
-loader 
 = ne
@@ -1138,17 +1138,16 @@
 sLoader(
- 
 Startup.
@@ -1169,25 +1169,23 @@
 oader(),
- 
 context
- 
 );%0A     
@@ -1214,14 +1214,123 @@
 der(
-loader
+webAppClassLoader);%0A        context.setContextPath(URIUtil.SLASH);%0A        context.setWar(location.toExternalForm()
 );%0A%0A

switch to NIO - fix continuation issue