Package jadex.publishservice.impl
Class RequestManager
java.lang.Object
jadex.publishservice.impl.RequestManager
The request manager is used to handle REST web requests.
It follows tha Jadex manager pattern, i.e. it is a singleton accessible
also from static contexts.
- Requests with jadex.js contained will be delivered the jadex.js file.
- Requests on the base url of a published service will be delivered an
overview site for the service.
The request manager has a sophisticated mapping mechanisms for request
paramaters and tries to map naturally as much as possible.
There is (nearly) a 1:1 relationship between sessions and sseinfos. Each jadex.js
uses the "jadex" cookie for session id. The cookie is path wide (from a path all subpaths)
so that multiple jadex.js and thus applications can coexist using different sessions.
Sessions do not need explicit timeouts as SSE pings are sent to the see clients.
Each client responds via a call to baseurl/ssealive path, which must be routed to
the request manager.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStruct for storing info about a request and the results.static classstatic classclassInfo struct for response.static classSSE event data class.static classStruct for storing info about a request and the results. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringURL parameter accept request.static final StringAsync context info.static final StringURL parameter type request.static longThe conversation timeout.protected Map<String, RequestManager.ConversationInfo> Info about an ongoing conversation, i.e.protected jadex.collection.MultiCollection<String, jadex.common.transformation.IObjectStringConverter> The media type converters.static final StringThe default app name.static final StringThe default hostportappcontext.static final StringThe default host name.static final intThe default port.static final StringFinished result marker.static final StringHttp header for the client side to indicate that conversation is still alive/ongoing.static final StringHttp header for the call id siganlling that this is the last response (resp).static final StringHttp header for the call id (req and resp).static final StringHttp header for the client side timeout of calls (req).static final Stringstatic final StringHttp header to login to and gain admin access (req).static final Stringstatic final StringHttp header for max value of intermediate future.static final Stringstatic final StringHttp header to terminate the call (req).static final StringHttp header for the Jadex version.protected static RequestManagerprotected jadex.serialization.serializers.JadexJsonSerializerThe json processor.protected booleanLogin security of or off.Some basic media types for service invocations.static final StringURL parameter random request.protected jadex.serialization.ISerializationServicesThe serialization services.The sessions.protected List<RequestManager.SSEEvent> SSE events that could not directly be sent.protected Map<String, RequestManager.SSEInfo> Infos about the sse sources. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddConversation(String callid, RequestManager.ConversationInfo cinfo) protected static voidstatic voidaddMimeTypes(Object cs, List<String> types) protected voidprotected voidprotected voidcomplete(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) static ObjectconvertJsonValue(String val, Class<?> type, ClassLoader cl, boolean tomap) Convert a json string to a java object.convertParameter(Object val, Class<?> target) Convert a (string) parameterprotected ObjectconvertParameter(List<String> sr, Object val, Class<?> targetclazz) Convert a parameter string to an object if is json or xml.static voidcreateInstance(jadex.serialization.ISerializationServices serser) protected RequestManager.SSEEventCreate an sse event.protected RequestManager.SSEEventcreateSSEEvent(Object result, boolean finished, String callid, Integer max, String exceptiontype) Create an sse event.protected StringCreate an sse event for a JavaSSE event.evaluateMapping(jadex.providedservice.IServiceIdentifier sid, PublishInfo pi, ClassLoader cl) Evaluate the service interface and generate mappings.extractCallerValues(Object request) Extract caller values like ip and browser.static Object[]generateInParameters(Map<String, Object> inparamsmap, jadex.common.Tuple2<List<jadex.common.Tuple2<String, String>>, Map<String, Class<?>>> pinfos, Class<?>[] types) Generate in parameters that are correct wrt order and number of targetparameter (must convert types possibly).protected IAsyncContextInfogetAsyncContextInfo(jakarta.servlet.http.HttpServletRequest request) Get the asyncprotected ClassLoaderprotected RequestManager.ConversationInfogetConversation(String callid) protected Collection<jadex.common.transformation.IObjectStringConverter> getConverters(String mediatype) Get the converters.static RequestManagergetParameterInfos(Method method) Get metainfo about parameters from the target method via annotations.getPath()Get the path to my package as pathstatic longgetRequestTimeout(jakarta.servlet.http.HttpServletRequest request) Get the request timeout.jadex.serialization.ISerializationServicesgetServiceInfo(Object service, String baseuri, PathManager<RequestManager.MappingInfo> mappings) Functionality blueprint for get service info web method.static StringgetServletHost(jakarta.servlet.http.HttpServletRequest req) Get the servlet base url.static StringgetServletUrl(jakarta.servlet.http.HttpServletRequest req) Get the servlet base url.getSession(jakarta.servlet.http.HttpServletRequest request, boolean create) Get a session.getSession(String sessionid) getSession(String sessionid, boolean create) Get a session.static StringgetSessionId(jakarta.servlet.http.HttpServletRequest request) Get a session id.jakarta.servlet.AsyncContextgetSSEContextFromSession(String sessionid) protected RequestManager.SSEInfogetSSEInfo(String sessionid) guessRestType(Method method) Guess the http type (GET, POST, PUT, DELETE, ...) of a method.voidhandleRequest(jadex.providedservice.IService service, PathManager<RequestManager.MappingInfo> pm, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object[] others) Handle a web request.protected booleanhasConversation(String callid) booleanhasStringConvertableParameters(Method method, Class<?> rettype, Class<?>[] paramtypes) Test if a method has parameters that are all convertible from string.protected booleanisComplete(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) booleanisLoggedIn(jakarta.servlet.http.HttpServletRequest request) Test if a the web user is logged in.booleanisLoggedIn(String callid) Test if a the web user is logged in.jadex.future.IFuture<byte[]> Load jadex.jsjadex.future.IFuture<Boolean> Log in to the platform.jadex.future.IFuture<Boolean> logout(jakarta.servlet.http.HttpServletRequest request) Logout from the platform.protected jadex.common.Tuple2<RequestManager.MappingInfo, Object[]> mapParameters(jakarta.servlet.http.HttpServletRequest request, Collection<RequestManager.MappingInfo> mis, List<Map<String, String>> bindings) Map the incoming uri/post/multipart parameters to the service target parameter types.protected ObjectMap a result using the result mapper.parseMimetypes(String mts) todo: make statically accessible Copied from Jadex ForwardFilterprotected voidPrune the timeouted conversations.voidputSession(String sessionid, Map<String, Object> session) voidputSSEContextInSession(String sessionid, jakarta.servlet.AsyncContext context) voidremoveSession(String sessionid) protected voidremoveSSEInfo(String sessionid) protected voidsendDelayedSSEEvents(Map<String, Object> session) Send the delayed events which have been collected during connection loss.protected voidsetCORSHeader(jakarta.servlet.http.HttpServletResponse response) Set the cors header in the response.voidsetInSession(String sessionid, String name, Object value) jadex.future.IFuture<Void> setLoginSecurity(boolean sec) Turn on or off the login security.protected voidsetNoCachingHeader(jakarta.servlet.http.HttpServletResponse response) Set the cache header in the response.splitQueryString(String query) Split the query and save the order.protected voidterminateConversation(RequestManager.ConversationInfo cinfo, Exception ex, boolean clientterm) protected voidupdateTimestamps(String sessionid) Update timestamps of all conversations that belong to a session / sse source.protected voidWrite the response (header and content).protected voidWrite the response content.
-
Field Details
-
DEFAULT_HOST
The default host name.- See Also:
-
DEFAULT_PORT
public static final int DEFAULT_PORTThe default port.- See Also:
-
DEFAULT_APP
The default app name.- See Also:
-
DEFAULT_COMPLETECONTEXT
The default hostportappcontext.- See Also:
-
CONVERSATION_TIMEOUT
public static long CONVERSATION_TIMEOUTThe conversation timeout. -
ASYNC_CONTEXT_INFO
Async context info.- See Also:
-
HEADER_JADEX_VERSION
Http header for the Jadex version.- See Also:
-
HEADER_JADEX_CALLID
Http header for the call id (req and resp).- See Also:
-
HEADER_JADEX_CALLFINISHED
Http header for the call id siganlling that this is the last response (resp).- See Also:
-
HEADER_JADEX_MAX
Http header for max value of intermediate future.- See Also:
-
HEADER_JADEX_CLIENTTIMEOUT
Http header for the client side timeout of calls (req).- See Also:
-
HEADER_JADEX_ALIVE
Http header for the client side to indicate that conversation is still alive/ongoing.- See Also:
-
HEADER_JADEX_SSEALIVE
- See Also:
-
HEADER_JADEX_TERMINATE
Http header to terminate the call (req).- See Also:
-
HEADER_JADEX_LOGIN
Http header to login to and gain admin access (req).- See Also:
-
HEADER_JADEX_LOGOUT
- See Also:
-
HEADER_JADEX_ISLOGGEDIN
- See Also:
-
FINISHED
Finished result marker.- See Also:
-
RANDOM
URL parameter random request.- See Also:
-
CONTENTTYPE
URL parameter type request.- See Also:
-
ACCEPT
URL parameter accept request.- See Also:
-
PARAMETER_MEDIATYPES
Some basic media types for service invocations. -
conversationinfos
Info about an ongoing conversation, i.e. Jadex future, session etc. -
sseevents
SSE events that could not directly be sent. -
sessions
The sessions. Cannot use built-in due to problem with concurrent inital requests (and also after platform restart). Two requests (sse, subscribeX) arrive at server with the same jsessionid -> session not known, server creates a new one for both with different ids. https://community.oracle.com/tech/developers/discussion/1455774/multiple-sessions-created. -
sseinfos
Infos about the sse sources. -
converters
protected jadex.collection.MultiCollection<String,jadex.common.transformation.IObjectStringConverter> convertersThe media type converters. -
loginsec
protected boolean loginsecLogin security of or off. -
jsonser
protected jadex.serialization.serializers.JadexJsonSerializer jsonserThe json processor. -
serser
protected jadex.serialization.ISerializationServices serserThe serialization services. -
instance
-
-
Constructor Details
-
RequestManager
public RequestManager(jadex.serialization.ISerializationServices serser)
-
-
Method Details
-
createInstance
public static void createInstance(jadex.serialization.ISerializationServices serser) -
getInstance
-
getSerializationServices
public jadex.serialization.ISerializationServices getSerializationServices() -
getConverters
protected Collection<jadex.common.transformation.IObjectStringConverter> getConverters(String mediatype) Get the converters. Needs not to be synchronized as long as only gets are performed. -
setLoginSecurity
Turn on or off the login security. If true one has to log in with platform secret before using published services.- Parameters:
sec- On or off.
-
getSession
public Map<String,Object> getSession(jakarta.servlet.http.HttpServletRequest request, boolean create) Get a session.- Parameters:
request- The requestcreate- Flag if shall be created.- Returns:
- The session.
-
getSession
Get a session.- Parameters:
create- Flag if shall be created.request- The request- Returns:
- The session.
-
getSSEContextFromSession
-
putSSEContextInSession
-
setInSession
-
getSession
-
putSession
-
removeSession
-
getSessionId
Get a session id.- Parameters:
request- The request- Returns:
- The session id.
-
handleRequest
public void handleRequest(jadex.providedservice.IService service, PathManager<RequestManager.MappingInfo> pm, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object[] others) throws IOException, jakarta.servlet.ServletException Handle a web request.- Parameters:
service- The service.request- The request.response- The response.mappings- The collected mapping infos for the service.- Throws:
IOExceptionjakarta.servlet.ServletException
-
pruneObsoleteConversations
protected void pruneObsoleteConversations()Prune the timeouted conversations. -
updateTimestamps
Update timestamps of all conversations that belong to a session / sse source.- Parameters:
sessionid- The session id.
-
terminateConversation
protected void terminateConversation(RequestManager.ConversationInfo cinfo, Exception ex, boolean clientterm) - Parameters:
cinfo-ex-
-
getConversation
-
addConversation
-
hasConversation
-
getSSEInfo
-
addSSEInfo
-
removeSSEInfo
-
setCORSHeader
protected void setCORSHeader(jakarta.servlet.http.HttpServletResponse response) Set the cors header in the response.- Parameters:
response- The response.
-
setNoCachingHeader
protected void setNoCachingHeader(jakarta.servlet.http.HttpServletResponse response) Set the cache header in the response.- Parameters:
response- The response.
-
sendDelayedSSEEvents
Send the delayed events which have been collected during connection loss. Must check if callid belongs to still ongoing call (could be terminated). -
addSSEEvent
-
logout
Logout from the platform.- Parameters:
secret- The platform secret.- Returns:
- True, if login was successful.
-
isLoggedIn
public boolean isLoggedIn(jakarta.servlet.http.HttpServletRequest request) Test if a the web user is logged in.- Parameters:
request- The web request.- Returns:
- True, if is logged in.
-
isLoggedIn
Test if a the web user is logged in.- Parameters:
callid- The callid of the request.- Returns:
- True, if is logged in.
-
getAsyncContextInfo
Get the async -
addMimeTypes
-
mapParameters
protected jadex.common.Tuple2<RequestManager.MappingInfo,Object[]> mapParameters(jakarta.servlet.http.HttpServletRequest request, Collection<RequestManager.MappingInfo> mis, List<Map<String, String>> bindings) Map the incoming uri/post/multipart parameters to the service target parameter types. -
generateInParameters
public static Object[] generateInParameters(Map<String, Object> inparamsmap, jadex.common.Tuple2<List<jadex.common.Tuple2<String, String>>, Map<String, Class<?>>> pinfos, Class<?>[] types) Generate in parameters that are correct wrt order and number of targetparameter (must convert types possibly). -
convertJsonValue
Convert a json string to a java object.- Parameters:
val- The json string.type- The target class.cl- The classloader.tomap- Flag, if a (nested) map should be read (only possible if type is map too).
-
convertParameter
Convert a (string) parameter- Parameters:
val-target-- Returns:
-
convertParameter
Convert a parameter string to an object if is json or xml.- Parameters:
sr- The media types.val- The string value.- Returns:
- The decoded object.
-
mapResult
Map a result using the result mapper. -
writeResponse
Write the response (header and content). -
writeResponseHeader
-
writeResponseContent
Write the response content. -
createSSEEvent
Create an sse event.- Parameters:
result-finished-callid-max-- Returns:
-
createSSEEvent
protected RequestManager.SSEEvent createSSEEvent(Object result, boolean finished, String callid, Integer max, String exceptiontype) Create an sse event. -
createSSEJson
Create an sse event for a JavaSSE event. -
getRequestTimeout
public static long getRequestTimeout(jakarta.servlet.http.HttpServletRequest request) Get the request timeout. -
parseMimetypes
todo: make statically accessible Copied from Jadex ForwardFilter -
getParameterInfos
public jadex.common.Tuple2<List<jadex.common.Tuple2<String,String>>, getParameterInfosMap<String, Class<?>>> (Method method) Get metainfo about parameters from the target method via annotations. -
extractCallerValues
Extract caller values like ip and browser.- Parameters:
request- The requrest.vals- The values.
-
getClassLoader
-
getServletUrl
Get the servlet base url.- Parameters:
req- The request.- Returns:
- The servlet base url.
-
getServletHost
Get the servlet base url.- Parameters:
req- The request.- Returns:
- The servlet base url.
-
getServiceInfo
public String getServiceInfo(Object service, String baseuri, PathManager<RequestManager.MappingInfo> mappings) Functionality blueprint for get service info web method. Creates a html page with css for style and javascript for ajax post requests. The service info site contains a section for each published method.- Parameters:
params- The parameters.- Returns:
- The result.
-
loadFunctionJS
-
loadStyleCSS
-
guessRestType
Guess the http type (GET, POST, PUT, DELETE, ...) of a method.- Parameters:
method- The method.- Returns:
- The rs annotation of the method type to use
-
hasStringConvertableParameters
public boolean hasStringConvertableParameters(Method method, Class<?> rettype, Class<?>[] paramtypes) Test if a method has parameters that are all convertible from string.- Parameters:
method- The method.rettype- The return types (possibly unwrapped from future type).paramtypes- The parameter types.- Returns:
- True, if is convertible.
-
complete
protected void complete(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) - Parameters:
request-cinfo-
-
isComplete
protected boolean isComplete(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) - Parameters:
request-cinfo-
-
loadJadexJS
public jadex.future.IFuture<byte[]> loadJadexJS()Load jadex.js- Returns:
- The text from the file.
-
getPath
Get the path to my package as path- Returns:
- The path.
-
splitQueryString
Split the query and save the order.- Throws:
Exception
-
addEntry
- Parameters:
ret-key-val-
-
login
public jadex.future.IFuture<Boolean> login(jakarta.servlet.http.HttpServletRequest request, String secret) Log in to the platform.- Parameters:
request- The request.secret- The platform secret.- Returns:
- True, if login was successful.
-
evaluateMapping
public PathManager<RequestManager.MappingInfo> evaluateMapping(jadex.providedservice.IServiceIdentifier sid, PublishInfo pi, ClassLoader cl) Evaluate the service interface and generate mappings. Return a multicollection in which for each path name the possible methods are contained (can be more than one due to different parameters).
-