com.judoscript.user.httpserver
Class ServeConnection

java.lang.Object
  extended by com.judoscript.user.httpserver.ServeConnection
All Implemented Interfaces:
java.lang.Runnable, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletRequest, javax.servlet.ServletResponse

public class ServeConnection
extends java.lang.Object
implements java.lang.Runnable, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse

provides request/response


Field Summary
static java.lang.String CHUNKED
           
static java.lang.String CONTENTLENGTH
           
static java.lang.String CONTENTTYPE
           
static java.lang.String COOKIE
           
protected static java.text.SimpleDateFormat expdatefmt
           
protected static java.text.SimpleDateFormat headerdateformat
           
static java.lang.String SESSION_COOKIE_NAME
           
static java.lang.String SETCOOKIE
           
static java.lang.String TRANSFERENCODING
           
static java.lang.String WWWFORMURLENCODE
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
 
Constructor Summary
ServeConnection(java.net.Socket socket, Serve serve)
           
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
           
 void addDateHeader(java.lang.String header, long date)
           
 void addHeader(java.lang.String header, java.lang.String value)
           
 void addIntHeader(java.lang.String header, int value)
           
 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)
           
 void flushBuffer()
           
 java.lang.Object getAttribute(java.lang.String name)
           
 java.util.Enumeration getAttributeNames()
           
 java.lang.String getAuthType()
           
 int getBufferSize()
           
 java.lang.String getCharacterEncoding()
           
 int getContentLength()
           
 java.lang.String getContentType()
           
 java.lang.String getContextPath()
           
 javax.servlet.http.Cookie[] getCookies()
           
 long getDateHeader(java.lang.String name)
           
 long getDateHeader(java.lang.String name, long def)
           
 java.lang.String getHeader(java.lang.String name)
           
 java.util.Enumeration getHeaderNames()
           
 java.util.Enumeration getHeaders(java.lang.String header)
           
 javax.servlet.ServletInputStream getInputStream()
           
 int getIntHeader(java.lang.String name)
           
 int getIntHeader(java.lang.String name, int def)
           
 java.util.Locale getLocale()
           
 java.util.Enumeration getLocales()
           
 long getLongHeader(java.lang.String name, long def)
           
 java.lang.String getMethod()
           
 javax.servlet.ServletOutputStream getOutputStream()
           
 java.lang.String getParameter(java.lang.String name)
           
 java.util.Map getParameterMap()
          Returns a java.util.Map of the parameters of this request.
 java.util.Enumeration getParameterNames()
           
 java.lang.String[] getParameterValues(java.lang.String name)
           
 java.lang.String getPathInfo()
           
 java.lang.String getPathTranslated()
           
 java.lang.String getProtocol()
           
 java.lang.String getQueryString()
           
 java.io.BufferedReader getReader()
           
 java.lang.String getRealPath(java.lang.String path)
           
 java.lang.String getRemoteAddr()
           
 java.lang.String getRemoteHost()
           
 java.lang.String getRemoteUser()
           
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String urlpath)
           
 java.lang.String getRequestedSessionId()
           
 java.lang.String getRequestURI()
          Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
 java.lang.StringBuffer getRequestURL()
          Reconstructs the URL the client used to make the request.
 java.lang.String getScheme()
           
 java.lang.String getServerName()
           
 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()
          Returns a boolean indicating if the response has been committed.
 boolean isRequestedSessionIdFromCookie()
          Checks whether the session id specified by this request came in as a cookie.
 boolean isRequestedSessionIdFromUrl()
           
 boolean isRequestedSessionIdFromURL()
           
 boolean isRequestedSessionIdValid()
           
 boolean isSecure()
           
 boolean isUserInRole(java.lang.String user)
           
static void putAll(java.util.Map map, java.util.Map src)
           
 void removeAttribute(java.lang.String name)
           
 void reset()
          Clears any data that exists in the buffer as well as the status code and headers.
 void resetBuffer()
          Clears the content of the underlying buffer in the response without clearing headers or status code.
 void run()
           
 void sendError(int resCode)
           
 void sendError(int resCode, java.lang.String resMessage)
           
 void sendRedirect(java.lang.String location)
           
 void setAttribute(java.lang.String key, java.lang.Object o)
           
 void setBufferSize(int size)
           
 void setCharacterEncoding(java.lang.String _enc)
          Overrides the name of the character encoding used in the body of this request.
 void setContentLength(int length)
           
 void setContentType(java.lang.String type)
           
 void setDateHeader(java.lang.String name, long value)
           
 void setHeader(java.lang.String name, java.lang.String value)
           
 void setIntHeader(java.lang.String name, int value)
           
 void setLocale(java.util.Locale locale)
          Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
 void setLongHeader(java.lang.String name, long value)
           
 void setStatus(int resCode)
           
 void setStatus(int resCode, java.lang.String resMessage)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WWWFORMURLENCODE

public static final java.lang.String WWWFORMURLENCODE
See Also:
Constant Field Values

TRANSFERENCODING

