public class RestHandler extends LegacyWebServiceHandler
Service registration is being performed via SourceNameMapper
, which loads the
programs marked with with-services
, via addService(com.goldencode.p2j.util.LegacyService, java.lang.Class<? extends com.goldencode.p2j.oo.lang._BaseObject_>, com.goldencode.p2j.util.LegacyService, java.lang.reflect.Method)
API.
Any converted Java code mapped to a service must have a class-level LegacyService
annotation. If this has operations defined via internal entries (procedure, function, method),
then each Java method must be annotated via LegacyService
.
The implicit basepath is /rest
, and the implicit timeout is 10 seconds (set to 0
to disable it). This timeout is read from the appserver's timeout.
The values which need to be configured in the directory are:
rest/basepath
, to specify the basepath. Defaults to /rest
.rest/alias
, a process certificate alias associated with the workers which
will process the REST requests; these will delegate the call to the appserver. This
context will automatically be set as HEADLESS.rest/keyStore
, the key store with the certificate to authenticate this
process. If is missing, the store will be built from the directory.rest/storePassword
, the store password, only if rest/keyStore
is set.rest/poolSize
- the pool size of workers. Defaults to 10.rest/appserver
- the name of the appserver handling the requests.Each queue of REST workers is ordered by the number of pending tasks to be executed - for each incoming request, the worker with the smallest number of pending tasks will be chosen.
org.eclipse.jetty.server.handler.AbstractHandler.ErrorDispatchHandler
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
Modifier and Type | Field and Description |
---|---|
private java.util.Set<java.lang.String> |
addresses
The already registered addresses.
|
private static org.eclipse.jetty.server.handler.ContextHandlerCollection |
handler
The context handler.
|
private static RestHandler |
instance
The singleton instance for this handler.
|
private static java.util.logging.Logger |
LOG
Anonymous log instance.
|
private static java.util.Map<java.lang.String,java.util.function.Supplier<? extends RequestArguments>> |
requests
A mapping of mime-types to their request resolvers.
|
private static java.util.Map<java.lang.String,java.util.function.Supplier<? extends ResponseArguments>> |
responses
A mapping of mime-types to their response serializers.
|
DELETE, EXTERNAL, JAVA, PERSISTENT, services, SINGLE_RUN, SINGLETON
basePath
Constructor and Description |
---|
RestHandler()
Initialize this handler with the 'rest' type and '/rest' default basepath.
|
Modifier and Type | Method and Description |
---|---|
static void |
addJavaService(LegacyService ls,
java.lang.Class<?> cls,
LegacyService mls,
java.lang.reflect.Method m)
Register a service which is defined in Java, and does not adhere to the constraints of a legacy program.
|
static void |
addService(LegacyService ls,
java.lang.Class<? extends _BaseObject_> cls,
LegacyService mls,
java.lang.reflect.Method m)
Register a legacy service associated with a legacy OO class method.
|
static void |
addService(LegacyService ls,
java.lang.String pname,
LegacyService iels,
InternalEntry ie,
boolean function)
Register a legacy service associated with an internal entry for an external program.
|
static void |
addService(LegacyService ls,
java.lang.String pname,
java.lang.reflect.Method m)
Register a legacy service associated with a legacy external program.
|
private LegacyServiceParameter |
buildJavaParameter(LegacyServiceParameter orig,
java.lang.reflect.Type type,
java.lang.String name)
Build the REST service parameter associated with a Java-style defined service.
|
protected ServiceKey |
buildServiceKey(LegacyService ls)
Build a
RestServiceKey for the specified legacy service. |
(package private) static java.lang.String |
extractVal(java.lang.String src)
From a structure like
a.attr['a'] , extract the bracketed value and remove the
quotes. |
void |
handle(java.lang.String target,
org.eclipse.jetty.server.Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Code to process web requests.
|
static org.eclipse.jetty.server.handler.AbstractHandler |
initialize()
Initialize the REST worker(s) and start the workers.
|
private static void |
invoke(RestService rest,
java.lang.String token,
LegacyServiceWorker worker,
java.lang.String target,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Execute the REST request.
|
private void |
registerJavaService(LegacyService ls,
java.lang.Class<?> cls,
LegacyService mls,
java.lang.reflect.Method m)
Register a service which is defined in Java, and does not adhere to the constraints of a legacy program.
|
static void |
terminate()
Terminate the rest worker threads.
|
static boolean |
useWebServiceAuthentication()
Determine if this web service is configured to authenticate the APIs.
|
registerService, registerService, registerService
authorize, getBasePath, getPaths, getTimeout, getType, handle, handle, initializeHandler, postHandle, readBody, resolveBasePath, terminateWorkers, useAuthorization
destroy, doError, doStart, doStop, getServer, setServer
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
private static RestHandler instance
private static final java.util.logging.Logger LOG
private static java.util.Map<java.lang.String,java.util.function.Supplier<? extends RequestArguments>> requests
private static java.util.Map<java.lang.String,java.util.function.Supplier<? extends ResponseArguments>> responses
private static org.eclipse.jetty.server.handler.ContextHandlerCollection handler
private java.util.Set<java.lang.String> addresses
public RestHandler()
public static boolean useWebServiceAuthentication()
true
if the authentication is enabled for this web service, in the directory.public static void terminate()
public static org.eclipse.jetty.server.handler.AbstractHandler initialize()
public static void addJavaService(LegacyService ls, java.lang.Class<?> cls, LegacyService mls, java.lang.reflect.Method m)
ls
- The annotation describing the service, at the defining class.cls
- The Java class defining this service.mls
- The annotation describing the service, at the Java method.m
- The target Java method.public static void addService(LegacyService ls, java.lang.Class<? extends _BaseObject_> cls, LegacyService mls, java.lang.reflect.Method m)
ls
- The annotation describing the service, at the legacy class.cls
- The BaseObject
sub-class implementing this
service.mls
- The annotation describing the service, at the legacy method.m
- The target operation.public static void addService(LegacyService ls, java.lang.String pname, java.lang.reflect.Method m)
ls
- The annotation describing the service.pname
- The legacy program name.m
- The target Java method for this service.public static void addService(LegacyService ls, java.lang.String pname, LegacyService iels, InternalEntry ie, boolean function)
ls
- The annotation describing the service, at the external program.pname
- The legacy program name.iels
- The annotation describing the service, at the internal entry.ie
- The target internal entry for this service.function
- Flag identifying if the internal entry is a function.static java.lang.String extractVal(java.lang.String src)
a.attr['a']
, extract the bracketed value and remove the
quotes.src
- The source text.private static void invoke(RestService rest, java.lang.String token, LegacyServiceWorker worker, java.lang.String target, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
rest
- The REST service instance.token
- When not null, it represents the token of a FWD context created for an authenticated and
authorized web service call. The API call will be performed in that context.worker
- The REST worker.target
- The target path.request
- The HTTP servlet request instance.response
- The HTTP servlet response instance.java.io.IOException
public void handle(java.lang.String target, org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
handle
in interface org.eclipse.jetty.server.Handler
handle
in class LegacyServiceHandler
target
- The target path.request
- The HTTP request.response
- The HTTP response.java.io.IOException
protected ServiceKey buildServiceKey(LegacyService ls)
RestServiceKey
for the specified legacy service.buildServiceKey
in class LegacyWebServiceHandler
ls
- The legacy service annotation.private void registerJavaService(LegacyService ls, java.lang.Class<?> cls, LegacyService mls, java.lang.reflect.Method m)
ls
- The annotation describing the service, at the defining class.cls
- The Java class defining this service.mls
- The annotation describing the service, at the Java method.m
- The target Java method.private LegacyServiceParameter buildJavaParameter(LegacyServiceParameter orig, java.lang.reflect.Type type, java.lang.String name)
orig
- The original signature.type
- The parameter's type, as defined at the Java method.name
- The parameter's name, as defined at the Java method.