java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
net.i2p.i2pcontrol.servlets.JSONRPC2Servlet
- All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Provide an JSON-RPC 2.0 API for remote controlling of I2P
- See Also:
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConfigurationManagerConfiguration manager.private final RouterContextRouter context.private final JSONRPC2HelperJSON-RPC 2.0 helper.private booleanWhether HTTP is available.private booleanWhether HTTPS is available.private final booleanWhether running as a webapp.private LogClass logger.private final SecurityManagerSecurity manager.private static final intBytes read at a time from the request.private DispatcherJSON-RPC 2.0 request dispatcher.private static final longPinned for serialized-form compatibility.private static final StringService name checked for HTTP access.private static final StringService name checked for HTTPS access.Constructor Summary
ConstructorsConstructorDescriptionWebapp form: requires a router context and builds its own config and security managers.JSONRPC2Servlet(RouterContext ctx, SecurityManager secMan) Plugin form: takes the host application's context and security manager, and creates no config file.Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Clean up port mappings and stop timed events.protected voiddoGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) Serve the I2PControl status page.private voiddoPasswordChange(HttpServletRequest req, HttpServletResponse httpServletResponse) Handle API password change form submission.protected voiddoPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) Handle JSON-RPC 2.0 requests and password changes.private StringReads the whole request body as text.voidinit()Register JSON-RPC 2.0 request handlers.private static voidHTTP security headers.Methods inherited from class HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, serviceMethods inherited from class GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
Field Details
serialVersionUID
private static final long serialVersionUIDPinned for serialized-form compatibility.- See Also:
BUFFER_LENGTH
private static final int BUFFER_LENGTHBytes read at a time from the request.- See Also:
SVC_HTTP_I2PCONTROL
Service name checked for HTTP access.- See Also:
SVC_HTTPS_I2PCONTROL
Service name checked for HTTPS access.- See Also:
disp
JSON-RPC 2.0 request dispatcher._log
Class logger._secMan
Security manager._conf
Configuration manager._helper
JSON-RPC 2.0 helper._context
Router context._isWebapp
private final boolean _isWebappWhether running as a webapp._isHTTP
private boolean _isHTTPWhether HTTP is available._isHTTPS
private boolean _isHTTPSWhether HTTPS is available.
Constructor Details
JSONRPC2Servlet
public JSONRPC2Servlet()Webapp form: requires a router context and builds its own config and security managers.JSONRPC2Servlet
Plugin form: takes the host application's context and security manager, and creates no config file.- Parameters:
ctx- the router context, may be null when there is none availablesecMan- the security manager backing the authentication handler
Method Details
init
Register JSON-RPC 2.0 request handlers.- Overrides:
initin classGenericServlet- Throws:
ServletException
destroy
public void destroy()Clean up port mappings and stop timed events.- Specified by:
destroyin interfaceServlet- Overrides:
destroyin classGenericServlet
doGet
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException Serve the I2PControl status page.- Overrides:
doGetin classHttpServlet- Throws:
ServletExceptionIOException
setHeaders
HTTP security headers.- Parameters:
resp- the response to add the security headers to
doPasswordChange
private void doPasswordChange(HttpServletRequest req, HttpServletResponse httpServletResponse) throws ServletException, IOException Handle API password change form submission.- Parameters:
req- the form submission carrying the password, password2 and password3 fieldshttpServletResponse- the response the result page is written to- Throws:
IOException- if the response writer cannot be obtainedServletException- declared for the servlet API, never thrown here
doPost
protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException Handle JSON-RPC 2.0 requests and password changes.- Overrides:
doPostin classHttpServlet- Throws:
ServletExceptionIOException
getRequest
Reads the whole request body as text.- Parameters:
sis- the stream to read from- Returns:
- the request body
- Throws:
IOException- if the stream cannot be read