Package edu.wpi.grip.core.http
Class GenericHandler
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.handler.AbstractHandler
-
- edu.wpi.grip.core.http.GenericHandler
-
- All Implemented Interfaces:
org.eclipse.jetty.server.Handler
,org.eclipse.jetty.util.component.Container
,org.eclipse.jetty.util.component.Destroyable
,org.eclipse.jetty.util.component.Dumpable
,org.eclipse.jetty.util.component.LifeCycle
- Direct Known Subclasses:
PedanticHandler
public abstract class GenericHandler extends org.eclipse.jetty.server.handler.AbstractHandler
Generic Jetty handler.Instances of this class can either claim a context, preventing other instances from handling events on that context, or not, in which case it will run on any context.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONTENT_TYPE_HTML
HTTP content type for HTML.static java.lang.String
CONTENT_TYPE_JSON
HTTP content type for json.static java.lang.String
CONTENT_TYPE_PLAIN_TEXT
HTTP content type for plain text.protected java.lang.String
context
The context that this handles.
-
Constructor Summary
Constructors Modifier Constructor Description protected
GenericHandler()
Creates a generic handler for all contexts on the server.protected
GenericHandler(ContextStore store, java.lang.String context)
Creates a generic handler that handles requests for the given context.protected
GenericHandler(ContextStore store, java.lang.String context, boolean doClaim)
Creates a generic handler that handles requests for the given context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getContext()
Gets the context for this handler.protected static boolean
isGet(javax.servlet.http.HttpServletRequest request)
Checks if the given request is a GET.protected static boolean
isPost(javax.servlet.http.HttpServletRequest request)
Checks if the given request is a POST.protected void
releaseContext()
Releases the context that this handles, allowing it to be claimed by another handler.protected static void
sendTextContent(javax.servlet.http.HttpServletResponse response, java.lang.String content, java.lang.String contentType)
Sends text content to the client.-
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler
destroy, doStart, doStop, dumpThis, getServer, setServer
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Field Detail
-
context
protected final java.lang.String context
The context that this handles.
-
CONTENT_TYPE_JSON
public static final java.lang.String CONTENT_TYPE_JSON
HTTP content type for json.- See Also:
- Constant Field Values
-
CONTENT_TYPE_HTML
public static final java.lang.String CONTENT_TYPE_HTML
HTTP content type for HTML.- See Also:
- Constant Field Values
-
CONTENT_TYPE_PLAIN_TEXT
public static final java.lang.String CONTENT_TYPE_PLAIN_TEXT
HTTP content type for plain text.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GenericHandler
protected GenericHandler()
Creates a generic handler for all contexts on the server.
-
GenericHandler
protected GenericHandler(ContextStore store, java.lang.String context)
Creates a generic handler that handles requests for the given context. That context will not be claimed.Note that the context is case sensitive.
- Parameters:
store
- the context store to use to check for claimed contextscontext
- the context for this handler- Throws:
java.lang.IllegalArgumentException
- if the given context has already been claimed
-
GenericHandler
protected GenericHandler(ContextStore store, java.lang.String context, boolean doClaim)
Creates a generic handler that handles requests for the given context.Note that the context is case sensitive.
- Parameters:
store
- the context store to use to check for claimed contextscontext
- the context for this handlerdoClaim
- flag marking if the given context should be claimed- Throws:
java.lang.IllegalArgumentException
- if the given context has already been claimed
-
-
Method Detail
-
releaseContext
protected void releaseContext()
Releases the context that this handles, allowing it to be claimed by another handler.
-
getContext
public java.lang.String getContext()
Gets the context for this handler.
-
sendTextContent
protected static void sendTextContent(javax.servlet.http.HttpServletResponse response, java.lang.String content, java.lang.String contentType) throws java.io.IOException
Sends text content to the client.- Parameters:
response
- the response that will be sent to the clientcontent
- the content to sendcontentType
- the type of the content (e.g. "application/json", "text/html")- Throws:
java.io.IOException
- if content couldn't be written to the response
-
isPost
protected static boolean isPost(javax.servlet.http.HttpServletRequest request)
Checks if the given request is a POST.
-
isGet
protected static boolean isGet(javax.servlet.http.HttpServletRequest request)
Checks if the given request is a GET.
-
-