openamf/src/java/org/openamf RequestContext.java,NONE,1.1
Sean Sullivan <[email protected]> Mon, 29 Mar 2004 03:26:23 +0000
| Newsgroups | gmane.comp.java.openamf.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/openamf/openamf/src/java/org/openamf
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12839/src/java/org/openamf
Added Files:
RequestContext.java
Log Message:
new class: RequestContext
--- NEW FILE: RequestContext.java ---
/*
* www.openamf.org
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.openamf;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
*
* This class allows web applications to
* easily access the HttpServletRequest object.
*
* OpenAMF's RequestContext class was inspired by the example code
* in chapter 7 of "Flash Remoting: The Definitive Guide"
* by Tom Muck.
*
* This class uses thread local storage.
*
* To learn more about thread local storage, read this
* article:
* <a href="http://www-106.ibm.com/developerworks/java/library/j-threads3.html">
* http://www-106.ibm.com/developerworks/java/library/j-threads3.html</a>
*
* @author Sean C. Sullivan
*
*/
public class RequestContext
{
static private ThreadLocal requestData = new ThreadLocal();
private RequestContext()
{
// private constructor
}
/**
*
* @param req the servlet request object
*
* @see #getHttpServletRequest()
*
*/
static public void setHttpServletRequest(HttpServletRequest req)
{
requestData.set(req);
}
/**
*
*
* @return may return null
*
* @see #setHttpServletRequest(HttpServletRequest)
*
*/
static public HttpServletRequest getHttpServletRequest()
{
HttpServletRequest req = (HttpServletRequest) requestData.get();
return req;
}
/**
*
* @return a non-null value
*
* @see #getHttpServletRequest
*
*/
static public HttpSession getHttpSession()
{
HttpServletRequest req = getHttpServletRequest();
if (req == null)
{
throw new IllegalStateException("HttpServletRequest is null");
}
return req.getSession(true);
}
}
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click