jrun.servlet
Class ServletConnection

jrun.servlet.ServletConnection
All Implemented Interfaces:
HttpConstants
Direct Known Subclasses:
ProxyEndpoint, WebEndpoint

public abstract class ServletConnection
implements HttpConstants

this class implements the full HttpServletRequest and HttpServletResponse API's, by throwing "not implemented" exceptions. Subclasses can override the methods they choose to implement.

This class turns out to be incredibly useful, in that it contains many useful constants, as well as several Servlet API methods that are simply convenience methods.

Services that implement servlet protocols can subclass this object to implement their specialized ServletRequest and ServletResponse objects. They can also use its buffered streams efficiently since the underlying streams can be swapped out without destroying any objects.

This class also implements the request attribute namespace so nobody else has to. The hashtable is not constructed until it is needed, so subclasses can avoid extra hashtables if they want.


Field Summary
 int bytesIn
           
 int bytesOut
           
protected  boolean committed
           
protected  NoCaseContainer headersIn
           
protected  NoCaseContainer headersOut
           
 Metrics metrics
           
 
Fields inherited from interface jrun.servlet.HttpConstants
ACCEPT_CHARSET, ACCEPT_LANGUAGE, CACHE_CONTROL, CONNECTION, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_TYPE, COOKIE, DATE, EXPIRES, HOST, LOCATION, SERVER, SET_COOKIE
 
Constructor Summary
protected ServletConnection(Metrics metrics, int bytesIn, int bytesOut)
           
 
Method Summary
 void addCookie(javax.servlet.http.Cookie c)
          Adds the specified cookie to the response.
 void addDateHeader(java.lang.String h, long time)
           
 void addHeader(java.lang.String name, java.lang.String value)
           
 void addIntHeader(java.lang.String name, int i)
           
protected  void closeInputStream()
           
protected  void commitHeaders()
          Writes status line and headers to specified servlet output stream.
 boolean containsHeader(java.lang.String name)
           
 java.lang.String encodeRedirectUrl(java.lang.String url)
           
 java.lang.String encodeRedirectURL(java.lang.String url)
           
 java.lang.String encodeUrl(java.lang.String url)
           
 java.lang.String encodeURL(java.lang.String url)
           
abstract  void flushBuffer()
           
protected  java.lang.String formatDateHeader(long time)
           
 java.lang.Object getAttribute(java.lang.String a)
           
 java.util.Enumeration getAttributeNames()
           
abstract  java.lang.String getAuthType()
           
abstract  int getBufferSize()
           
 java.lang.String getCharacterEncoding()
           
 int getContentLength()
           
 java.lang.String getContentType()
           
 java.lang.String getContextPath()
           
 javax.servlet.http.Cookie[] getCookies()
           
static ServletConnection getCurrent()
          Get the current ServletConnection for this thread.
 long getDateHeader(java.lang.String name)
          Returns the date value of the header field with the specified name.
abstract  java.lang.String getHeader(java.lang.String h)
           
abstract  java.util.Enumeration getHeaderNames()
           
abstract  java.util.Enumeration getHeaders(java.lang.String h)
           
protected  javax.servlet.ServletInputStream getIn()
           
 javax.servlet.ServletInputStream getInputStream()
           
 int getIntHeader(java.lang.String name)
          Returns the integer value of the header field with the specified name.
 java.util.Locale getLocale()
           
 java.util.Enumeration getLocales()
           
abstract  java.lang.String getMethod()
           
abstract  javax.servlet.ServletOutputStream getOutputStream()
           
 java.lang.String getParameter(java.lang.String p)
           
 java.util.Map getParameterMap()
           
 java.util.Enumeration getParameterNames()
           
 java.lang.String[] getParameterValues(java.lang.String p)
           
 java.lang.String getPathInfo()
           
 java.lang.String getPathTranslated()
           
abstract  java.lang.String getProtocol()
           
abstract  java.lang.String getQueryString()
           
 java.io.BufferedReader getReader()
           
abstract  java.lang.String getRealPath(java.lang.String p)
           
abstract  java.lang.String getRemoteAddr()
           
abstract  java.lang.String getRemoteHost()
           
abstract  java.lang.String getRemoteUser()
           
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String relPath)
           
 java.lang.String getRequestedSessionId()
           
abstract  java.lang.String getRequestURI()
           
 java.lang.StringBuffer getRequestURL()
           
abstract  java.lang.String getScheme()
           
