public abstract class LegacyServiceHandler
extends org.eclipse.jetty.server.handler.AbstractHandler
org.eclipse.jetty.server.handler.AbstractHandler.ErrorDispatchHandler
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
Modifier and Type | Field and Description |
---|---|
private WebAuthHandler |
authHandler
The authentication handler, if enabled in the directory, for this web service type.
|
protected java.lang.String |
basePath
The base path for the service handler.
|
private AppServerConnectionPool |
pool
The appserver connection pool of worker threads.
|
private java.util.Map<java.lang.String,java.lang.String> |
responseHeaders
Additional response headers to add.
|
private java.lang.String |
type
The service type.
|
Constructor and Description |
---|
LegacyServiceHandler(java.lang.String type,
java.lang.String basePath)
Initialize this handler with the given base path.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
authorize(java.lang.String target,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
If
authorization is enabled , perform the
authorization to check if the request configuration is allowed to
access this API. |
java.lang.String |
getBasePath()
Get the
basePath . |
private static java.io.InputStream |
getInputStream(javax.servlet.http.HttpServletRequest request)
Get the input stream to read the request's body.
|
static java.lang.String[] |
getPaths(java.lang.String path)
Get the individual path entries from this path.
|
int |
getTimeout()
Get the
AppServerConnectionPool.timeout . |
protected java.lang.String |
getType()
Get the service handler's
type . |
static void |
handle(LegacyServiceHandler instance,
java.util.function.Consumer<LegacyServiceWorker> work,
java.lang.String target,
javax.servlet.http.HttpServletResponse response)
Code to process web requests.
|
static void |
handle(LegacyServiceHandler instance,
java.lang.String connectionID,
java.util.function.Consumer<LegacyServiceWorker> work,
java.lang.String target,
javax.servlet.http.HttpServletResponse response)
Code to process web requests.
|
void |
handle(java.lang.String target,
org.eclipse.jetty.server.Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Process web requests.
|
void |
initializeHandler()
Initialize the worker(s) and start them.
|
private java.lang.String[] |
parseHeader(java.lang.String h)
Parse a header string, in the
name: value format, and return its header name and value. |
protected void |
postHandle(java.lang.String token)
Contains any post
handle(com.goldencode.p2j.main.LegacyServiceHandler, java.util.function.Consumer<com.goldencode.p2j.main.LegacyServiceWorker>, java.lang.String, javax.servlet.http.HttpServletResponse) code to be executed after the service request has been invoked. |
private void |
prepareResponse(javax.servlet.http.HttpServletResponse response)
Prepare the HTTP response with any custom settings or headers.
|
static byte[] |
readBody(javax.servlet.http.HttpServletRequest request)
Red the body from a HTTP request.
|
private void |
readResponseHeaders()
Read any custom response headers configured in the directory.
|
protected java.lang.String |
resolveBasePath(java.lang.String basePath)
Resolve the configured basepath for this handler.
|
void |
terminateWorkers()
Terminate the service worker threads.
|
protected boolean |
useAuthorization()
Check if the authentication and authorization is enabled for this web service type.
|
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
protected java.lang.String basePath
private final java.lang.String type
private final AppServerConnectionPool pool
private java.util.Map<java.lang.String,java.lang.String> responseHeaders
web-response-headers
directory node.private WebAuthHandler authHandler
public LegacyServiceHandler(java.lang.String type, java.lang.String basePath)
type
- The service type, also name of node to get the configuration from the directory.basePath
- The implicit basepath.public static void handle(LegacyServiceHandler instance, java.util.function.Consumer<LegacyServiceWorker> work, java.lang.String target, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
instance
- The legacy service instance.work
- The work to perform the request.target
- The target path.response
- The HTTP response.java.io.IOException
public static void handle(LegacyServiceHandler instance, java.lang.String connectionID, java.util.function.Consumer<LegacyServiceWorker> work, java.lang.String target, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
instance
- The legacy service instance.connectionID
- When not-null, force to use the worker with the specified connection ID.work
- The work to perform the request.target
- The target path.response
- The HTTP response.java.io.IOException
public static java.lang.String[] getPaths(java.lang.String path)
path
- The '/' separated path.public static byte[] readBody(javax.servlet.http.HttpServletRequest request) throws java.io.IOException
request
- The HTTP request payload.java.io.IOException
public java.lang.String getBasePath()
basePath
.public int getTimeout()
AppServerConnectionPool.timeout
.public void terminateWorkers()
public void initializeHandler()
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
authorization
is enabled, this will authenicate the
request. The authorization
will be responsible of creating the FWD context and
returning the token for this web request.handle
in interface org.eclipse.jetty.server.Handler
handle
in class org.eclipse.jetty.server.handler.AbstractHandler
target
- The target path.request
- The HTTP request.response
- The HTTP response.java.io.IOException
protected void postHandle(java.lang.String token)
handle(com.goldencode.p2j.main.LegacyServiceHandler, java.util.function.Consumer<com.goldencode.p2j.main.LegacyServiceWorker>, java.lang.String, javax.servlet.http.HttpServletResponse)
code to be executed after the service request has been invoked.token
- When set, the web service token used to authenticate and authorize this request.protected boolean useAuthorization()
true
if authHandler
exists.protected java.lang.String authorize(java.lang.String target, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
authorization is enabled
, perform the
authorization
to check if the request configuration is allowed to
access this API.target
- The target path.request
- The HTTP request.response
- The HTTP response.protected java.lang.String resolveBasePath(java.lang.String basePath)
basePath
- The default base path.protected java.lang.String getType()
type
.private void readResponseHeaders()
web-response-headers/default
, and after that overwriting/merging the ones from
web-response-headers/type
.private java.lang.String[] parseHeader(java.lang.String h)
name: value
format, and return its header name and value.h
- The string to parse.private void prepareResponse(javax.servlet.http.HttpServletResponse response)
response
- The HTTP response.private static java.io.InputStream getInputStream(javax.servlet.http.HttpServletRequest request) throws java.io.IOException
Depending on the 'Content-Encoding', a different stream will read it.
request
- The HTTP request.java.io.IOException