protected Response invokeController ( HttpServerExchange exchange , Response response ) throws IllegalAccessException , InvocationTargetException , MangooTemplateEngineException , IOException { Response invokedResponse ; if ( this . attachment . getMethodParameters ( ) . isEmpty ( ) ) { invokedResponse = ( Response ) this . attachment . getMethod ( ) . invoke ( this . attachment . getControllerInstance ( ) ) ; } else { final Object [ ] convertedParameters = getConvertedParameters ( exchange ) ; invokedResponse = ( Response ) this . attachment . getMethod ( ) . invoke ( this . attachment . getControllerInstance ( ) , convertedParameters ) ; } invokedResponse . andContent ( response . getContent ( ) ) ; invokedResponse . andHeaders ( response . getHeaders ( ) ) ; if ( invokedResponse . isRendered ( ) ) { TemplateContext templateContext = new TemplateContext ( invokedResponse . getContent ( ) ) . withFlash ( this . attachment . getFlash ( ) ) . withSession ( this . attachment . getSession ( ) ) . withForm ( this . attachment . getForm ( ) ) . withMessages ( this . attachment . getMessages ( ) ) . withController ( this . attachment . getControllerAndMethod ( ) ) . withPrettyTime ( this . attachment . getLocale ( ) ) . withAuthenticity ( this . attachment . getSession ( ) ) . withAuthenticityForm ( this . attachment . getSession ( ) ) . withTemplatePath ( getTemplatePath ( invokedResponse ) ) ; invokedResponse . andBody ( this . attachment . getTemplateEngine ( ) . renderTemplate ( templateContext ) ) ; } else if ( invokedResponse . isUnrendered ( ) ) { Cache cache = Application . getInstance ( CacheProvider . class ) . getCache ( CacheName . RESPONSE ) ; String path = "templates/" + this . attachment . getControllerClassName ( ) + ' ' + this . attachment . getControllerMethodName ( ) + ".body" ; String body = "" ; if ( cache . get ( path ) == null ) { body = Resources . toString ( Resources . getResource ( path ) , StandardCharsets . UTF_8 ) ; cache . put ( path , body ) ; } else { body = cache . get ( path ) ; } invokedResponse . andBody ( body ) ; } else { //ignore anything else } return invokedResponse ; }
Invokes the controller methods and retrieves the response which is later send to the client