public static final java.lang.String TRANSFERENCODING
See Also:
Constant Field Values

CHUNKED

public static final java.lang.String CHUNKED
See Also:
Constant Field Values

CONTENTLENGTH

public static final java.lang.String CONTENTLENGTH
See Also:
Constant Field Values

CONTENTTYPE

public static final java.lang.String CONTENTTYPE
See Also:
Constant Field Values

SETCOOKIE

public static final java.lang.String SETCOOKIE
See Also:
Constant Field Values

COOKIE

public static final java.lang.String COOKIE
See Also:
Constant Field Values

SESSION_COOKIE_NAME

public static final java.lang.String SESSION_COOKIE_NAME
See Also:
Constant Field Values

expdatefmt

protected static final java.text.SimpleDateFormat expdatefmt

headerdateformat

protected static final java.text.SimpleDateFormat headerdateformat
Constructor Detail

ServeConnection

public ServeConnection(java.net.Socket socket,
                       Serve serve)
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

getContentLength

public int getContentLength()
Specified by:
getContentLength in interface javax.servlet.ServletRequest

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface javax.servlet.ServletRequest

getProtocol

public java.lang.String getProtocol()
Specified by:
getProtocol in interface javax.servlet.ServletRequest

getScheme

public java.lang.String getScheme()
Specified by:
getScheme in interface javax.servlet.ServletRequest

getServerName

public java.lang.String getServerName()
Specified by:
getServerName in interface javax.servlet.ServletRequest

getServerPort

public int getServerPort()
Specified by:
getServerPort in interface javax.servlet.ServletRequest

getRemoteAddr

public java.lang.String getRemoteAddr()
Specified by:
getRemoteAddr in interface javax.servlet.ServletRequest

getRemoteHost

public java.lang.String getRemoteHost()
Specified by:
getRemoteHost in interface javax.servlet.ServletRequest

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Specified by:
getRealPath in interface javax.servlet.ServletRequest

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws java.io.IOException
Specified by:
getInputStream in interface javax.servlet.ServletRequest
Throws:
java.io.IOException

getReader

public java.io.BufferedReader getReader()
Specified by:
getReader in interface javax.servlet.ServletRequest

putAll

public static void putAll(java.util.Map map,
                          java.util.Map src)

getParameterNames

public java.util.Enumeration getParameterNames()
Specified by:
getParameterNames in interface javax.servlet.ServletRequest

getParameter

public java.lang.String getParameter(java.lang.String name)
Specified by:
getParameter in interface javax.servlet.ServletRequest

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Specified by:
getParameterValues in interface javax.servlet.ServletRequest

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Specified by:
getAttribute in interface javax.servlet.ServletRequest

getCookies

public javax.servlet.http.Cookie[] getCookies()
Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest

getMethod

public java.lang.String getMethod()
Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest

getRequestURI

public java.lang.String getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. To reconstruct an URL with a scheme and host, use HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest).

Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest

getRequestURL

public java.lang.StringBuffer getRequestURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.
Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters.

This method is useful for creating redirect messages and for reporting errors.

Specified by:
getRequestURL in interface javax.servlet.http.HttpServletRequest
Returns:
a StringBuffer object containing the reconstructed URL
Since:
2.3

getServletPath

public java.lang.String getServletPath()
Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest

getPathInfo

public java.lang.String getPathInfo()
Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest

getPathTranslated

public java.lang.String getPathTranslated()
Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest

getQueryString

public java.lang.String getQueryString()
Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest

getRemoteUser

public java.lang.String getRemoteUser()
Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest

getAuthType

public java.lang.String getAuthType()
Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest

getHeader

public java.lang.String getHeader(java.lang.String name)
Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest

getIntHeader

public int getIntHeader(java.lang.String name)
Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest

getIntHeader

public int getIntHeader(java.lang.String name,
                        int def)

getLongHeader

public long getLongHeader(java.lang.String name,
                          long def)

getDateHeader

public long getDateHeader(java.lang.String name)
Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest

getDateHeader

public long getDateHeader(java.lang.String name,
                          long def)

getHeaderNames

public java.util.Enumeration getHeaderNames()
Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession()
Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Specified by:
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequest

getAttributeNames

public java.util.Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object o)
Specified by:
setAttribute in interface javax.servlet.ServletRequest

getRequestedSessionId

public java.lang.String getRequestedSessionId()
Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Checks whether the session id specified by this request came in as a cookie. (The requested session may not be one returned by the getSession method.)

Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest

setContentLength

public void setContentLength(int length)
Specified by:
setContentLength in interface javax.servlet.ServletResponse

setContentType

public void setContentType(java.lang.String type)
Specified by:
setContentType in interface javax.servlet.ServletResponse

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
Specified by:
getOutputStream in interface javax.servlet.ServletResponse

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Specified by:
getWriter in interface javax.servlet.ServletResponse
Throws:
java.io.IOException

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Specified by:
getCharacterEncoding in interface javax.servlet.ServletRequest
Specified by:
getCharacterEncoding in interface javax.servlet.ServletResponse

