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 ObjectgetAttribute(String name)Get attribute from the server context.StringgetContextPath()Returns the context path, relative to the server root.static javax.servlet.http.HttpServletRequestgetCurrentRequest()static javax.servlet.http.HttpServletResponsegetCurrentResponse()static KawaServlet.ContextgetInstance(String command)static KawaServlet.ContextgetInstanceOrNull()InetAddressgetLocalHost()StringgetLocalIPAddress()intgetLocalPort()StringgetPathTranslated()StringgetQueryString()InetAddressgetRemoteHost()StringgetRemoteIPAddress()intgetRemotePort()javax.servlet.http.HttpServletRequestgetRequest()StringgetRequestHeader(String name)Map<String,List<String>>getRequestHeaders()List<String>getRequestHeaders(String name)StringgetRequestMethod()Map<String,List<String>>getRequestParameters()StringgetRequestPath()StringgetRequestScheme()InputStreamgetRequestStream()URIgetRequestURI()StringBuffergetRequestURLBuffer()URLgetResourceURL(String path)Returns the URL of a resource.javax.servlet.http.HttpServletResponsegetResponse()OutputStreamgetResponseStream()Return an OutputStream for the result body.javax.servlet.http.HttpServletgetServlet()javax.servlet.ServletConfiggetServletConfig()javax.servlet.ServletContextgetServletContext()StringgetServletPath()voidlog(String message)voidlog(String message, Throwable ex)booleanreset(boolean headersAlso)Try to reset (delete) any response generated so far.voidsendResponseHeaders(int reasonCode, String reasonPhrase, long responseLength)Send headers.voidsetAttribute(String name, Object value)Set attribute in the server context.voidsetContentType(String type)voidsetResponseHeader(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:
getRequestURIin classHttpRequestContext
-
getContextPath
public String getContextPath()
Description copied from class:HttpRequestContextReturns 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:
getContextPathin classHttpRequestContext
-
getQueryString
public String getQueryString()
- Specified by:
getQueryStringin classHttpRequestContext
-
getRequestMethod
public String getRequestMethod()
- Specified by:
getRequestMethodin classHttpRequestContext
-
getRequestPath
public String getRequestPath()
- Overrides:
getRequestPathin classHttpRequestContext
-
getRequestScheme
public String getRequestScheme()
- Overrides:
getRequestSchemein classHttpRequestContext
-
getLocalHost
public InetAddress getLocalHost()
- Overrides:
getLocalHostin classHttpRequestContext
-
getLocalIPAddress
public String getLocalIPAddress()
- Overrides:
getLocalIPAddressin classHttpRequestContext
-
getLocalPort
public int getLocalPort()
- Specified by:
getLocalPortin classHttpRequestContext
-
getRemoteIPAddress
public String getRemoteIPAddress()
- Specified by:
getRemoteIPAddressin classHttpRequestContext
-
getRemoteHost
public InetAddress getRemoteHost()
- Specified by:
getRemoteHostin classHttpRequestContext
-
getRemotePort
public int getRemotePort()
- Specified by:
getRemotePortin classHttpRequestContext
-
getRequestURLBuffer
public StringBuffer getRequestURLBuffer()
- Overrides:
getRequestURLBufferin classHttpRequestContext
-
getServletPath
public String getServletPath()
-
getPathTranslated
public String getPathTranslated()
- Specified by:
getPathTranslatedin classHttpRequestContext
-
getRequestParameters
public Map<String,List<String>> getRequestParameters()
- Specified by:
getRequestParametersin classHttpRequestContext
-
getRequestHeader
public String getRequestHeader(String name)
- Specified by:
getRequestHeaderin classHttpRequestContext
-
getRequestHeaders
public Map<String,List<String>> getRequestHeaders()
- Specified by:
getRequestHeadersin classHttpRequestContext
-
getRequestHeaders
public List<String> getRequestHeaders(String name)
- Specified by:
getRequestHeadersin classHttpRequestContext
-
getRequestStream
public InputStream getRequestStream()
- Specified by:
getRequestStreamin classHttpRequestContext
-
getResponseStream
public OutputStream getResponseStream()
Description copied from class:HttpRequestContextReturn an OutputStream for the result body. Multiple calls will return the same OutputStream.- Specified by:
getResponseStreamin classHttpRequestContext
-
setResponseHeader
public void setResponseHeader(String name, String value)
- Specified by:
setResponseHeaderin classHttpRequestContext
-
setContentType
public void setContentType(String type)
- Overrides:
setContentTypein classHttpRequestContext
-
reset
public boolean reset(boolean headersAlso)
Description copied from class:HttpRequestContextTry to reset (delete) any response generated so far.- Specified by:
resetin 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:HttpRequestContextReturns 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:
getResourceURLin classHttpRequestContext
-
getAttribute
public Object getAttribute(String name)
Description copied from class:HttpRequestContextGet attribute from the server context.- Specified by:
getAttributein classHttpRequestContext
-
setAttribute
public void setAttribute(String name, Object value)
Description copied from class:HttpRequestContextSet attribute in the server context.- Specified by:
setAttributein classHttpRequestContext
-
sendResponseHeaders
public void sendResponseHeaders(int reasonCode, String reasonPhrase, long responseLength) throws IOExceptionDescription copied from class:HttpRequestContextSend headers.- Specified by:
sendResponseHeadersin 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:
login classHttpRequestContext
-
log
public void log(String message, Throwable ex)
- Specified by:
login classHttpRequestContext
-
-