Package org.eclipse.jetty.server.session

Examples of org.eclipse.jetty.server.session.AbstractTestServer


    {
        String contextPath = "";
        String servletMapping = "/server";
        int maxInactivePeriod = 10000;
        int scavengePeriod = 20000;
        AbstractTestServer server1 = createServer(0,maxInactivePeriod,scavengePeriod);
        server1.addContext(contextPath).addServlet(TestServlet.class,servletMapping);
        server1.start();
        int port1 = server1.getPort();
        try
        {

            HttpClient client = new HttpClient();
            client.start();
            try
            {
                String[] sessionTestValue = new String[]
                { "0", "null" };

                // Perform one request to server1 to create a session
                ContentResponse response = client.GET("http://localhost:" + port1 + contextPath + servletMapping + "?action=init");
     
                assertEquals(HttpServletResponse.SC_OK,response.getStatus());

                String[] sessionTestResponse = response.getContentAsString().split("/");
                assertTrue(Long.parseLong(sessionTestValue[0]) < Long.parseLong(sessionTestResponse[0]));

                sessionTestValue = sessionTestResponse;

                String sessionCookie = response.getHeaders().get("Set-Cookie");
                assertTrue(sessionCookie != null);
                // Mangle the cookie, replacing Path with $Path, etc.
                sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=","$1\\$Path=");

                // Perform some request to server2 using the session cookie from the previous request
                // This should migrate the session from server1 to server2, and leave server1's
                // session in a very stale state, while server2 has a very fresh session.
                // We want to test that optimizations done to the saving of the shared lastAccessTime
                // do not break the correct working
                int requestInterval = 500;

                for (int i = 0; i < 10; ++i)
                {
                    Request request2 = client.newRequest("http://localhost:" + port1 + contextPath + servletMapping);
                    request2.header("Cookie",sessionCookie);
                    ContentResponse response2 = request2.send();
        
                    assertEquals(HttpServletResponse.SC_OK,response2.getStatus());

                    sessionTestResponse = response2.getContentAsString().split("/");

                    assertTrue(Long.parseLong(sessionTestValue[0]) < Long.parseLong(sessionTestResponse[0]));
                    assertTrue(Long.parseLong(sessionTestValue[1]) < Long.parseLong(sessionTestResponse[1]));

                    sessionTestValue = sessionTestResponse;

                    String setCookie = response2.getHeaders().get("Set-Cookie");
                    if (setCookie != null)
                        sessionCookie = setCookie.replaceFirst("(\\W)(P|p)ath=","$1\\$Path=");

                    Thread.sleep(requestInterval);
                }

//               Thread.sleep(320000);
            }
            finally
            {
                client.stop();
            }
        }
        finally
        {
            server1.stop();
        }
    }
View Full Code Here


    {
        String contextPath = "";
        String servletMapping = "/server";
        int maxInactivePeriod = 10000;
        int scavengePeriod = 20000;
        AbstractTestServer server1 = createServer(0,maxInactivePeriod,scavengePeriod);
        server1.addContext(contextPath).addServlet(TestServlet.class,servletMapping);
        server1.start();
        int port1 = server1.getPort();
       
        AbstractTestServer server2 = createServer(0,maxInactivePeriod,scavengePeriod);
        server2.addContext(contextPath).addServlet(TestServlet.class,servletMapping);
        server2.start();
        int port2 = server2.getPort();
       
        try
        {

            HttpClient client = new HttpClient();
            client.start();
            try
            {

                // Perform one request to server1 to create a session with attribute with dotted name
                ContentResponse response = client.GET("http://localhost:" + port1 + contextPath + servletMapping + "?action=init");
     
                assertEquals(HttpServletResponse.SC_OK,response.getStatus());

                String resp = response.getContentAsString();
               
                String[] sessionTestResponse = resp.split("/");
                assertEquals("a.b.c",sessionTestResponse[0]);

                String sessionCookie = response.getHeaders().get(HttpHeader.SET_COOKIE);
                     
                assertTrue(sessionCookie != null);
                //Mangle the cookie, replacing Path with $Path, etc.
                sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=","$1\\$Path=");

                //Make a request to the 2nd server which will do a refresh, use TestServlet to ensure that the
                //session attribute with dotted name is not removed
                Request request2 = client.newRequest("http://localhost:" + port2 + contextPath + servletMapping + "?action=get");
                request2.header("Cookie", sessionCookie);
                ContentResponse response2 = request2.send();
                assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
               
            }
            finally
            {
                client.stop();
            }
        }
        finally
        {
            server1.stop();
            server2.stop();
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.server.session.AbstractTestServer

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.