private RESTResponse validateAndExecuteRequest ( HttpServletRequest request ) { Map < String , String > variableMap = new HashMap < String , String > ( ) ; String query = extractQueryParam ( request , variableMap ) ; Tenant tenant = getTenant ( variableMap ) ; // Command matching expects an encoded URI but without the servlet context, if any. String uri = request . getRequestURI ( ) ; String context = request . getContextPath ( ) ; if ( ! Utils . isEmpty ( context ) ) { uri = uri . substring ( context . length ( ) ) ; } ApplicationDefinition appDef = getApplication ( uri , tenant ) ; HttpMethod method = HttpMethod . methodFromString ( request . getMethod ( ) ) ; if ( method == null ) { throw new NotFoundException ( "Request does not match a known URI: " + request . getRequestURL ( ) ) ; } RegisteredCommand cmd = RESTService . instance ( ) . findCommand ( appDef , method , uri , query , variableMap ) ; if ( cmd == null ) { throw new NotFoundException ( "Request does not match a known URI: " + request . getRequestURL ( ) ) ; } validateTenantAccess ( request , tenant , cmd ) ; RESTCallback callback = cmd . getNewCallback ( ) ; callback . setRequest ( new RESTRequest ( tenant , appDef , request , variableMap ) ) ; return callback . invoke ( ) ; }
Execute the given request and return a RESTResponse or throw an appropriate error .