Acme.Serve
Class Serve.ServeConnection

java.lang.Object
  extended by Acme.Serve.Serve.ServeConnection
All Implemented Interfaces:
Runnable, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletRequest, javax.servlet.ServletResponse
Enclosing class:
Serve

public static class Serve.ServeConnection
extends Object
implements Runnable, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse

provides request/response


Field Summary
static String ACCEPT_LANGUAGE
           
static String CHUNKED
           
static String CONNECTION
           
static String CONTENT_ENCODING
           
static String CONTENTLENGTH
           
static String CONTENTTYPE
           
static String COOKIE
           
static String HOST
           
protected  boolean keepAlive
           
static String KEEPALIVE
           
protected  long lastRun
           
protected  long lastWait
           
protected  String reqQuery
           
static String SESSION_COOKIE_NAME
           
static String SESSION_URL_NAME
           
static String SETCOOKIE
           
protected  int timesRequested
           
static String TRANSFERENCODING
           
static 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_FOUND, 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
Serve.ServeConnection(Socket socket, Serve serve)
           
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
           
 void addDateHeader(String header, long date)
           
 void addHeader(String header, String value)
           
 void addIntHeader(String header, int value)
           
 void closeSocket()
           
 void closeStreams()
          it closes stream awaring of keep -alive
 boolean containsHeader(String name)
           
 String encodeRedirectUrl(String url)
           
 String encodeRedirectURL(String url)
           
 String encodeUrl(String url)
           
 String encodeURL(String url)
           
 void flushBuffer()
           
 Object getAttribute(String name)
           
 Enumeration getAttributeNames()
           
 String getAuthType()
           
 int getBufferSize()
           
 String getCharacterEncoding()
           
 int getContentLength()
           
 String getContentType()
           
 String getContextPath()
           
 javax.servlet.http.Cookie[] getCookies()
           
 long getDateHeader(String name)
           
 String getHeader(String name)
           
 Enumeration getHeaderNames()
           
 Enumeration getHeaders(String header)
           
 javax.servlet.ServletInputStream getInputStream()
           
 int getIntHeader(String name)
           
 String getLocalAddr()
          Returns the Internet Protocol (IP) address of the interface on which the request was received.
 Locale getLocale()
          For request: Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.
 Enumeration getLocales()
          Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.
 String getLocalName()
          Returns the host name of the Internet Protocol (IP) interface on which the request was received.
 int getLocalPort()
          Returns the Internet Protocol (IP) port number of the interface on which the request was received.
 String getMethod()
           
 javax.servlet.ServletOutputStream getOutputStream()
           
 String getParameter(String name)
           
 Map getParameterMap()
          Returns a java.util.Map of the parameters of this request.
 Enumeration getParameterNames()
           
 String[] getParameterValues(String name)
           
 String getPathInfo()
           
 String getPathTranslated()
           
 String getProtocol()
           
 String getQueryString()
           
 BufferedReader getReader()
           
 String getRealPath(String path)
           
 String getRemoteAddr()
           
 String getRemoteHost()
           
 int getRemotePort()
          Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
 String getRemoteUser()
           
 javax.servlet.RequestDispatcher getRequestDispatcher(String urlpath)
           
 String getRequestedSessionId()
           
 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.
 StringBuffer getRequestURL()
          Reconstructs the URL the client used to make the request.
 String getScheme()
           
 String getServerName()
           
 int getServerPort()
           
 String getServletPath()
           
 javax.servlet.http.HttpSession getSession()
           
 javax.servlet.http.HttpSession getSession(boolean create)
           
 Socket getSocket()
           
 Principal getUserPrincipal()
           
 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(String user)
           
 void removeAttribute(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, String resMessage)
           
 void sendRedirect(String location)
           
 void setAttribute(String key, Object o)
          Stores an attribute in this request.
 void setBufferSize(int size)
           
 void setCharacterEncoding(String _enc)
          Overrides the name of the character encoding used in the body of this request.
 void setContentLength(int length)
           
 void setContentType(String type)
           
 void setDateHeader(String header, long value)
           
 void setHeader(String header, String value)
           
 void setInInclude(boolean set)
           
 void setIntHeader(String header, int value)
           
 void setLocale(Locale locale)
          Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
 void setLongHeader(String header, long value)
           
 void setStatus(int resCode)
           
 void setStatus(int resCode, 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 String WWWFORMURLENCODE
See Also:
Constant Field Values

TRANSFERENCODING

public static final String TRANSFERENCODING

KEEPALIVE

public static final String KEEPALIVE

CONTENT_ENCODING

public static final String CONTENT_ENCODING

CONNECTION

public static final String CONNECTION

CHUNKED

public static final String CHUNKED
See Also:
Constant Field Values

CONTENTLENGTH

public static final String CONTENTLENGTH

CONTENTTYPE

public static final String CONTENTTYPE

SETCOOKIE

public static final String SETCOOKIE

HOST

public static final String HOST

COOKIE

public static final String COOKIE

ACCEPT_LANGUAGE

public static final String ACCEPT_LANGUAGE

SESSION_COOKIE_NAME

public static final String SESSION_COOKIE_NAME
See Also:
Constant Field Values

SESSION_URL_NAME

public static final String SESSION_URL_NAME
See Also:
Constant Field Values

keepAlive

protected boolean keepAlive

timesRequested

protected int timesRequested

lastRun

protected long lastRun

lastWait

protected long lastWait

reqQuery

protected String reqQuery
Constructor Detail

Serve.ServeConnection

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

closeStreams

public void closeStreams()
                  throws IOException
it closes stream awaring of keep -alive

Throws:
IOException

closeSocket

public void closeSocket()

run

public void run()
Specified by:
run in interface Runnable

getContentLength

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

getContentType

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

getProtocol

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

getScheme

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

getServerName

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

getServerPort

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

getRemoteAddr

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

getRemoteHost

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

getRealPath

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

getInputStream

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

getReader

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

getParameterNames

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

getParameter

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

getParameterValues

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

getAttribute

public Object getAttribute(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 String getMethod()
Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest

getRequestURI

public 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 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 String getServletPath()
Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest

getPathInfo

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

getPathTranslated

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

getQueryString

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

getRemoteUser

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

getAuthType

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

getHeader

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

getIntHeader

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

getDateHeader

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

getHeaderNames

public 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 Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

setAttribute

public void setAttribute(String key,
                         Object o)
Stores an attribute in this request. Attributes are reset between requests. This method is most often used in conjunction with RequestDispatcher.

Attribute names should follow the same conventions as package names. Names beginning with java.*, javax.*, and com.sun.*, are reserved for use by Sun Microsystems. If the object passed in is null, the effect is the same as calling removeAttribute(java.lang.String).

It is warned that when the request is dispatched from the servlet resides in a different web application by RequestDispatcher, the object set by this method may not be correctly retrieved in the caller servlet.

Specified by:
setAttribute in interface javax.servlet.ServletRequest
Parameters:
name - - a String specifying the name of the attribute
o - - the Object to be stored

getRequestedSessionId

public 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(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 PrintWriter getWriter()
                      throws IOException
Specified by:
getWriter in interface javax.servlet.ServletResponse
Throws:
IOException

getCharacterEncoding

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

flushBuffer

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

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 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:
IllegalStateException - - if the response has already been committed
See Also:
setBufferSize(int), getBufferSize(), flushBuffer(), isCommitted()

setLocale

public void setLocale(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 Locale getLocale()
For request: Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.

For response: Returns the locale specified for this response using the setLocale(java.util.Locale) method. Calls made to setLocale after the response is committed have no effect. If no locale has been specified, the container's default locale is returned.

Specified by:
getLocale in interface javax.servlet.ServletRequest
Specified by:
getLocale in interface javax.servlet.ServletResponse

getLocales

public Enumeration getLocales()
Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns an Enumeration containing one Locale, the default locale for the server.

Specified by:
getLocales in interface javax.servlet.ServletRequest

setCharacterEncoding

public void setCharacterEncoding(String _enc)
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
Specified by:
setCharacterEncoding in interface javax.servlet.ServletResponse
Parameters:
a - - String containing the name of the chararacter encoding.
Throws:
UnsupportedEncodingException - - if this is not a valid encoding
Since:
JSDK 2.3

addDateHeader

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

addHeader

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

addIntHeader

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

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(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(String name)
Specified by:
removeAttribute in interface javax.servlet.ServletRequest

getContextPath

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

getHeaders

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

getUserPrincipal

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

isUserInRole

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

getParameterMap

public 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(String name)
Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse

encodeURL

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

encodeRedirectURL

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

getRemotePort

public int getRemotePort()
Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.

Specified by:
getRemotePort in interface javax.servlet.ServletRequest
Returns:
an integer specifying the port number
Since:
2.4

getLocalName

public String getLocalName()
Returns the host name of the Internet Protocol (IP) interface on which the request was received.

Specified by:
getLocalName in interface javax.servlet.ServletRequest
Returns:
a String containing the host name of the IP on which the request was received.
Since:
2.4

getLocalAddr

public String getLocalAddr()
Returns the Internet Protocol (IP) address of the interface on which the request was received.

Specified by:
getLocalAddr in interface javax.servlet.ServletRequest
Returns:
a String containing the IP address on which the request was received.
Since:
2.4

getLocalPort

public int getLocalPort()
Returns the Internet Protocol (IP) port number of the interface on which the request was received.

Specified by:
getLocalPort in interface javax.servlet.ServletRequest
Returns:
an integer specifying the port number
Since:
2.4

setStatus

public void setStatus(int resCode,
                      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(String header,
                      String value)
Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse

setIntHeader

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

setLongHeader

public void setLongHeader(String header,
                          long value)

setDateHeader

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

sendError

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

sendError

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

setInInclude

public void setInInclude(boolean set)

sendRedirect

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

encodeUrl

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

encodeRedirectUrl

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

getSocket

public Socket getSocket()


Copyright © 2012. All Rights Reserved.