abstract  java.lang.String getServerName()
           
abstract  int getServerPort()
           
 java.lang.String getServletPath()
           
 javax.servlet.http.HttpSession getSession()
           
 javax.servlet.http.HttpSession getSession(boolean create)
           
 java.security.Principal getUserPrincipal()
           
 java.io.PrintWriter getWriter()
           
 boolean isCommitted()
           
 boolean isRequestedSessionIdFromCookie()
           
 boolean isRequestedSessionIdFromUrl()
           
 boolean isRequestedSessionIdFromURL()
           
 boolean isRequestedSessionIdValid()
           
abstract  boolean isSecure()
           
 boolean isUserInRole(java.lang.String role)
           
protected  void readRequest()
          using whatever implementation specific code, initialize this request.
protected static java.lang.String reason(int status, java.util.Locale loc)
          Given a status ID, return the text reason.
 void removeAttribute(java.lang.String a)
           
 void reset()
           
abstract  void resetBuffer()
           
 void sendError(int s)
           
 void sendError(int s, java.lang.String m)
           
 void sendRedirect(java.lang.String l)
           
 void setAttribute(java.lang.String a, java.lang.Object o)
           
abstract  void setBufferSize(int size)
           
 void setCharacterEncoding(java.lang.String env)
           
 void setContentLength(int length)
           
 void setContentType(java.lang.String type)
           
 void setDateHeader(java.lang.String h, long time)
           
 void setHeader(java.lang.String name, java.lang.String value)
           
protected  void setInputStream(java.io.InputStream in)
          install the given input stream underneath our ServletInputStream and input stream buffer.
 void setIntHeader(java.lang.String name, int i)
           
 void setLocale(java.util.Locale loc)
           
 void setStatus(int code)
          Sets the status code for this response.
 void setStatus(int code, java.lang.String message)
           
abstract  void writeHeader(java.lang.String name, java.lang.String value)
           
abstract  void writeStatus(int sc, java.lang.String message)
           
 

Field Detail

headersIn

protected final NoCaseContainer headersIn

metrics

public Metrics metrics

bytesIn

public int bytesIn

bytesOut

public int bytesOut

headersOut

protected final NoCaseContainer headersOut

committed

protected boolean committed
Constructor Detail

ServletConnection

protected ServletConnection(Metrics metrics,
                            int bytesIn,
                            int bytesOut)
Method Detail

readRequest

protected void readRequest()
                    throws java.io.IOException
using whatever implementation specific code, initialize this request. Typically this involves reading data from a socket, but it doesnt' have to.

subclasses that implement this method should call super.readRequest so that we can reset attributes and do any other housekeeping we need to.


getCurrent

public static final ServletConnection getCurrent()
Get the current ServletConnection for this thread.

closeInputStream

protected void closeInputStream()
                         throws java.io.IOException

setInputStream

protected final void setInputStream(java.io.InputStream in)
install the given input stream underneath our ServletInputStream and input stream buffer.

getIn

protected final javax.servlet.ServletInputStream getIn()

setAttribute

public void setAttribute(java.lang.String a,
                         java.lang.Object o)

getAttribute

public java.lang.Object getAttribute(java.lang.String a)

getAttributeNames

public java.util.Enumeration getAttributeNames()

removeAttribute

public void removeAttribute(java.lang.String a)

getProtocol

public abstract java.lang.String getProtocol()

getScheme

public abstract java.lang.String getScheme()

getServerName

public abstract java.lang.String getServerName()

getServerPort

public abstract int getServerPort()

getRemoteAddr

public abstract java.lang.String getRemoteAddr()

getRemoteHost

public abstract java.lang.String getRemoteHost()

isSecure

public abstract boolean isSecure()

getAuthType

public abstract java.lang.String getAuthType()

getMethod

public abstract java.lang.String getMethod()

getQueryString

public abstract java.lang.String getQueryString()

getRemoteUser

public abstract java.lang.String getRemoteUser()

getRequestURI

public abstract java.lang.String getRequestURI()

getHeader

public abstract java.lang.String getHeader(java.lang.String h)

getHeaderNames

public abstract java.util.Enumeration getHeaderNames()

getHeaders

public abstract java.util.Enumeration getHeaders(java.lang.String h)

getRealPath

public abstract java.lang.String getRealPath(java.lang.String p)

setBufferSize

public abstract void setBufferSize(int size)

resetBuffer

public abstract void resetBuffer()

getBufferSize

