package com.cjmalloy.torrentfs.server;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.servlet.ServletContainer;

public class Entry
{
	public static final int DEFAULT_PORT = 8080;

	public static void main(String[] args)
	{
		int port = DEFAULT_PORT;
		if (args.length == 1)
		{
			port = Integer.parseInt(args[0]);
		}
		else if (args.length != 0)
		{
			System.out.println("Usage: torrent-fs [PORT]");
			return;
		}

        ServletHolder sh = new ServletHolder(ServletContainer.class);
        sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
        sh.setInitParameter("com.sun.jersey.config.property.packages", "com.cjmalloy.torrentfs.server.remote.rest");
        sh.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");

        Server server = new Server(port);
        ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
        context.addServlet(sh, "/*");
        try
        {
        	System.out.println("Starting server...");
			server.start();
	        server.join();
		}
        catch (Exception e)
        {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

@@ -555,196 +555,252 @@
 Serv
-letHolder sh = new ServletHolder(ServletContainer.class);%0A        sh.setInitParameter(%22com.sun.jersey.config.property.resourceConfigC
+er server = new Server(port);%0A        ServletContextHandler context = new ServletContextHandler(server, %22/%22, ServletContextHandler.SESSIONS);%0A        ServletHolder sh = context.addServlet(ServletContainer.c
 lass
-%22
 , %22
-com.sun.jersey.api.core.PackagesResourceConfig%22
+/*%22);%0A        sh.setInitOrder(1
 );%0A 
@@ -823,32 +823,24 @@
 tParameter(%22
-com.sun.
 jersey.confi
@@ -845,16 +845,23 @@
 fig.
-property
+server.provider
 .pac
@@ -867,17 +867,16 @@
 ckages%22,
- 
 %22com.cjm
@@ -925,365 +925,101 @@
     
-sh.setInitParameter(%22com.sun.jersey.api.json.POJOMappingFeature%22, %22true%22);%0A%0A        Server server = new Server(port);%0A        ServletContextHandler context = new ServletContextHandler(server, %22/%22, ServletContextHandler.SESSIONS);%0A        context.addServlet(sh, %22/*%22);%0A        try%0A        %7B%0A        %09System.out.println(%22Starting server...%22);%0A%09%09%09server.sta
+try%0A        %7B%0A%09%09%09server.start();%0A        %09System.out.println(%22Server started on port %22 + po
 rt
-(
 );%0A%09

Update config for jersey 2.x