Package de.gsi.acc.remote
Class RestServer
- java.lang.Object
-
- de.gsi.acc.remote.RestServer
-
public final class RestServer extends java.lang.ObjectSmall RESTful server helper class.The Javalin framework is being used internally: https://javalin.io/ The primary purposes of this utility class is to provide
- some convenience methods, default configuration (in particular relating to SSL and HTTP/2), and
- to wrap the primary REST server implementation in view of back-end server upgrades or changing API.
- to provide every GET route also with an long-polling and SSE listener/data-retrieval management.
Server parameter can be controlled via the following system properties:
- restServerHostName: host name or IP address the server should bind to
- restServerPort: the HTTP port
- restServerPort2: the HTTP/2 port (encrypted)
- restKeyStore: the path to the file containing the key store for the encryption
- restKeyStorePassword: the path to the file containing the key store for the encryption
- restUserPasswordStore: the path to the file containing the user passwords and roles encryption
- Author:
- rstein
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringTAG_REST_SERVER_HOST_NAMEstatic java.lang.StringTAG_REST_SERVER_PORTstatic java.lang.StringTAG_REST_SERVER_PORT2
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddLongPollingCookie(io.javalin.http.Context ctx, java.lang.String key, long lastUpdateMillies)static voidapplyRateLimit(io.javalin.http.Context ctx, int numRequests, java.util.concurrent.TimeUnit timeUnit)guards this end point and returns HTTP error response if predefined rate limit is exceededstatic de.gsi.dataset.remote.MimeTypegetDefaultProtocol()static java.util.Set<io.javalin.core.security.Role>getDefaultRole()static javafx.collections.ObservableList<io.javalin.core.event.HandlerMetaInfo>getEndpoints()static java.util.Queue<io.javalin.http.sse.SseClient>getEventClients(java.lang.String endpointName)static java.lang.StringgetHostName()static intgetHostPort()static intgetHostPort2()static io.javalin.JavalingetInstance()static java.net.URIgetLocalURI()static java.net.URIgetPublicURI()static de.gsi.dataset.remote.MimeTypegetRequestedMimeProtocol(io.javalin.http.Context ctx, de.gsi.dataset.remote.MimeType... defaultProtocol)static java.lang.StringgetRequestedProtocol(io.javalin.http.Context ctx, java.lang.String... defaultProtocol)static java.util.Set<io.javalin.core.security.Role>getSessionCurrentRoles(io.javalin.http.Context ctx)static java.lang.StringgetSessionCurrentUser(io.javalin.http.Context ctx)static java.lang.StringgetSessionLocale(io.javalin.http.Context ctx)static RestUserHandlergetUserHandler()static java.lang.StringprefixPath(java.lang.String path)static voidsetDefaultProtocol(de.gsi.dataset.remote.MimeType defaultProtocol)static voidsetUserHandler(RestUserHandler newUserHandler)Sets a new user handler.static voidstartRestServer()static voidstartRestServer(int hostPort, int hostPort2)static voidstartRestServer(java.lang.String hostName, int hostPort, int hostPort2)static voidstopRestServer()static voidsuppressCaching(io.javalin.http.Context ctx)Suppresses caching for this end pointstatic voidwriteBytesToContext(io.javalin.http.Context ctx, byte[] bytes, int nSize)
-
-
-
Field Detail
-
TAG_REST_SERVER_HOST_NAME
public static final java.lang.String TAG_REST_SERVER_HOST_NAME
- See Also:
- Constant Field Values
-
TAG_REST_SERVER_PORT
public static final java.lang.String TAG_REST_SERVER_PORT
- See Also:
- Constant Field Values
-
TAG_REST_SERVER_PORT2
public static final java.lang.String TAG_REST_SERVER_PORT2
- See Also:
- Constant Field Values
-
-
Method Detail
-
addLongPollingCookie
public static void addLongPollingCookie(io.javalin.http.Context ctx, java.lang.String key, long lastUpdateMillies)
-
applyRateLimit
public static void applyRateLimit(io.javalin.http.Context ctx, int numRequests, java.util.concurrent.TimeUnit timeUnit)guards this end point and returns HTTP error response if predefined rate limit is exceeded- Parameters:
ctx- end point context handlernumRequests- number of callstimeUnit- time base reference
-
getDefaultRole
public static java.util.Set<io.javalin.core.security.Role> getDefaultRole()
-
getEndpoints
public static javafx.collections.ObservableList<io.javalin.core.event.HandlerMetaInfo> getEndpoints()
-
getEventClients
public static java.util.Queue<io.javalin.http.sse.SseClient> getEventClients(@NotNull java.lang.String endpointName)
-
getHostName
public static java.lang.String getHostName()
-
getHostPort
public static int getHostPort()
-
getHostPort2
public static int getHostPort2()
-
getInstance
public static io.javalin.Javalin getInstance()
-
getRequestedProtocol
public static java.lang.String getRequestedProtocol(io.javalin.http.Context ctx, java.lang.String... defaultProtocol)
-
getRequestedMimeProtocol
public static de.gsi.dataset.remote.MimeType getRequestedMimeProtocol(io.javalin.http.Context ctx, de.gsi.dataset.remote.MimeType... defaultProtocol)
-
getLocalURI
public static java.net.URI getLocalURI()
-
getPublicURI
public static java.net.URI getPublicURI()
-
getSessionCurrentRoles
public static java.util.Set<io.javalin.core.security.Role> getSessionCurrentRoles(io.javalin.http.Context ctx)
-
getSessionCurrentUser
public static java.lang.String getSessionCurrentUser(io.javalin.http.Context ctx)
-
getSessionLocale
public static java.lang.String getSessionLocale(io.javalin.http.Context ctx)
-
getUserHandler
public static RestUserHandler getUserHandler()
-
prefixPath
public static java.lang.String prefixPath(@NotNull java.lang.String path)
-
setUserHandler
public static void setUserHandler(RestUserHandler newUserHandler)
Sets a new user handler. N.B: This will issue a warning to remind system admins or security-minded people that the default implementation may have been replaced with a better/worse/different implementation (e.g. based on LDAP or another data base)- Parameters:
newUserHandler- the new implementation
-
startRestServer
public static void startRestServer()
-
startRestServer
public static void startRestServer(int hostPort, int hostPort2)
-
startRestServer
public static void startRestServer(java.lang.String hostName, int hostPort, int hostPort2)
-
stopRestServer
public static void stopRestServer()
-
suppressCaching
public static void suppressCaching(io.javalin.http.Context ctx)
Suppresses caching for this end point- Parameters:
ctx- end point context handler
-
writeBytesToContext
public static void writeBytesToContext(@NotNull io.javalin.http.Context ctx, byte[] bytes, int nSize)
-
getDefaultProtocol
public static de.gsi.dataset.remote.MimeType getDefaultProtocol()
-
setDefaultProtocol
public static void setDefaultProtocol(de.gsi.dataset.remote.MimeType defaultProtocol)
-
-