Package jadex.extension.rs.publish
Class AbstractRestPublishService
- java.lang.Object
- 
- jadex.extension.rs.publish.AbstractRestPublishService
 
- 
- All Implemented Interfaces:
- IPublishService,- IWebPublishService
 - Direct Known Subclasses:
- ExternalRestPublishService,- GrizzlyRestPublishService,- JettyRestPublishService
 
 public abstract class AbstractRestPublishService extends java.lang.Object implements IWebPublishService Publish service without Jersey directly using different containers (in concrete impls).
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classAbstractRestPublishService.MappingInfostatic classAbstractRestPublishService.RequestInfoStruct for storing info about a request and the results.
 - 
Field SummaryFields Modifier and Type Field Description static java.lang.StringASYNC_CONTEXT_INFOAsync context info.protected IInternalAccesscomponentThe component.protected MultiCollection<java.lang.String,IObjectStringConverter>convertersThe media type converters.static java.lang.StringFINISHEDFinished result marker.static java.lang.StringHEADER_JADEX_CALLFINISHEDHttp header for the call id siganlling that this is the last response (resp).static java.lang.StringHEADER_JADEX_CALLIDHttp header for the call id (req and resp).static java.lang.StringHEADER_JADEX_CLIENTTIMEOUTHttp header for the client side timeout of calls (req).static java.lang.StringHEADER_JADEX_TERMINATEHttp header to terminate the call (req).static java.util.List<java.lang.String>PARAMETER_MEDIATYPESSome basic media types for service invocations.protected java.util.Map<java.lang.String,AbstractRestPublishService.RequestInfo>requestinfosThe internal request info containing also results per call (coming from the called Jadex service).protected MultiCollection<java.lang.String,javax.servlet.AsyncContext>requestspercallThe requests per call (coming from the rest client).- 
Fields inherited from interface jadex.bridge.service.types.publish.IPublishServiceDEFAULT_RSPUBLISH_COMPONENTS, PUBLISH_RS, PUBLISH_WS
 
- 
 - 
