Package gnu.kawa.servlet
Class HttpRequestContext
- java.lang.Object
-
- gnu.kawa.servlet.HttpRequestContext
-
- Direct Known Subclasses:
KawaHttpHandler.Context,KawaServlet.Context
public abstract class HttpRequestContext extends java.lang.ObjectA representation of an http request as it is being handled. It abstracts over different http server's API - specially, there are are concrete implementations on top of JDK6's com.sun.net.httpserver, javax.servlet.http, and CGI (on top of servlets).
-
-
Field Summary
Fields Modifier and Type Field Description static intHTTP_NOT_FOUNDstatic intHTTP_OKstatic intimportServletDefinitionsThis is a bit of a kludge, to import servlet functions into Scheme.protected static java.lang.ThreadLocal<HttpRequestContext>instanceintstatusCodejava.lang.StringstatusReasonPhrase
-
Constructor Summary
Constructors Constructor Description HttpRequestContext()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.ObjectgetAttribute(java.lang.String name)Get attribute from the server context.ServletPrintergetConsumer()abstract java.lang.StringgetContextPath()Returns the context path, relative to the server root.static HttpRequestContextgetInstance()static HttpRequestContextgetInstance(java.lang.String command)java.net.InetAddressgetLocalHost()java.lang.StringgetLocalIPAddress()java.lang.StringgetLocalPath()Returns the remainder of the request path, relative to the script.abstract intgetLocalPort()java.net.InetSocketAddressgetLocalSocketAddress()abstract java.lang.StringgetPathTranslated()abstract java.lang.StringgetQueryString()abstract java.net.InetAddressgetRemoteHost()abstract java.lang.StringgetRemoteIPAddress()abstract intgetRemotePort()java.net.InetSocketAddressgetRemoteSocketAddress()java.lang.StringgetRequestBodyChars()abstract java.lang.StringgetRequestHeader(java.lang.String name)abstract java.util.Map<java.lang.String,java.util.List<java.lang.String>>getRequestHeaders()abstract java.util.List<java.lang.String>getRequestHeaders(java.lang.String name)abstract java.lang.StringgetRequestMethod()java.lang.StringgetRequestParameter(java.lang.String name)abstract java.util.Map<java.lang.String,java.util.List<java.lang.String>>getRequestParameters()java.lang.StringgetRequestPath()gnu.kawa.io.InPortgetRequestPort()java.lang.StringgetRequestScheme()abstract java.io.InputStreamgetRequestStream()abstract java.net.URIgetRequestURI()java.lang.StringBuffergetRequestURLBuffer()abstract java.net.URLgetResourceURL(java.lang.String path)Returns the URL of a resource.abstract java.io.OutputStreamgetResponseStream()Return an OutputStream for the result body.java.lang.StringgetScriptPath()Returns the path of the script, relative to the context.static voidhandleStaticFile(HttpRequestContext hctx, gnu.kawa.io.Path absPath)abstract voidlog(java.lang.String message)abstract voidlog(java.lang.String message, java.lang.Throwable ex)protected java.lang.StringnormalizeToContext(java.lang.String path)abstract booleanreset(boolean headersAlso)Try to reset (delete) any response generated so far.voidsendNotFound(java.lang.String path)abstract voidsendResponseHeaders(int reasonCode, java.lang.String reasonPhrase, long responseLength)Send headers.abstract voidsetAttribute(java.lang.String name, java.lang.Object value)Set attribute in the server context.voidsetContentType(java.lang.String type)static voidsetInstance(HttpRequestContext ctx)abstract voidsetResponseHeader(java.lang.String name, java.lang.String value)voidsetScriptAndLocalPath(java.lang.String scriptPath, java.lang.String localPath)
-
-
-
Field Detail
-
HTTP_OK
public static final int HTTP_OK
- See Also:
- Constant Field Values
-
HTTP_NOT_FOUND
public static final int HTTP_NOT_FOUND
- See Also:
- Constant Field Values
-
statusCode
public int statusCode
-
statusReasonPhrase
public java.lang.String statusReasonPhrase
-
importServletDefinitions
public static int importServletDefinitions
This is a bit of a kludge, to import servlet functions into Scheme. (The kludge is that we really shouldn't be using a static.) If importServletDefinitions == 1, then we're running in (or compiling for) a web server context; if it is 2 we specifically support servlets.
-
instance
protected static final java.lang.ThreadLocal<HttpRequestContext> instance
-
-
Method Detail
-
getInstance
public static HttpRequestContext getInstance()
-
getInstance
public static HttpRequestContext getInstance(java.lang.String command)
-
setInstance
public static void setInstance(HttpRequestContext ctx)
-
getRequestStream
public abstract java.io.InputStream getRequestStream()
-
getRequestPort
public gnu.kawa.io.InPort getRequestPort()
-
getRequestBodyChars
public java.lang.String getRequestBodyChars() throws java.io.IOException- Throws:
java.io.IOException
-
getResponseStream
public abstract java.io.OutputStream getResponseStream()
Return an OutputStream for the result body. Multiple calls will return the same OutputStream.
-
getConsumer
public ServletPrinter getConsumer() throws java.io.IOException
- Throws:
java.io.IOException
-
reset
public abstract boolean reset(boolean headersAlso)
Try to reset (delete) any response generated so far.- Parameters:
headersAlso- if response headers should also be reset.- Returns:
- true on success, false if it's too late.
-
getRequestParameter
public java.lang.String getRequestParameter(java.lang.String name)
-
getRequestParameters
public abstract java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestParameters()
-
getRequestURI
public abstract java.net.URI getRequestURI()
-
getContextPath
public abstract java.lang.String getContextPath()
Returns the context path, relative to the server root. This is an initial substring of thegetRequestPath(). LikeServletContext#getContextPath, but ends with a'/'. The stringgetRequestURI()is the same as the concatenation ofgetContextPath(),getScriptPath(), andgetLocalPath().
-
getScriptPath
public java.lang.String getScriptPath()
Returns the path of the script, relative to the context. LikeServletRequestt#getServletPath, but ends with a'/', and does not start with one. (The reason for this is to produce URIs that work better with operations like resolve-uri.)
-
getLocalPath
public java.lang.String getLocalPath()
Returns the remainder of the request path, relative to the script.
-
setScriptAndLocalPath
public void setScriptAndLocalPath(java.lang.String scriptPath, java.lang.String localPath)
-
getPathTranslated
public abstract java.lang.String getPathTranslated()
-
getRequestPath
public java.lang.String getRequestPath()
-
getRequestScheme
public java.lang.String getRequestScheme()
-
getLocalSocketAddress
public java.net.InetSocketAddress getLocalSocketAddress()
-
getLocalIPAddress
public java.lang.String getLocalIPAddress()
-
getLocalHost
public java.net.InetAddress getLocalHost()
-
getLocalPort
public abstract int getLocalPort()
-
getRemoteSocketAddress
public java.net.InetSocketAddress getRemoteSocketAddress()
-
getRemoteHost
public abstract java.net.InetAddress getRemoteHost()
-
getRemoteIPAddress
public abstract java.lang.String getRemoteIPAddress()
-
getRemotePort
public abstract int getRemotePort()
-
getRequestURLBuffer
public java.lang.StringBuffer getRequestURLBuffer()
-
getQueryString
public abstract java.lang.String getQueryString()
-
getRequestMethod
public abstract java.lang.String getRequestMethod()
-
getRequestHeader
public abstract java.lang.String getRequestHeader(java.lang.String name)
-
getRequestHeaders
public abstract java.util.List<java.lang.String> getRequestHeaders(java.lang.String name)
-
getRequestHeaders
public abstract java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestHeaders()
-
setResponseHeader
public abstract void setResponseHeader(java.lang.String name, java.lang.String value)
-
setContentType
public void setContentType(java.lang.String type)
-
normalizeToContext
protected java.lang.String normalizeToContext(java.lang.String path)
-
getResourceURL
public abstract java.net.URL getResourceURL(java.lang.String path)
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.
-
getAttribute
public abstract java.lang.Object getAttribute(java.lang.String name)
Get attribute from the server context.
-
setAttribute
public abstract void setAttribute(java.lang.String name, java.lang.Object value)Set attribute in the server context.
-
sendResponseHeaders
public abstract void sendResponseHeaders(int reasonCode, java.lang.String reasonPhrase, long responseLength) throws java.io.IOExceptionSend headers.- 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:
java.io.IOException
-
sendNotFound
public void sendNotFound(java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
log
public abstract void log(java.lang.String message)
-
log
public abstract void log(java.lang.String message, java.lang.Throwable ex)
-
handleStaticFile
public static void handleStaticFile(HttpRequestContext hctx, gnu.kawa.io.Path absPath) throws java.io.IOException
- Throws:
java.io.IOException
-
-