Package org.hcjf.io.net.http.layered
Class LayeredContext<L extends LayerInterface,P extends LayeredRequest,R extends LayeredResponse>
- java.lang.Object
-
- org.hcjf.io.net.http.Context
-
- org.hcjf.io.net.http.layered.LayeredContext<L,P,R>
-
public abstract class LayeredContext<L extends LayerInterface,P extends LayeredRequest,R extends LayeredResponse> extends Context
This kind of context publish an http interface for som kind of layer.- Author:
- javaito
-
-
Field Summary
-
Fields inherited from class org.hcjf.io.net.http.Context
END_CONTEXT, START_CONTEXT, URI_FOLDER_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description LayeredContext(java.lang.String... endPointPath)
-
Method Summary
Modifier and Type Method Description protected abstract Pdecode(HttpRequest request)This implementation must create request package from http request.protected abstract HttpResponseencode(R response, P request)This implementation must create a http response package from response layered package and request layered package.protected java.util.List<java.lang.String>getEndPointPath()Return the list of the paths of the end point.protected LgetLayerInterface(java.lang.String implementationName)This method must return the instance of the layer interface.protected java.util.List<java.lang.String>getResourcePath(HttpRequest request)Return the list of paths skipping all the end point paths.protected abstract RonAction(P request)The implementation of this method must resolve the interface with the layer.HttpResponseonContext(HttpRequest request)This method is called when there comes a http package addressed to this context.protected HttpResponseonError(HttpRequest request, java.lang.Throwable throwable)This method is called when there are any error on the context execution.-
Methods inherited from class org.hcjf.io.net.http.Context
addDefaultResponseHeaders, createDefaultErrorResponse, getContextRegex, getPattern, getTimeout, setTimeout
-
-
-
-
Method Detail
-
getLayerInterface
protected final L getLayerInterface(java.lang.String implementationName)
This method must return the instance of the layer interface.- Parameters:
implementationName- Name of the implementation founded- Returns:
- Return the implementation founded.
- Throws:
java.lang.IllegalArgumentException- if the implementation with the pointed name is not found.
-
getEndPointPath
protected final java.util.List<java.lang.String> getEndPointPath()
Return the list of the paths of the end point.- Returns:
- List of the paths.
-
getResourcePath
protected final java.util.List<java.lang.String> getResourcePath(HttpRequest request)
Return the list of paths skipping all the end point paths.- Parameters:
request- Http request.- Returns:
- List of the resource path.
-
onContext
public final HttpResponse onContext(HttpRequest request)
This method is called when there comes a http package addressed to this context.
-
onAction
protected abstract R onAction(P request)
The implementation of this method must resolve the interface with the layer.- Parameters:
request- Request package.- Returns:
- Response package.
-
onError
protected HttpResponse onError(HttpRequest request, java.lang.Throwable throwable)
This method is called when there are any error on the context execution.
-
decode
protected abstract P decode(HttpRequest request)
This implementation must create request package from http request.- Parameters:
request- Http request.- Returns:
- Layered request package.
-
encode
protected abstract HttpResponse encode(R response, P request)
This implementation must create a http response package from response layered package and request layered package.- Parameters:
response- Layered response.request- Layered request.- Returns:
- Http response.
-
-