Package org.hcjf.io.net.http
Class Context
- java.lang.Object
-
- org.hcjf.io.net.http.Context
-
- Direct Known Subclasses:
EnumContext,FolderContext,LayeredContext,RestContext
public abstract class Context extends java.lang.ObjectThis class represents a standard web context that can be published- Author:
- javaito
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringEND_CONTEXTprotected static java.lang.StringSTART_CONTEXTprotected static java.lang.StringURI_FOLDER_SEPARATOR
-
Constructor Summary
Constructors Constructor Description Context(java.lang.String contextRegex)Constructor
-
Method Summary
Modifier and Type Method Description static HttpResponseaddDefaultResponseHeaders(HttpResponse response, byte[] body)Utils method in order to add a default headers into the default response package.static HttpResponsecreateDefaultErrorResponse(java.lang.Throwable throwable)Utils method in order to reuse the creation of error response package.java.lang.StringgetContextRegex()Return the regular expression that represents the add of URLs that refer to this context.java.util.regex.PatterngetPattern()Returns the pattern created with the regex of the context.longgetTimeout()Returns the timeout value of the context execution.abstract 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.voidsetTimeout(long timeout)Set the timeout value of the context execution.
-
-
-
Field Detail
-
START_CONTEXT
protected static final java.lang.String START_CONTEXT
- See Also:
- Constant Field Values
-
END_CONTEXT
protected static final java.lang.String END_CONTEXT
- See Also:
- Constant Field Values
-
URI_FOLDER_SEPARATOR
protected static final java.lang.String URI_FOLDER_SEPARATOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getContextRegex
public final java.lang.String getContextRegex()
Return the regular expression that represents the add of URLs that refer to this context.- Returns:
- Regular expression.
-
getPattern
public java.util.regex.Pattern getPattern()
Returns the pattern created with the regex of the context.- Returns:
- Pattern instance.
-
onContext
public abstract HttpResponse onContext(HttpRequest request)
This method is called when there comes a http package addressed to this context.- Parameters:
request- All the request information.- Returns:
- Return an object with all the response information.
-
getTimeout
public long getTimeout()
Returns the timeout value of the context execution.- Returns:
- Timeout value.
-
setTimeout
public void setTimeout(long timeout)
Set the timeout value of the context execution.- Parameters:
timeout- Timeout value.
-
onError
protected HttpResponse onError(HttpRequest request, java.lang.Throwable throwable)
This method is called when there are any error on the context execution.- Parameters:
request- All the request information.throwable- Throwable object, could be null.- Returns:
- Return an object with all the response information.
-
createDefaultErrorResponse
public static HttpResponse createDefaultErrorResponse(java.lang.Throwable throwable)
Utils method in order to reuse the creation of error response package.- Parameters:
throwable- Throwable instance.- Returns:
- Http response instance.
-
addDefaultResponseHeaders
public static HttpResponse addDefaultResponseHeaders(HttpResponse response, byte[] body)
Utils method in order to add a default headers into the default response package.- Parameters:
response- Response package.body- Body object.- Returns:
- Returns the same response instance with the headers added.
-
-