Package gnu.kawa.servlet
Class KawaServlet.Context
- java.lang.Object
-
- gnu.kawa.servlet.HttpRequestContext
-
- gnu.kawa.servlet.KawaServlet.Context
-
- Enclosing class:
- KawaServlet
public static class KawaServlet.Context extends HttpRequestContext
-
-
Field Summary
-
Fields inherited from class gnu.kawa.servlet.HttpRequestContext
HTTP_NOT_FOUND, HTTP_OK, importServletDefinitions, instance, statusCode, statusReasonPhrase
-
-
Constructor Summary
Constructors Constructor Description Context(javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
getAttribute(String name)
Get attribute from the server context.String
getContextPath()
Returns the context path, relative to the server root.static javax.servlet.http.HttpServletRequest
getCurrentRequest()
static javax.servlet.http.HttpServletResponse
getCurrentResponse()
static KawaServlet.Context
getInstance(String command)
static KawaServlet.Context
getInstanceOrNull()
InetAddress
getLocalHost()
String
getLocalIPAddress()
int
getLocalPort()
String
getPathTranslated()
String
getQueryString()
InetAddress
getRemoteHost()
String
getRemoteIPAddress()
int
getRemotePort()
javax.servlet.http.HttpServletRequest
getRequest()
String
getRequestHeader(String name)
Map<String,List<String>>
getRequestHeaders()
List<String>
getRequestHeaders(String name)
String
getRequestMethod()
Map<String,List<String>>
getRequestParameters()
String
getRequestPath()
String
getRequestScheme()
InputStream
getRequestStream()
URI
getRequestURI()
StringBuffer
getRequestURLBuffer()
URL
getResourceURL(String path)
Returns the URL of a resource.javax.servlet.http.HttpServletResponse
getResponse()
OutputStream
getResponseStream()
Return an OutputStream for the result body.javax.servlet.http.HttpServlet
getServlet()
javax.servlet.ServletConfig
getServletConfig()
javax.servlet.ServletContext
getServletContext()
String
getServletPath()
void
log(String message)
void
log(String message, Throwable ex)
boolean
reset(boolean headersAlso)
Try to reset (delete) any response generated so far.void
sendResponseHeaders(int reasonCode, String reasonPhrase, long responseLength)
Send headers.void
setAttribute(String name, Object value)
Set attribute in the server context.void
setContentType(String type)
void
setResponseHeader(String name, String value)
-
Methods inherited from class gnu.kawa.servlet.HttpRequestContext
getConsumer, getInstance, getLocalPath, getLocalSocketAddress, getRemoteSocketAddress, getRequestBodyChars, getRequestParameter, getRequestPort, getScriptPath, handleStaticFile, normalizeToContext, sendNotFound, setInstance, setScriptAndLocalPath
-
-
-
-
Method Detail
-
getInstance
public static KawaServlet.Context getInstance(String command)
-
getInstanceOrNull
public static KawaServlet.Context getInstanceOrNull()
-
getCurrentRequest
public static javax.servlet.http.HttpServletRequest getCurrentRequest()
-
getCurrentResponse
public static javax.servlet.http.HttpServletResponse getCurrentResponse()
-
getServlet
public javax.servlet.http.HttpServlet getServlet()
-
getRequest
public javax.servlet.http.HttpServletRequest getRequest()
-
getResponse
public javax.servlet.http.HttpServletResponse getResponse()
-
getServletConfig
public javax.servlet.ServletConfig getServletConfig()
-
getServletContext
public javax.servlet.ServletContext getServletContext()
-
getRequestURI
public URI getRequestURI()
- Specified by:
getRequestURI
in classHttpRequestContext
-
getContextPath
public String getContextPath()
Description copied from class:HttpRequestContext
Returns the context path, relative to the server root. This is an initial substring of theHttpRequestContext.getRequestPath()
. LikeServletContext#getContextPath
, but ends with a'/'
. The stringgetRequestURI()
is the same as the concatenation ofgetContextPath()
,getScriptPath()
, andgetLocalPath()
.- Specified by:
getContextPath
in classHttpRequestContext
-
getQueryString
public String getQueryString()
- Specified by:
getQueryString
in classHttpRequestContext
-
getRequestMethod
public String getRequestMethod()
- Specified by:
getRequestMethod
in classHttpRequestContext
-
getRequestPath
public String getRequestPath()
- Overrides:
getRequestPath
in classHttpRequestContext
-
getRequestScheme
public String getRequestScheme()
- Overrides:
getRequestScheme
in classHttpRequestContext
-
getLocalHost
public InetAddress getLocalHost()
- Overrides:
getLocalHost
in classHttpRequestContext
-
getLocalIPAddress
public String getLocalIPAddress()
- Overrides:
getLocalIPAddress
in classHttpRequestContext
-
getLocalPort
public int getLocalPort()
- Specified by:
getLocalPort
in classHttpRequestContext
-
getRemoteIPAddress
public String getRemoteIPAddress()
- Specified by:
getRemoteIPAddress
in classHttpRequestContext
-
getRemoteHost
public InetAddress getRemoteHost()
- Specified by:
getRemoteHost
in classHttpRequestContext
-
getRemotePort
public int getRemotePort()
- Specified by:
getRemotePort
in classHttpRequestContext
-
getRequestURLBuffer
public StringBuffer getRequestURLBuffer()
- Overrides:
getRequestURLBuffer
in classHttpRequestContext
-
getServletPath
public String getServletPath()
-
getPathTranslated
public String getPathTranslated()
- Specified by:
getPathTranslated
in classHttpRequestContext
-
getRequestParameters
public Map<String,List<String>> getRequestParameters()
- Specified by:
getRequestParameters
in classHttpRequestContext
-
getRequestHeader
public String getRequestHeader(String name)
- Specified by:
getRequestHeader
in classHttpRequestContext
-
getRequestHeaders
public Map<String,List<String>> getRequestHeaders()
- Specified by:
getRequestHeaders
in classHttpRequestContext
-
getRequestHeaders
public List<String> getRequestHeaders(String name)
- Specified by:
getRequestHeaders
in classHttpRequestContext
-
getRequestStream
public InputStream getRequestStream()
- Specified by:
getRequestStream
in classHttpRequestContext
-
getResponseStream
public OutputStream getResponseStream()
Description copied from class:HttpRequestContext
Return an OutputStream for the result body. Multiple calls will return the same OutputStream.- Specified by:
getResponseStream
in classHttpRequestContext
-
setResponseHeader
public void setResponseHeader(String name, String value)
- Specified by:
setResponseHeader
in classHttpRequestContext
-
setContentType
public void setContentType(String type)
- Overrides:
setContentType
in classHttpRequestContext
-
reset
public boolean reset(boolean headersAlso)
Description copied from class:HttpRequestContext
Try to reset (delete) any response generated so far.- Specified by:
reset
in classHttpRequestContext
- Parameters:
headersAlso
- if response headers should also be reset.- Returns:
- true on success, false if it's too late.
-
getResourceURL
public URL getResourceURL(String path)
Description copied from class:HttpRequestContext
Returns the URL of a resource. The resource is relative to the script path, if the path is relative; otherwise (if it starts with a'/'
it is relative to the context path.- Specified by:
getResourceURL
in classHttpRequestContext
-
getAttribute
public Object getAttribute(String name)
Description copied from class:HttpRequestContext
Get attribute from the server context.- Specified by:
getAttribute
in classHttpRequestContext
-
setAttribute
public void setAttribute(String name, Object value)
Description copied from class:HttpRequestContext
Set attribute in the server context.- Specified by:
setAttribute
in classHttpRequestContext
-
sendResponseHeaders
public void sendResponseHeaders(int reasonCode, String reasonPhrase, long responseLength) throws IOException
Description copied from class:HttpRequestContext
Send headers.- Specified by:
sendResponseHeaders
in classHttpRequestContext
- Parameters:
reasonCode
- response code - e.g. 200 for OK.reasonPhrase
- response string - e.g. "OK" or "Not Found".responseLength
- response length in bytes, or -1 (unspecified). Note this is different from HttpExchange.sendResponseHeaders. This method must be called before getResponseStream. Implementations should set statusCode to STATUS_SENT.- Throws:
IOException
-
log
public void log(String message)
- Specified by:
log
in classHttpRequestContext
-
log
public void log(String message, Throwable ex)
- Specified by:
log
in classHttpRequestContext
-
-