Package org.eclipse.jetty.client.api

Examples of org.eclipse.jetty.client.api.Request$CommitListener


     {
         try
         {
             startClient();

             Request request = _client.newRequest(_baseUri.resolve("output.txt"));
             request.method(HttpMethod.PUT);
             request.content(new BytesContentProvider(_content.getBytes()));
             ContentResponse response = request.send();
             int responseStatus = response.getStatus();
             boolean statusOk = (responseStatus == 200 || responseStatus == 201);
             assertTrue(statusOk);
             String content = IO.toString(new FileInputStream(new File(_docRoot,"output.txt")));
             assertEquals(_content,content);
View Full Code Here


     {
         try
         {
             startClient();

             Request request = _client.newRequest(_baseUri.resolve("input.txt"));
             request.method(HttpMethod.HEAD);
             ContentResponse response = request.send();
             int responseStatus = response.getStatus();
             assertEquals(HttpStatus.OK_200,responseStatus);
         }
         finally
         {
View Full Code Here

     {
         try
         {
             startClient();

             Request request = _client.newRequest(_baseUri.resolve("test"));
             request.method(HttpMethod.POST);
             request.content(new BytesContentProvider(_content.getBytes()));
             ContentResponse response = request.send();
             assertEquals(HttpStatus.OK_200,response.getStatus());
             assertEquals(_content,_testServer.getTestHandler().getRequestContent());
         }
         finally
         {
View Full Code Here

           
            port1 = server1.getPort();
            url = "http://localhost:" + port1 + contextPath + servletMapping;

            //make another request, the session should have expired
            Request request = client.newRequest(url + "?action=test");
            request.getHeaders().add("Cookie", sessionCookie);
            ContentResponse response2 = request.send();
            assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
           
            //and wait until the expiry time has passed
            pause(inactivePeriod);
           
View Full Code Here


                Thread.currentThread().sleep(3*purgeDelay); //sleep long enough for purger to have run

                //make a request using previous session to test if its still there              
                Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=test");
                request.header("Cookie", sessionCookie);
                ContentResponse response2 = request.send();
                assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
            }
            finally
            {
                client.stop();
View Full Code Here

                //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
            {
View Full Code Here

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

                //make a request to invalidate the session
                Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=invalidate");
                request.header("Cookie", sessionCookie);
                response = request.send();
                assertEquals(HttpServletResponse.SC_OK,response.getStatus());
               
                Thread.currentThread().sleep(3*purgeDelay); //sleep long enough for purger to have run
               
                //make a request using previous session to test if its still there
                request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=test");
                request.header("Cookie", sessionCookie);
                response = request.send();
                assertEquals(HttpServletResponse.SC_OK,response.getStatus());
            }
            finally
            {
                client.stop();
View Full Code Here

                assertTrue(sessionCookie != null);
                // Mangle the cookie, replacing Path with $Path, etc.
                sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
               
                //do another request to change the maxinactive interval
                Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=change&val="+newMaxInactive);
                request.header("Cookie", sessionCookie);
                response = request.send();

                assertEquals(HttpServletResponse.SC_OK,response.getStatus());
                              
                //wait for longer than the old inactive interval
                Thread.currentThread().sleep(10*1000L);
               
                //do another request using the cookie to ensure the session is still there
              
                request= client.newRequest("http://localhost:" + port + "/mod/test?action=test");
                request.header("Cookie", sessionCookie);
                response = request.send();
                assertEquals(HttpServletResponse.SC_OK,response.getStatus());
            }
            finally
            {
                client.stop();
View Full Code Here

                sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
                long lastSaved = ((JDBCSessionManager.Session)servlet._session).getLastSaved();
               
               
                //do another request to change the session attribute
                Request request = client.newRequest("http://localhost:" + port + "/mod/test?action=set");
                request.header("Cookie", sessionCookie);
                response = request.send();
                assertEquals(HttpServletResponse.SC_OK,response.getStatus());
                long tmp = ((JDBCSessionManager.Session)servlet._session).getLastSaved();
                assertNotEquals(lastSaved, tmp); //set of attribute will cause save to db
                lastSaved = tmp;
               
                //do nothing for just a bit longer than the save interval to ensure
                //session will be checked against database on next request
                Thread.currentThread().sleep((SAVE+2)*1000);
            
               
                //do another request to access the session, this will cause session to be initially
                //checked against db. On exit of request, the access time will need updating, so the
                //session will be saved to db.
                request = client.newRequest("http://localhost:" + port + "/mod/test?action=tickle");
                request.header("Cookie", sessionCookie);
                response = request.send();
                assertEquals(HttpServletResponse.SC_OK,response.getStatus());
                tmp = ((JDBCSessionManager.Session)servlet._session).getLastSaved();
                assertNotEquals(lastSaved, tmp);
                lastSaved = tmp;
             
                //wait a little and do another request to access the session
                Thread.currentThread().sleep((SAVE/2)*1000);
               
                //do another request to access the session. This time, the save interval has not
                //expired, so we should NOT see a debug trace of loading stale session. Nor should
                //the exit of the request cause a save of the updated access time.
                request = client.newRequest("http://localhost:" + port + "/mod/test?action=tickle");
                request.header("Cookie", sessionCookie);
                response = request.send();
                assertEquals(HttpServletResponse.SC_OK,response.getStatus());
                tmp = ((JDBCSessionManager.Session)servlet._session).getLastSaved();
                assertEquals(lastSaved, tmp); //the save interval did not expire, so update to the access time will not have been persisted
            }
            finally
View Full Code Here

    private String sendRequest( JdbcTestServer server ) throws Exception {

        int port=server.getPort();

        //Log.getLog().setDebugEnabled(true);
        Request request = client.newRequest("http://localhost:" + port + "" + "/test");
        if (sessionCookie != null)
            request.header("Cookie", sessionCookie);
        ContentResponse response = request.send();
        assertEquals(HttpServletResponse.SC_OK, response.getStatus());

        sessionCookie = response.getHeaders().get("Set-Cookie");
        assertTrue( sessionCookie != null );
        // Mangle the cookie, replacing Path with $Path, etc.
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.client.api.Request$CommitListener

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.