public CloseableHttpResponse render ( String pageUrl , IncomingRequest incomingRequest , Renderer ... renderers ) throws IOException , HttpErrorPage { DriverRequest driverRequest = new DriverRequest ( incomingRequest , this , pageUrl ) ; // Replace ESI variables in URL // TODO: should be performed in the ESI extension String resultingPageUrl = VariablesResolver . replaceAllVariables ( pageUrl , driverRequest ) ; String targetUrl = ResourceUtils . getHttpUrlWithQueryString ( resultingPageUrl , driverRequest , false ) ; String currentValue ; CloseableHttpResponse response ; // Retrieve URL // Get from cache to prevent multiple request to the same url if // multiple fragments are used. String cacheKey = CACHE_RESPONSE_PREFIX + targetUrl ; Pair < String , CloseableHttpResponse > cachedValue = incomingRequest . getAttribute ( cacheKey ) ; // content and response were not in cache if ( cachedValue == null ) { OutgoingRequest outgoingRequest = requestExecutor . createOutgoingRequest ( driverRequest , targetUrl , false ) ; headerManager . copyHeaders ( driverRequest , outgoingRequest ) ; response = requestExecutor . execute ( outgoingRequest ) ; int redirects = MAX_REDIRECTS ; try { while ( redirects > 0 && this . redirectStrategy . isRedirected ( outgoingRequest , response , outgoingRequest . getContext ( ) ) ) { // Must consume the entity EntityUtils . consumeQuietly ( response . getEntity ( ) ) ; redirects -- ; // Perform new request outgoingRequest = this . requestExecutor . createOutgoingRequest ( driverRequest , this . redirectStrategy . getLocationURI ( outgoingRequest , response , outgoingRequest . getContext ( ) ) . toString ( ) , false ) ; this . headerManager . copyHeaders ( driverRequest , outgoingRequest ) ; response = requestExecutor . execute ( outgoingRequest ) ; } } catch ( ProtocolException e ) { throw new HttpErrorPage ( HttpStatus . SC_BAD_GATEWAY , "Invalid response from server" , e ) ; } response = this . headerManager . copyHeaders ( outgoingRequest , incomingRequest , response ) ; currentValue = HttpResponseUtils . toString ( response , this . eventManager ) ; // Cache cachedValue = new ImmutablePair <> ( currentValue , response ) ; incomingRequest . setAttribute ( cacheKey , cachedValue ) ; } currentValue = cachedValue . getKey ( ) ; response = cachedValue . getValue ( ) ; logAction ( "render" , pageUrl , renderers ) ; // Apply renderers currentValue = performRendering ( pageUrl , driverRequest , response , currentValue , renderers ) ; response . setEntity ( new StringEntity ( currentValue , HttpResponseUtils . getContentType ( response ) ) ) ; return response ; }
Perform rendering on a single url content and append result to writer . Automatically follows redirects