Constructor SummaryConstructors Constructor Description AbstractRestPublishService()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddConverter(java.lang.String[] mediatypes, IObjectStringConverter converter)Add a converter for one or multiple types.protected static voidaddEntry(java.util.Map<java.lang.String,java.lang.Object> ret, java.lang.String key, java.lang.Object val)protected voidcomplete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)static java.lang.ObjectconvertJsonValue(java.lang.String val, java.lang.Class<?> type, java.lang.ClassLoader cl, boolean tomap)Convert a json string to a java object.java.lang.ObjectconvertParameter(java.lang.Object val, java.lang.Class<?> target)Convert a (string) parameterprotected java.lang.ObjectconvertParameter(java.util.List<java.lang.String> sr, java.lang.String val, java.lang.Class<?> targetclazz)Convert a parameter string to an object if is json or xml.IFuture<PathManager<AbstractRestPublishService.MappingInfo>>evaluateMapping(IServiceIdentifier sid, PublishInfo pi)Evaluate the service interface and generate mappings.java.util.Map<java.lang.String,java.lang.String>extractCallerValues(java.lang.Object request)Extract caller values like ip and browser.protected javax.servlet.AsyncContextgetAsyncContext(javax.servlet.http.HttpServletRequest request)Get the asyncjava.lang.StringgetCleanPublishId(java.lang.String id)Get the cleaned publish id.abstract java.lang.ObjectgetHttpServer(java.net.URI uri, PublishInfo info)Get or start an api to the http server.Tuple2<java.util.List<Tuple2<java.lang.String,java.lang.String>>,java.util.Map<java.lang.String,java.lang.Class<?>>>getParameterInfos(java.lang.reflect.Method method)static longgetRequestTimeout(javax.servlet.http.HttpServletRequest request)Get the request timeout.java.lang.StringgetServiceInfo(java.lang.Object service, java.lang.String baseuri, PathManager<AbstractRestPublishService.MappingInfo> mappings)Functionality blueprint for get service info web method.static java.lang.StringgetServletHost(javax.servlet.http.HttpServletRequest req)Get the servlet base url.static java.lang.StringgetServletUrl(javax.servlet.http.HttpServletRequest req)Get the servlet base url.AbstractRestPublishService.MappingInfo.HttpMethodguessRestType(java.lang.reflect.Method method)Guess the http type (GET, POST, PUT, DELETE, ...) of a method.voidhandleRequest(IService service, PathManager<AbstractRestPublishService.MappingInfo> pm, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object[] others)Handle a web request.booleanhasStringConvertableParameters(java.lang.reflect.Method method, java.lang.Class<?> rettype, java.lang.Class<?>[] paramtypes)Test if a method has parameters that are all convertible from string.IFuture<java.lang.Void>init()The service init.protected booleanisComplete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)IFuture<java.lang.Boolean>isSupported(java.lang.String publishtype)Test if publishing a specific type is supported (e.g.java.lang.StringloadFunctionJS()java.lang.StringloadStyleCSS()static voidmain(java.lang.String[] args)protected Tuple2<AbstractRestPublishService.MappingInfo,java.lang.Object[]>mapParameters(javax.servlet.http.HttpServletRequest request, java.util.Collection<AbstractRestPublishService.MappingInfo> mis, java.util.List<java.util.Map<java.lang.String,java.lang.String>> bindings)Map the incoming uri/post/multipart parameters to the service target parameter types.protected java.lang.ObjectmapResult(java.lang.reflect.Method method, java.lang.Object ret)Map a result using the result mapper.static java.util.List<java.lang.String>parseMimetypes(java.lang.String mts)todo: make statically accessible Copied from Jadex ForwardFilterabstract IFuture<java.lang.Void>publishService(IServiceIdentifier serviceid, PublishInfo info)Publish a service.voidremoveConverter(java.lang.String[] mediatypes, IObjectStringConverter converter)Remove a converter.protected voidsaveRequestContext(java.lang.String callid, javax.servlet.AsyncContext ctx)static java.util.Map<java.lang.String,java.lang.Object>splitQueryString(java.lang.String query)Split the query and save the order.protected voidwriteResponse(java.lang.Object result, int status, java.lang.String callid, AbstractRestPublishService.MappingInfo mi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean fin)protected voidwriteResponse(java.lang.Object result, java.lang.String callid, AbstractRestPublishService.MappingInfo mi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean fin)protected voidwriteResponseContent(java.lang.Object result, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.List<java.lang.String> sr)Write the response content.protected java.util.List<java.lang.String>writeResponseHeader(java.lang.Object ret, int status, java.lang.String callid, AbstractRestPublishService.MappingInfo mi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean fin)- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface jadex.bridge.service.types.publish.IPublishServiceunpublishService
 - 
Methods inherited from interface jadex.bridge.service.types.publish.IWebPublishServicepublishHMTLPage, publishResources
 
- 
 
- 
- 
- 
Field Detail- 
ASYNC_CONTEXT_INFOpublic static final java.lang.String ASYNC_CONTEXT_INFO Async context info.- See Also:
- Constant Field Values
 
 - 
HEADER_JADEX_CALLIDpublic static final java.lang.String HEADER_JADEX_CALLID Http header for the call id (req and resp).- See Also:
- Constant Field Values
 
 - 
HEADER_JADEX_CALLFINISHEDpublic static final java.lang.String HEADER_JADEX_CALLFINISHED Http header for the call id siganlling that this is the last response (resp).- See Also:
- Constant Field Values
 
 - 
HEADER_JADEX_CLIENTTIMEOUTpublic static final java.lang.String HEADER_JADEX_CLIENTTIMEOUT Http header for the client side timeout of calls (req).- See Also:
- Constant Field Values
 
 - 
HEADER_JADEX_TERMINATEpublic static final java.lang.String HEADER_JADEX_TERMINATE Http header to terminate the call (req).- See Also:
- Constant Field Values
 
 - 
FINISHEDpublic static final java.lang.String FINISHED Finished result marker.- See Also:
- Constant Field Values
 
 - 
PARAMETER_MEDIATYPESpublic static java.util.List<java.lang.String> PARAMETER_MEDIATYPES Some basic media types for service invocations.
 - 
componentprotected IInternalAccess component The component.
 - 
requestinfosprotected java.util.Map<java.lang.String,AbstractRestPublishService.RequestInfo> requestinfos The internal request info containing also results per call (coming from the called Jadex service).
 - 
requestspercallprotected MultiCollection<java.lang.String,javax.servlet.AsyncContext> requestspercall The requests per call (coming from the rest client). Signals on ongoing conversation as long as callid is contained (results are not immediately available).
 - 
convertersprotected MultiCollection<java.lang.String,IObjectStringConverter> converters The media type converters.
 
- 
 - 
Method Detail- 
initpublic IFuture<java.lang.Void> init() The service init.
 - 
addConverterpublic void addConverter(java.lang.String[] mediatypes, IObjectStringConverter converter)Add a converter for one or multiple types.
 - 
removeConverterpublic void removeConverter(java.lang.String[] mediatypes, IObjectStringConverter converter)Remove a converter.- Parameters:
- converter- The converter.
 
 - 
isSupportedpublic IFuture<java.lang.Boolean> isSupported(java.lang.String publishtype) Test if publishing a specific type is supported (e.g. web service).- Specified by:
- isSupportedin interface- IPublishService
- Parameters:
- publishtype- The type to test.
- Returns:
- True, if can be published.
 
 - 
handleRequestpublic void handleRequest(IService service, PathManager<AbstractRestPublishService.MappingInfo> pm, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object[] others) throws java.io.IOException, javax.servlet.ServletException Handle a web request.- Parameters:
- service- The service.
- mappings- The collected mapping infos for the service.
- request- The request.
- response- The response.
- Throws:
- java.io.IOException
- javax.servlet.ServletException
 
 - 
publishServicepublic abstract IFuture<java.lang.Void> publishService(IServiceIdentifier serviceid, PublishInfo info) Publish a service.- Specified by:
- publishServicein interface- IPublishService
- Parameters:
- cl- The classloader.
- service- The original service.
- pid- The publish id (e.g. url or name).
 
 - 
getHttpServerpublic abstract java.lang.Object getHttpServer(java.net.URI uri, PublishInfo info)Get or start an api to the http server.
 - 
getAsyncContextprotected javax.servlet.AsyncContext getAsyncContext(javax.servlet.http.HttpServletRequest request) Get the async
 - 
mapParametersprotected Tuple2<AbstractRestPublishService.MappingInfo,java.lang.Object[]> mapParameters(javax.servlet.http.HttpServletRequest request, java.util.Collection<AbstractRestPublishService.MappingInfo> mis, java.util.List<java.util.Map<java.lang.String,java.lang.String>> bindings) Map the incoming uri/post/multipart parameters to the service target parameter types.
 - 
convertJsonValuepublic static java.lang.Object convertJsonValue(java.lang.String val, java.lang.Class<?> type, java.lang.ClassLoader cl, boolean tomap)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).
 
 - 
