Package edu.wpi.grip.core.sources
Class HttpImageHandler
- 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
-
- edu.wpi.grip.core.http.PedanticHandler
-
- edu.wpi.grip.core.sources.HttpImageHandler
-
- 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
public final class HttpImageHandler extends PedanticHandler
Jetty handler for incoming images to be used byHttpSource
. Only one instance of this class can exist for a context.This handler will return one of the following status codes to a request on
/GRIP/upload/image
:- 405 - Not Allowed: if the request is not a POST
- 202 - Accepted: if the image sent is the same as the previous one
- 201 - Created: if the image was successfully handled
-
-
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 inherited from class edu.wpi.grip.core.http.GenericHandler
CONTENT_TYPE_HTML, CONTENT_TYPE_JSON, CONTENT_TYPE_PLAIN_TEXT, context
-
-
Constructor Summary
Constructors Constructor Description HttpImageHandler(ContextStore store)
Creates an image handler on the default upload path/GRIP/upload/image
.HttpImageHandler(ContextStore store, java.lang.String path)
Creates an image handler on the given path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCallback(java.util.function.Consumer<org.bytedeco.javacpp.opencv_core.Mat> callback)
Adds a callback to this handler.java.util.Optional<org.bytedeco.javacpp.opencv_core.Mat>
getImage()
Gets the most recently POSTed image.protected void
handleIfPassed(java.lang.String target, org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Handles an HTTP request if the target is the same as the one for this handler.void
removeCallback(java.util.function.Consumer<org.bytedeco.javacpp.opencv_core.Mat> callback)
Removes the given callback from this handler.-
Methods inherited from class edu.wpi.grip.core.http.PedanticHandler
handle
-
Methods inherited from class edu.wpi.grip.core.http.GenericHandler
getContext, isGet, isPost, releaseContext, sendTextContent
-
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
-
-
-
-
Constructor Detail
-
HttpImageHandler
public HttpImageHandler(ContextStore store)
Creates an image handler on the default upload path/GRIP/upload/image
.
-
HttpImageHandler
public HttpImageHandler(ContextStore store, java.lang.String path)
Creates an image handler on the given path.- Parameters:
path
- the path on the server that images will be uploaded to
-
-
Method Detail
-
handleIfPassed
protected void handleIfPassed(java.lang.String target, org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
Description copied from class:PedanticHandler
Handles an HTTP request if the target is the same as the one for this handler.- Specified by:
handleIfPassed
in classPedanticHandler
- Parameters:
target
- the target of the HTTP request (e.g. a request on "localhost:8080/foo/bar" has a target of "foo/bar")baseRequest
- the base HTTP requestrequest
- the request after being wrapped or filtered by other handlersresponse
- the HTTP response to send to the client- Throws:
java.io.IOException
- if an I/O error occurred while handling the requestjavax.servlet.ServletException
- if the request could not be handled- See Also:
Handler.handle(String, Request, HttpServletRequest, HttpServletResponse)
-
getImage
public java.util.Optional<org.bytedeco.javacpp.opencv_core.Mat> getImage()
Gets the most recently POSTed image.
-
addCallback
public void addCallback(java.util.function.Consumer<org.bytedeco.javacpp.opencv_core.Mat> callback)
Adds a callback to this handler. The callback will be called when a new image is POSTed to/GRIP/upload/image
and can be removed later withremoveCallback(Consumer)
.- Parameters:
callback
- the callback to add- See Also:
removeCallback(Consumer)
-
removeCallback
public void removeCallback(@Nullable java.util.function.Consumer<org.bytedeco.javacpp.opencv_core.Mat> callback)
Removes the given callback from this handler. The callback will no longer be called when a new image is POSTed to/GRIP/upload/image
, unless it is re-added withaddCallback(Consumer)
. Does nothing ifcallback
isnull
.- Parameters:
callback
- the callback to remove- See Also:
addCallback(Consumer)
-
-