private void routeHandle ( RouteContext context ) { Object target = context . routeTarget ( ) ; if ( null == target ) { Class < ? > clazz = context . routeAction ( ) . getDeclaringClass ( ) ; target = WebContext . blade ( ) . getBean ( clazz ) ; } if ( context . targetType ( ) == RouteHandler . class ) { RouteHandler routeHandler = ( RouteHandler ) target ; routeHandler . handle ( context ) ; } else if ( context . targetType ( ) == RouteHandler0 . class ) { RouteHandler0 routeHandler = ( RouteHandler0 ) target ; routeHandler . handle ( context . request ( ) , context . response ( ) ) ; } else { Method actionMethod = context . routeAction ( ) ; Class < ? > returnType = actionMethod . getReturnType ( ) ; Path path = target . getClass ( ) . getAnnotation ( Path . class ) ; JSON JSON = actionMethod . getAnnotation ( JSON . class ) ; boolean isRestful = ( null != JSON ) || ( null != path && path . restful ( ) ) ; // if request is restful and not InternetExplorer userAgent if ( isRestful ) { if ( ! context . isIE ( ) ) { context . contentType ( Const . CONTENT_TYPE_JSON ) ; } else { context . contentType ( Const . CONTENT_TYPE_HTML ) ; } } int len = actionMethod . getParameterTypes ( ) . length ; MethodAccess methodAccess = BladeCache . getMethodAccess ( target . getClass ( ) ) ; Object returnParam = methodAccess . invoke ( target , actionMethod . getName ( ) , len > 0 ? context . routeParameters ( ) : null ) ; if ( null == returnParam ) { return ; } if ( isRestful ) { context . json ( returnParam ) ; return ; } if ( returnType == String . class ) { context . body ( ViewBody . of ( new ModelAndView ( returnParam . toString ( ) ) ) ) ; return ; } if ( returnType == ModelAndView . class ) { context . body ( ViewBody . of ( ( ModelAndView ) returnParam ) ) ; } } }
Actual routing method execution