public abstract int getBufferSize()

flushBuffer

public abstract void flushBuffer()
                          throws java.io.IOException

getOutputStream

public abstract javax.servlet.ServletOutputStream getOutputStream()
                                                           throws java.io.IOException

writeHeader

public abstract void writeHeader(java.lang.String name,
                                 java.lang.String value)
                          throws java.io.IOException

writeStatus

public abstract void writeStatus(int sc,
                                 java.lang.String message)
                          throws java.io.IOException

getCharacterEncoding

public java.lang.String getCharacterEncoding()

setCharacterEncoding

public void setCharacterEncoding(java.lang.String env)
                          throws java.io.UnsupportedEncodingException

getParameter

public java.lang.String getParameter(java.lang.String p)

getParameterNames

public java.util.Enumeration getParameterNames()

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String p)

getReader

public java.io.BufferedReader getReader()
                                 throws java.io.IOException

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws java.io.IOException

getLocale

public java.util.Locale getLocale()

getLocales

public java.util.Enumeration getLocales()

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String relPath)

getParameterMap

public java.util.Map getParameterMap()

getCookies

public javax.servlet.http.Cookie[] getCookies()

getPathInfo

public java.lang.String getPathInfo()

getPathTranslated

public java.lang.String getPathTranslated()

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()

getServletPath

public java.lang.String getServletPath()

getContextPath

public java.lang.String getContextPath()

getSession

public javax.servlet.http.HttpSession getSession()

getSession

public javax.servlet.http.HttpSession getSession(boolean create)

isUserInRole

public boolean isUserInRole(java.lang.String role)

getUserPrincipal

public java.security.Principal getUserPrincipal()

getRequestURL

public java.lang.StringBuffer getRequestURL()

getRequestedSessionId

public java.lang.String getRequestedSessionId()

getContentLength

public int getContentLength()

getContentType

public java.lang.String getContentType()

getDateHeader

public final long getDateHeader(java.lang.String name)
Returns the date value of the header field with the specified name.
Parameters:
name - the header field name
Returns:
the header field date value, -1 if header not found
Throws:
java.lang.IllegalArgumentException - if the header exists but cannot be parsed.

getIntHeader

public final int getIntHeader(java.lang.String name)
Returns the integer value of the header field with the specified name.
Parameters:
name - the header field name
Returns:
the header field integer value, or -1 if not found

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException

setLocale

public void setLocale(java.util.Locale loc)

encodeURL

public java.lang.String encodeURL(java.lang.String url)

encodeUrl

public java.lang.String encodeUrl(java.lang.String url)

encodeRedirectURL

public java.lang.String encodeRedirectURL(java.lang.String url)

encodeRedirectUrl

public java.lang.String encodeRedirectUrl(java.lang.String url)

sendError

public void sendError(int s)
               throws java.io.IOException

sendError

public void sendError(int s,
                      java.lang.String m)
               throws java.io.IOException

sendRedirect

public void sendRedirect(java.lang.String l)
                  throws java.io.IOException

setContentLength

public void setContentLength(int length)

setContentType

public void setContentType(java.lang.String type)

containsHeader

public final boolean containsHeader(java.lang.String name)

setHeader

public final void setHeader(java.lang.String name,
                            java.lang.String value)

addHeader

public final void addHeader(java.lang.String name,
                            java.lang.String value)

isCommitted

public final boolean isCommitted()

reset

public void reset()

addCookie

public final void addCookie(javax.servlet.http.Cookie c)
Adds the specified cookie to the response.

setStatus

public final void setStatus(int code)
Sets the status code for this response.

setStatus

public void setStatus(int code,
                      java.lang.String message)

formatDateHeader

protected final java.lang.String formatDateHeader(long time)

addDateHeader

public final void addDateHeader(java.lang.String h,
                                long time)

setDateHeader

public final void setDateHeader(java.lang.String h,
                                long time)

setIntHeader

public final void setIntHeader(java.lang.String name,
                               int i)

addIntHeader

public final void addIntHeader(java.lang.String name,
                               int i)

commitHeaders

protected final void commitHeaders()
                            throws java.io.IOException
Writes status line and headers to specified servlet output stream. Called by JRunOutputStream just before flushing data to the underlying output stream.

reason

protected static final java.lang.String reason(int status,
                                               java.util.Locale loc)
Given a status ID, return the text reason.


Copyright � 2002 Macromedia Corporation. All Rights Reserved.