|
Jetty example source code file (SessionTest.java)
The Jetty SessionTest.java source code// ======================================================================== // Copyright 2006 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ======================================================================== package org.mortbay.jetty; import java.io.InputStream; import java.net.URL; import org.mortbay.jetty.Handler; import org.mortbay.jetty.Server; import org.mortbay.jetty.SessionIdManager; import org.mortbay.jetty.SessionManager; import org.mortbay.jetty.handler.ContextHandlerCollection; import org.mortbay.jetty.handler.DefaultHandler; import org.mortbay.jetty.handler.HandlerCollection; import org.mortbay.jetty.handler.RequestLogHandler; import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.security.HashUserRealm; import org.mortbay.jetty.security.UserRealm; import org.mortbay.jetty.webapp.WebAppContext; import org.mortbay.thread.BoundedThreadPool; import org.mortbay.util.IO; import junit.framework.TestCase; /** * @version $Revision$ */ public class SessionTest extends TestCase { Server server; WebAppContext test0; WebAppContext test1; SessionManager session0; SessionManager session1; SessionIdManager ids; String url; protected void setUp() throws Exception { server = new Server(0); HandlerCollection handlers = new HandlerCollection(); ContextHandlerCollection contexts = new ContextHandlerCollection(); RequestLogHandler requestLogHandler = new RequestLogHandler(); handlers.setHandlers(new Handler[]{contexts,new DefaultHandler(),requestLogHandler}); server.setHandler(handlers); test0 = new WebAppContext(contexts,"../../webapps/test","/test0"); test1 = new WebAppContext(contexts,"../../webapps/test","/test1"); HashUserRealm userRealm = new HashUserRealm(); userRealm.setName("Test Realm"); userRealm.setConfig("../../etc/realm.properties"); server.setUserRealms(new UserRealm[]{userRealm}); server.start(); url="http://127.0.0.1:"+server.getConnectors()[0].getLocalPort(); session0=test0.getSessionHandler().getSessionManager(); session1=test1.getSessionHandler().getSessionManager(); ids=test0.getSessionHandler().getSessionManager().getMetaManager(); assertEquals(ids,test1.getSessionHandler().getSessionManager().getMetaManager()); } protected void tearDown() throws Exception { server.stop(); } public void testSession() throws Exception { // no sessions to start with. testContains("/test0/session","No Session"); testContains("/test1/session","No Session"); // create context in context 0 String id0=getID("/test0/session?Action=New+Session"); assertTrue(id0!=null); assertEquals(id0,getID("/test0/session;jsessionid="+id0)); testContains("/test1/session;jsessionid="+id0,"No Session"); // test setting value testContains("/test0/session;jsessionid="+id0+"?Action=Set&Name=name0&Value=value0","<b>name0: value0 Other Jetty examples (source code examples)Here is a short list of links related to this Jetty SessionTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.