public static Resource optimizeNestedResourceChain ( final SecurityContext securityContext , final HttpServletRequest request , final Map < Pattern , Class < ? extends Resource > > resourceMap , final Value < String > propertyView ) throws FrameworkException { final List < Resource > resourceChain = ResourceHelper . parsePath ( securityContext , request , resourceMap , propertyView ) ; ViewFilterResource view = null ; int num = resourceChain . size ( ) ; boolean found = false ; do { for ( Iterator < Resource > it = resourceChain . iterator ( ) ; it . hasNext ( ) ; ) { Resource constr = it . next ( ) ; if ( constr instanceof ViewFilterResource ) { view = ( ViewFilterResource ) constr ; it . remove ( ) ; } } found = false ; try { for ( int i = 0 ; i < num ; i ++ ) { Resource firstElement = resourceChain . get ( i ) ; Resource secondElement = resourceChain . get ( i + 1 ) ; Resource combinedConstraint = firstElement . tryCombineWith ( secondElement ) ; if ( combinedConstraint != null ) { // remove source constraints resourceChain . remove ( firstElement ) ; resourceChain . remove ( secondElement ) ; // add combined constraint resourceChain . add ( i , combinedConstraint ) ; // signal success found = true ; } } } catch ( Throwable t ) { // ignore exceptions thrown here but make it possible to set a breakpoint final boolean test = false ; } } while ( found ) ; if ( resourceChain . size ( ) == 1 ) { Resource finalResource = resourceChain . get ( 0 ) ; if ( view != null ) { finalResource = finalResource . tryCombineWith ( view ) ; } if ( finalResource == null ) { // fall back to original resource finalResource = resourceChain . get ( 0 ) ; } return finalResource ; } else { logger . warn ( "Resource chain evaluation for path {} resulted in {} entries, returning status code 400." , new Object [ ] { request . getPathInfo ( ) , resourceChain . size ( ) } ) ; } throw new IllegalPathException ( "Cannot resolve URL path" ) ; }
Optimize the resource chain by trying to combine two resources to a new one