Package org.spincast.core.controllers
Class SpincastFrontController<R extends RequestContext<R>,W extends WebsocketContext<?>>
java.lang.Object
org.spincast.core.controllers.SpincastFrontController<R,W>
- All Implemented Interfaces:
FrontController
public class SpincastFrontController<R extends RequestContext<R>,W extends WebsocketContext<?>>
extends Object
implements FrontController
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSpincastFrontController(Router<R, W> router, SpincastConfig spincastConfig, Dictionary dictionary, Server server, RequestContextFactory<R> requestCreationFactory, SpincastRequestScope spincastRequestScope, Type requestContextType, JsonManager jsonManager, XmlManager xmlManager) The constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdd the default Not Found route.protected voidaddDependenciesInCustomRequestScope(R requestContext) Add dependencies to the custom request scopeprotected voidaddRequestContextInCustomRequestScope(R requestContext) Add the request context objects in the cutom request scopeprotected voidcallRouteHandlers(R requestContext, RoutingResult<R> routingResult) Call the handlers, in order they are specified.protected RcreateForwardedRequestContext(R context, String fullUrlOrRelativePathAndQueryString) protected voidcustomExceptionHandling(Throwable ex, R requestContext, RoutingResult<R> originalRoutingResult) Custom exception handling.protected voiddefaultExceptionHandling(Object exchange, Throwable ex) Default exception handling.protected voiddefaultPrivateExceptionHandling(Object exchange, Throwable exception) Default exception handling for private exceptionsprotected voiddefaultPublicExceptionHandling(Object exchange, PublicException publicException) Default exception handling for exceptions with public information.protected RoutingResult<R>findRouteMatch(R requestContext) Find the route handlers to call.protected StringCharset used by the default exception handling.Create the default Not Found handlerprotected StringThe message to send for the default Not Found handler.protected Dictionaryprotected StringgetInternalErrorHtmlContent(String errorMessage) protected StringgetInternalErrorJsonContent(String errorMessage) protected StringgetInternalErrorTextContent(String errorMessage) protected StringgetInternalErrorXmlContent(String errorMessage) protected JsonManagerprotected StringgetNotFoundHtmlContent(String message) protected StringgetNotFoundJsonContent(String message) protected StringgetNotFoundPlainTextContent(String message) protected StringgetNotFoundXmlContent(String message) protected RequestContextFactory<R>protected Typeprotected ContentTypeDefaultsgetResponseContentTypeToUse(Object exchange) protected Serverprotected SpincastConfigprotected SpincastRequestScopeprotected XmlManagervoidFront controller's handle() method, called by the HTTP server.protected voidlastResortExceptionHandling(Throwable originalException, Throwable defaultHandlingException) Called when the default exception handler itself throws an exception...protected voidmanageForwardRouteException(ForwardRouteException ex, R context, RoutingResult<R> originalRoutingResult) Manage a ForwardRouteException exception.protected voidmanageRedirectException(RedirectException ex, R context, RoutingResult<R> routingResult) Manage a RedirectException exception.protected RoutingResult<R>prepareNotFoundRouting(Object exchange, R requestContext) Prepares a direct Not Found routing.protected RoutingResult<R>prepareNotFoundRouting(Object exchange, R requestContext, boolean alreadyTried) Prepares a direct Not Found routing.protected voidresetResponse(R requestContext) protected voidsendErrorUsingBestMatchContentType(Object exchange, String errorMessage, Integer statusCode) Send an error to the client.protected ObjectvalidateExchange(Object exchange) Validate/modify the exchange before the handling.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger
-
-
Constructor Details
-
SpincastFrontController
@Inject public SpincastFrontController(Router<R, W> router, SpincastConfig spincastConfig, Dictionary dictionary, Server server, RequestContextFactory<R> requestCreationFactory, SpincastRequestScope spincastRequestScope, Type requestContextType, JsonManager jsonManager, XmlManager xmlManager) The constructor.
-
-
Method Details
-
getRouter
-
getSpincastConfig
-
getDictionary
-
getServer
-
getRequestContextFactory
-
getSpincastRequestScope
-
getRequestContextType
-
getJsonManager
-
getXmlManager
-
handle
Front controller's handle() method, called by the HTTP server.- Specified by:
handlein interfaceFrontController- Parameters:
exchange- an object representing the current request, provided by the HTTP server
-
prepareNotFoundRouting
Prepares a direct Not Found routing. -
prepareNotFoundRouting
protected RoutingResult<R> prepareNotFoundRouting(Object exchange, R requestContext, boolean alreadyTried) Prepares a direct Not Found routing. -
addDefaultNotFoundRoute
protected void addDefaultNotFoundRoute()Add the default Not Found route. -
getDefaultNotFoundHandler
Create the default Not Found handler -
getNotFoundHtmlContent
-
getNotFoundJsonContent
-
getNotFoundXmlContent
-
getNotFoundPlainTextContent
-
getDefaultNotFoundHandlerNotFoundMessage
The message to send for the default Not Found handler. -
resetResponse
-
customExceptionHandling
protected void customExceptionHandling(Throwable ex, R requestContext, RoutingResult<R> originalRoutingResult) throws Throwable Custom exception handling.- Throws:
Throwable
-
addDependenciesInCustomRequestScope
Add dependencies to the custom request scope -
addRequestContextInCustomRequestScope
Add the request context objects in the cutom request scope -
callRouteHandlers
Call the handlers, in order they are specified.- Throws:
Exception
-
manageRedirectException
protected void manageRedirectException(RedirectException ex, R context, RoutingResult<R> routingResult) Manage a RedirectException exception. -
manageForwardRouteException
protected void manageForwardRouteException(ForwardRouteException ex, R context, RoutingResult<R> originalRoutingResult) throws Exception Manage a ForwardRouteException exception.- Throws:
Exception
-
createForwardedRequestContext
-
validateExchange
Validate/modify the exchange before the handling. -
findRouteMatch
Find the route handlers to call. -
defaultExceptionHandling
Default exception handling.- Throws:
Throwable
-
defaultPublicExceptionHandling
protected void defaultPublicExceptionHandling(Object exchange, PublicException publicException) throws Throwable Default exception handling for exceptions with public information.- Throws:
Throwable
-
defaultPrivateExceptionHandling
protected void defaultPrivateExceptionHandling(Object exchange, Throwable exception) throws Throwable Default exception handling for private exceptions- Throws:
Throwable
-
sendErrorUsingBestMatchContentType
protected void sendErrorUsingBestMatchContentType(Object exchange, String errorMessage, Integer statusCode) throws Throwable Send an error to the client.- Throws:
Throwable
-
getDefaultExceptionHandlingCharset
Charset used by the default exception handling. -
getInternalErrorJsonContent
-
getInternalErrorXmlContent
-
getInternalErrorHtmlContent
-
getInternalErrorTextContent
-
getResponseContentTypeToUse
-
lastResortExceptionHandling
protected void lastResortExceptionHandling(Throwable originalException, Throwable defaultHandlingException) Called when the default exception handler itself throws an exception... Last resort!
-