flushBuffer

public void flushBuffer()
Specified by:
flushBuffer in interface javax.servlet.ServletResponse

resetBuffer

public void resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code. If the response has been committed, this method throws an IllegalStateException.

Specified by:
resetBuffer in interface javax.servlet.ServletResponse
Since:
2.3

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface javax.servlet.ServletResponse

setBufferSize

public void setBufferSize(int size)
Specified by:
setBufferSize in interface javax.servlet.ServletResponse

isCommitted

public boolean isCommitted()
Returns a boolean indicating if the response has been committed. A commited response has already had its status code and headers written.

Specified by:
isCommitted in interface javax.servlet.ServletResponse
Returns:
a boolean indicating if the response has been committed
See Also:
setBufferSize(int), getBufferSize(), flushBuffer(), reset()

reset

public void reset()
           throws java.lang.IllegalStateException
Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.

Specified by:
reset in interface javax.servlet.ServletResponse
Throws:
java.lang.IllegalStateException - - if the response has already been committed
See Also:
setBufferSize(int), getBufferSize(), flushBuffer(), isCommitted()

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate. This method should be called before a call to getWriter(). By default, the response locale is the default locale for the server.

Specified by:
setLocale in interface javax.servlet.ServletResponse
Parameters:
loc - - the locale of the response
See Also:
getLocale()

getLocale

public java.util.Locale getLocale()
Specified by:
getLocale in interface javax.servlet.ServletRequest
Specified by:
getLocale in interface javax.servlet.ServletResponse

getLocales

public java.util.Enumeration getLocales()
Specified by:
getLocales in interface javax.servlet.ServletRequest

setCharacterEncoding

public void setCharacterEncoding(java.lang.String _enc)
                          throws java.io.UnsupportedEncodingException
Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader().

Specified by:
setCharacterEncoding in interface javax.servlet.ServletRequest
Parameters:
a - - String containing the name of the chararacter encoding.
Throws:
java.io.UnsupportedEncodingException - - if this is not a valid encoding
Since:
JSDK 2.3

addDateHeader

public void addDateHeader(java.lang.String header,
                          long date)
Specified by:
addDateHeader in interface javax.servlet.http.HttpServletResponse

addHeader

public void addHeader(java.lang.String header,
                      java.lang.String value)
Specified by:
addHeader in interface javax.servlet.http.HttpServletResponse

addIntHeader

public void addIntHeader(java.lang.String header,
                         int value)
Specified by:
addIntHeader in interface javax.servlet.http.HttpServletResponse

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String urlpath)
Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest

isSecure

public boolean isSecure()
Specified by:
isSecure in interface javax.servlet.ServletRequest

removeAttribute

public void removeAttribute(java.lang.String name)
Specified by:
removeAttribute in interface javax.servlet.ServletRequest

getContextPath

public java.lang.String getContextPath()
Specified by:
getContextPath in interface javax.servlet.http.HttpServletRequest

getHeaders

public java.util.Enumeration getHeaders(java.lang.String header)
Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest

getUserPrincipal

public java.security.Principal getUserPrincipal()
Specified by:
getUserPrincipal in interface javax.servlet.http.HttpServletRequest

isUserInRole

public boolean isUserInRole(java.lang.String user)
Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest

getParameterMap

public java.util.Map getParameterMap()
Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

Specified by:
getParameterMap in interface javax.servlet.ServletRequest
Returns:
an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
Since:
2.3

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Specified by:
addCookie in interface javax.servlet.http.HttpServletResponse

containsHeader

public boolean containsHeader(java.lang.String name)
Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse

encodeURL

public java.lang.String encodeURL(java.lang.String url)
Specified by:
encodeURL in interface javax.servlet.http.HttpServletResponse

encodeRedirectURL

public java.lang.String encodeRedirectURL(java.lang.String url)
Specified by:
encodeRedirectURL in interface javax.servlet.http.HttpServletResponse

setStatus

public void setStatus(int resCode,
                      java.lang.String resMessage)
Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse

setStatus

public void setStatus(int resCode)
Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse

setIntHeader

public void setIntHeader(java.lang.String name,
                         int value)
Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse

setLongHeader

public void setLongHeader(java.lang.String name,
                          long value)

setDateHeader

public void setDateHeader(java.lang.String name,
                          long value)
Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse

sendError

public void sendError(int resCode,
                      java.lang.String resMessage)
               throws java.io.IOException
Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Throws:
java.io.IOException

sendError

public void sendError(int resCode)
               throws java.io.IOException
Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Throws:
java.io.IOException

sendRedirect

public void sendRedirect(java.lang.String location)
                  throws java.io.IOException
Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse
Throws:
java.io.IOException

encodeUrl

public java.lang.String encodeUrl(java.lang.String url)
Specified by:
encodeUrl in interface javax.servlet.http.HttpServletResponse

encodeRedirectUrl

public java.lang.String encodeRedirectUrl(java.lang.String url)
Specified by:
encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse