Package com.gears42.iot.webthing
Class WebThingServer.BaseHandler
- java.lang.Object
-
- com.gears42.iot.webthing.WebThingServer.BaseHandler
-
- All Implemented Interfaces:
fi.iki.elonen.router.RouterNanoHTTPD.UriResponder
- Direct Known Subclasses:
WebThingServer.ActionHandler,WebThingServer.ActionIDHandler,WebThingServer.ActionsHandler,WebThingServer.ComplianceEventHandler,WebThingServer.ComplianceHandler,WebThingServer.EventHandler,WebThingServer.EventsHandler,WebThingServer.LoginHandler,WebThingServer.MDMAttributesHandler,WebThingServer.PropertiesHandler,WebThingServer.PropertyHandler,WebThingServer.ThingHandler,WebThingServer.ThingsHandler
- Enclosing class:
- WebThingServer
public static class WebThingServer.BaseHandler extends java.lang.Object implements fi.iki.elonen.router.RouterNanoHTTPD.UriResponderBase handler that responds to every request with a 405 Method Not Allowed.
-
-
Constructor Summary
Constructors Constructor Description BaseHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static fi.iki.elonen.NanoHTTPD.ResponsecorsResponse(fi.iki.elonen.NanoHTTPD.Response response)Add necessary CORS headers to response.fi.iki.elonen.NanoHTTPD.Responsedelete(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle a DELETE request.fi.iki.elonen.NanoHTTPD.Responseget(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle a GET request.ThinggetThing(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Get the thing this request is for.java.lang.StringgetUriParam(java.lang.String uri, int index)Get a parameter from the URI.booleanisValidToken(fi.iki.elonen.NanoHTTPD.IHTTPSession session)fi.iki.elonen.NanoHTTPD.Responseother(java.lang.String method, fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle any other request.org.json.JSONObjectparseBody(fi.iki.elonen.NanoHTTPD.IHTTPSession session)Parse a JSON body.org.json.JSONArrayparseBodyArray(fi.iki.elonen.NanoHTTPD.IHTTPSession session)fi.iki.elonen.NanoHTTPD.Responsepost(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle a POST request.fi.iki.elonen.NanoHTTPD.Responseput(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle a PUT request.booleanvalidateHost(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Validate Host header.
-
-
-
Method Detail
-
corsResponse
public static fi.iki.elonen.NanoHTTPD.Response corsResponse(fi.iki.elonen.NanoHTTPD.Response response)
Add necessary CORS headers to response.- Parameters:
response- Response to add headers to- Returns:
- The Response object.
-
get
public fi.iki.elonen.NanoHTTPD.Response get(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle a GET request.- Specified by:
getin interfacefi.iki.elonen.router.RouterNanoHTTPD.UriResponder- Parameters:
uriResource- The URI resource that was matchedurlParams- Map of URL parameterssession- The HTTP session- Returns:
- 405 Method Not Allowed response.
-
put
public fi.iki.elonen.NanoHTTPD.Response put(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle a PUT request.- Specified by:
putin interfacefi.iki.elonen.router.RouterNanoHTTPD.UriResponder- Parameters:
uriResource- The URI resource that was matchedurlParams- Map of URL parameterssession- The HTTP session- Returns:
- 405 Method Not Allowed response.
-
post
public fi.iki.elonen.NanoHTTPD.Response post(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle a POST request.- Specified by:
postin interfacefi.iki.elonen.router.RouterNanoHTTPD.UriResponder- Parameters:
uriResource- The URI resource that was matchedurlParams- Map of URL parameterssession- The HTTP session- Returns:
- 405 Method Not Allowed response.
-
delete
public fi.iki.elonen.NanoHTTPD.Response delete(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle a DELETE request.- Specified by:
deletein interfacefi.iki.elonen.router.RouterNanoHTTPD.UriResponder- Parameters:
uriResource- The URI resource that was matchedurlParams- Map of URL parameterssession- The HTTP session- Returns:
- 405 Method Not Allowed response.
-
other
public fi.iki.elonen.NanoHTTPD.Response other(java.lang.String method, fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, java.util.Map<java.lang.String,java.lang.String> urlParams, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Handle any other request.- Specified by:
otherin interfacefi.iki.elonen.router.RouterNanoHTTPD.UriResponder- Parameters:
method- The HTTP methoduriResource- The URI resource that was matchedurlParams- Map of URL parameterssession- The HTTP session- Returns:
- 405 Method Not Allowed response.
-
getUriParam
public java.lang.String getUriParam(java.lang.String uri, int index)Get a parameter from the URI.- Parameters:
uri- The URIindex- Index of the parameter- Returns:
- The URI parameter, or null if index was invalid.
-
parseBody
public org.json.JSONObject parseBody(fi.iki.elonen.NanoHTTPD.IHTTPSession session)
Parse a JSON body.- Parameters:
session- The HTTP session- Returns:
- The parsed JSON body as a JSONObject, or null on error.
-
parseBodyArray
public org.json.JSONArray parseBodyArray(fi.iki.elonen.NanoHTTPD.IHTTPSession session)
-
getThing
public Thing getThing(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, fi.iki.elonen.NanoHTTPD.IHTTPSession session)
Get the thing this request is for.- Parameters:
uriResource- The URI resource that was matchedsession- The HTTP session- Returns:
- The thing, or null if not found.
-
validateHost
public boolean validateHost(fi.iki.elonen.router.RouterNanoHTTPD.UriResource uriResource, fi.iki.elonen.NanoHTTPD.IHTTPSession session)Validate Host header.- Parameters:
uriResource- The URI resource that was matchedsession- The HTTP session- Returns:
- Boolean indicating validation success.
-
isValidToken
public boolean isValidToken(fi.iki.elonen.NanoHTTPD.IHTTPSession session)
-
-