001    /*
002     * Copyright (c) 2005 Henri Sivonen
003     * Copyright (c) 2007 Mozilla Foundation
004     *
005     * Permission is hereby granted, free of charge, to any person obtaining a 
006     * copy of this software and associated documentation files (the "Software"), 
007     * to deal in the Software without restriction, including without limitation 
008     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
009     * and/or sell copies of the Software, and to permit persons to whom the 
010     * Software is furnished to do so, subject to the following conditions:
011     *
012     * The above copyright notice and this permission notice shall be included in 
013     * all copies or substantial portions of the Software.
014     *
015     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
016     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
017     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
018     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
019     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
020     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
021     * DEALINGS IN THE SOFTWARE.
022     */
023    
024    package nu.validator.servlet;
025    
026    
027    import org.apache.log4j.PropertyConfigurator;
028    import org.mortbay.jetty.Connector;
029    import org.mortbay.jetty.Handler;
030    import org.mortbay.jetty.Server;
031    import org.mortbay.jetty.ajp.Ajp13SocketConnector;
032    import org.mortbay.jetty.bio.SocketConnector;
033    import org.mortbay.jetty.handler.ContextHandler;
034    import org.mortbay.jetty.servlet.Context;
035    import org.mortbay.jetty.servlet.FilterHolder;
036    import org.mortbay.jetty.servlet.ServletHandler;
037    import org.mortbay.jetty.servlet.ServletHolder;
038    import org.mortbay.servlet.GzipFilter;
039    
040    /**
041     * @version $Id: Main.java 86 2007-10-02 13:14:01Z hsivonen $
042     * @author hsivonen
043     */
044    public class Main {
045    
046        public static void main(String[] args) throws Exception {
047            PropertyConfigurator.configure(System.getProperty("nu.validator.servlet.log4j-properties", "log4j.properties"));
048            new VerifierServletTransaction(null, null);
049            Server server = new Server();
050            Connector connector;
051            if (args.length > 0 && "ajp".equals(args[0])) {
052                connector = new Ajp13SocketConnector();
053                int port = Integer.parseInt(args[1]);
054                connector.setPort(port);
055                connector.setHost("127.0.0.1");
056            } else {
057                connector = new SocketConnector();
058                int port = Integer.parseInt(args[0]);
059                connector.setPort(port);
060            }
061            server.addConnector(connector);
062    
063            Context context = new Context(server, "/");
064            context.addServlet(new ServletHolder(new VerifierServlet()), "/*");
065            context.addFilter(new FilterHolder(new GzipFilter()), "/*", Handler.REQUEST);
066            context.addFilter(new FilterHolder(new MultipartFormDataFilter()), "/*", Handler.REQUEST);
067            server.start();
068            
069            System.in.read(); // XXX do something smarter
070            server.stop();
071        }
072    }