convertParameterpublic java.lang.Object convertParameter(java.lang.Object val, java.lang.Class<?> target)Convert a (string) parameter- Parameters:
- val-
- target-
- Returns:
 
 - 
convertParameterprotected java.lang.Object convertParameter(java.util.List<java.lang.String> sr, java.lang.String val, java.lang.Class<?> targetclazz)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.
 
 - 
mapResultprotected java.lang.Object mapResult(java.lang.reflect.Method method, java.lang.Object ret)Map a result using the result mapper.
 - 
writeResponseprotected void writeResponse(java.lang.Object result, java.lang.String callid, AbstractRestPublishService.MappingInfo mi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean fin)
 - 
writeResponseprotected void writeResponse(java.lang.Object result, int status, java.lang.String callid, AbstractRestPublishService.MappingInfo mi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean fin)
 - 
writeResponseHeaderprotected java.util.List<java.lang.String> writeResponseHeader(java.lang.Object ret, int status, java.lang.String callid, AbstractRestPublishService.MappingInfo mi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean fin)
 - 
writeResponseContentprotected void writeResponseContent(java.lang.Object result, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.List<java.lang.String> sr)Write the response content.
 - 
saveRequestContextprotected void saveRequestContext(java.lang.String callid, javax.servlet.AsyncContext ctx)- Parameters:
- callid-
- ctx-
 
 - 
getRequestTimeoutpublic static long getRequestTimeout(javax.servlet.http.HttpServletRequest request) Get the request timeout.
 - 
parseMimetypespublic static java.util.List<java.lang.String> parseMimetypes(java.lang.String mts) todo: make statically accessible Copied from Jadex ForwardFilter
 - 
splitQueryStringpublic static java.util.Map<java.lang.String,java.lang.Object> splitQueryString(java.lang.String query) throws java.lang.ExceptionSplit the query and save the order.- Throws:
- java.lang.Exception
 
 - 
mainpublic static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
- java.lang.Exception
 
 - 
addEntryprotected static void addEntry(java.util.Map<java.lang.String,java.lang.Object> ret, java.lang.String key, java.lang.Object val)- Parameters:
- ret-
- key-
- val-
 
 - 
evaluateMappingpublic IFuture<PathManager<AbstractRestPublishService.MappingInfo>> evaluateMapping(IServiceIdentifier sid, PublishInfo pi) 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).
 - 
getServletUrlpublic static java.lang.String getServletUrl(javax.servlet.http.HttpServletRequest req) Get the servlet base url.- Parameters:
- req- The request.
- Returns:
- The servlet base url.
 
 - 
getServletHostpublic static java.lang.String getServletHost(javax.servlet.http.HttpServletRequest req) Get the servlet base url.- Parameters:
- req- The request.
- Returns:
- The servlet base url.
 
 - 
getServiceInfopublic java.lang.String getServiceInfo(java.lang.Object service, java.lang.String baseuri, PathManager<AbstractRestPublishService.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.
 
 - 
loadFunctionJSpublic java.lang.String loadFunctionJS() 
 - 
loadStyleCSSpublic java.lang.String loadStyleCSS() 
 - 
guessRestTypepublic AbstractRestPublishService.MappingInfo.HttpMethod guessRestType(java.lang.reflect.Method method) 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
 
 - 
hasStringConvertableParameterspublic boolean hasStringConvertableParameters(java.lang.reflect.Method method, java.lang.Class<?> rettype, java.lang.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.
 
 - 
completeprotected void complete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)- Parameters:
- request-
- cinfo-
 
 - 
isCompleteprotected boolean isComplete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)- Parameters:
- request-
- cinfo-
 
 - 
getParameterInfospublic Tuple2<java.util.List<Tuple2<java.lang.String,java.lang.String>>,java.util.Map<java.lang.String,java.lang.Class<?>>> getParameterInfos(java.lang.reflect.Method method) 
 - 
extractCallerValuespublic java.util.Map<java.lang.String,java.lang.String> extractCallerValues(java.lang.Object request) Extract caller values like ip and browser.- Parameters:
- request- The requrest.
- vals- The values.
 
 - 
getCleanPublishIdpublic java.lang.String getCleanPublishId(java.lang.String id) Get the cleaned publish id. Square brackets for the optional host and context part are removed.
 
- 
 
-