Package org.mortbay.jetty.servlet

Examples of org.mortbay.jetty.servlet.Context


        String contextA = "/contextA";
        String contextB = "/contextB";
        String servletMapping = "/server";
        int port = random.nextInt(50000) + 10000;
        TerracottaJettyServer server = new TerracottaJettyServer(port);
        Context ctxA = server.addContext(contextA);
        ctxA.addServlet(TestServletA.class, servletMapping);
        Context ctxB = server.addContext(contextB);
        ctxB.addServlet(TestServletB.class, servletMapping);
        server.start();
        try
        {
            HttpClient client = new HttpClient();
            client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
View Full Code Here


{
    public static void main(String[] args)
        throws Exception
    {
        Server server = new Server(8080);
        Context context = new Context(server,"/",Context.SESSIONS);
        context.addServlet(new ServletHolder(new HelloServlet()), "/*");
       
        server.start();
        server.join();
    }
View Full Code Here

        {
            _connector.setPort(_PORT);
        }

        _server.addConnector(_connector);
        Context context = new Context(_server,"",Context.NO_SECURITY | Context.NO_SESSIONS);
        ServletHolder h = new ServletHolder(new HttpServlet()
        {
            private static final long serialVersionUID = 1L;

            @Override
            protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
            {
                resp.setContentType("text/plain");
                resp.setStatus(HttpServletResponse.SC_OK);
                resp.getWriter().write("ok\n");
            }

            @Override
            protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
            {
                resp.setContentType("text/plain");
                resp.setStatus(HttpServletResponse.SC_OK);
                resp.getWriter().write("ok\n");
            }

        });
        context.addServlet(h,"/ping");
        _server.start();
        _PORT = _connector.getLocalPort();
        _url = String.format("http://localhost:%d/ping",_PORT);

    }
View Full Code Here

        String contextPath = "";
        String servletMapping = "/server";
        int port = random.nextInt(50000) + 10000;
        int scavengePeriod = 3;
        TerracottaJettyServer server = new TerracottaJettyServer(port, 1, scavengePeriod);
        Context context = server.addContext(contextPath);
        context.addServlet(TestServlet.class, servletMapping);
        server.start();
        try
        {
            HttpClient client = new HttpClient();
            client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
View Full Code Here

    {
        _server = new Server();
        SelectChannelConnector scc = new SelectChannelConnector();
        scc.setPort(8010);
        _server.addConnector(scc);
        Context context = new Context();
        context.setContextPath("/");
        context.addServlet(HelloWorldServiceImpl.class, "/helloworld");
        _server.setHandler(context);
        _server.start();
    }
View Full Code Here

        {
            _server = new Server();
            _server.setConnectors(new Connector[]
            { new SelectChannelConnector() });

            Context context = new Context(Context.SECURITY);
            context.setContextPath("/test");
            context.addServlet(PostServlet.class,"/");
            context.setAllowNullPathInfo(true);

            HashUserRealm realm = new HashUserRealm("test");
            realm.put("testuser","password");
            realm.addUserToRole("testuser","test");
            _server.setUserRealms(new UserRealm[]{realm});
           
            SecurityHandler security=context.getSecurityHandler();
            security.setAuthenticator(new DigestAuthenticator());
            security.setUserRealm(realm);
          
            Constraint constraint = new Constraint("SecureTest","test");
            constraint.setAuthenticate(true);
View Full Code Here

        server.start();
    }

    public Context addContext(String contextPath)
    {
        Context context = new Context(contexts, contextPath);

        TerracottaSessionManager sessionManager = new TestTerracottaSessionManager();
        sessionManager.setIdManager(sessionIdManager);
        sessionManager.setMaxInactiveInterval(maxInactivePeriod);
        sessionManager.setScavengePeriodMs(TimeUnit.SECONDS.toMillis(scavengePeriod));

        SessionHandler sessionHandler = new TerracottaSessionHandler(sessionManager);
        sessionManager.setSessionHandler(sessionHandler);
        context.setSessionHandler(sessionHandler);

        return context;
    }
View Full Code Here

        server.addConnector(connector);
       
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        server.setHandler(contexts);
       
        Context context = new Context(contexts,"/",Context.NO_SECURITY|Context.SESSIONS);
       

        String version = Server.getVersion();
        if (Server.UNKNOWN_VERSION.equals(version))
            version=Server.SNAPSHOT_VERSION;
        context.setBaseResource(new ResourceCollection(new Resource[]
        {
            Resource.newResource(base+"/../demo/src/main/webapp/"),
            Resource.newResource(base+"/../demo/target/cometd-demo-"+version+"/"),
        }));
       
        // Cometd servlet
        ServletHolder cometd_holder = new ServletHolder(ContinuationCometdServlet.class);
        cometd_holder.setInitParameter("timeout","200000");
        cometd_holder.setInitParameter("interval","100");
        cometd_holder.setInitParameter("maxInterval","100000");
        cometd_holder.setInitParameter("multiFrameInterval","1500");
        cometd_holder.setInitParameter("directDeliver","true");
        cometd_holder.setInitParameter("logLevel","1");
        cometd_holder.setInitOrder(1);
        context.addServlet(cometd_holder, "/cometd/*");
       
        ServletHolder oort_holder = new ServletHolder(OortServlet.class);
        oort_holder.setInitParameter(Oort.OORT_URL,"http://localhost:"+port+"/cometd");
        oort_holder.setInitParameter(Oort.OORT_CHANNELS,"/chat/**");
        oort_holder.setInitParameter(Oort.OORT_CLOUD,(port==8080)?"http://localhost:"+8081+"/cometd":"http://localhost:"+8080+"/cometd");
        oort_holder.setInitOrder(2);
        context.addServlet(oort_holder, "/oort/*");

        ServletHolder seti_holder = new ServletHolder(SetiServlet.class);
        seti_holder.setInitParameter(Seti.SETI_SHARD,"S"+(port%2));
        seti_holder.setInitOrder(2);
        context.addServlet(seti_holder, "/seti/*");

        ServletHolder demo_holder = new ServletHolder(OortDemoServlet.class);
        demo_holder.setInitOrder(3);
        context.getServletHandler().addServlet(demo_holder);
       
        context.addServlet("org.mortbay.jetty.servlet.DefaultServlet", "/");
       
        server.start();
       
        _oort = (Oort)context.getServletContext().getAttribute(Oort.OORT_ATTRIBUTE);
        assert(_oort!=null);
       
    }
View Full Code Here

        Server server = new Server(8080);

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

        Context root = new Context(contexts,"/",Context.SESSIONS);
        root.addServlet(new ServletHolder(new HelloServlet("Ciao")), "/*");

        Context other = new Context(contexts,"/other",Context.SESSIONS);
        other.addServlet("org.mortbay.jetty.example.ManyServletContexts$HelloServlet", "/*");

        StatisticsHandler stats = new StatisticsHandler();
        contexts.addHandler(stats);
        Context yetanother =new Context(stats,"/yo",Context.SESSIONS);
        yetanother.addServlet(new ServletHolder(new HelloServlet("YO!")), "/*");

        server.start();
        server.join();
    }
View Full Code Here

    {
        // Just a little test main....

        Server server = new Server();
        server.addConnector(new RandomConnector());
        Context context = new Context(server,"/",Context.SESSIONS);
        context.addServlet(new ServletHolder(new HelloServlet()), "/*");
       
        server.start();
        server.join();
    }
View Full Code Here

TOP

Related Classes of org.mortbay.jetty.servlet.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.