public CloseableHttpResponse proxy ( String relUrl , IncomingRequest incomingRequest , Renderer ... renderers ) throws IOException , HttpErrorPage { DriverRequest driverRequest = new DriverRequest ( incomingRequest , this , relUrl ) ; driverRequest . setCharacterEncoding ( this . config . getUriEncoding ( ) ) ; // This is used to ensure EVENT_PROXY_POST is called once and only once. // there are 3 different cases // - Success -> the main code // - Error page -> the HttpErrorPage exception // - Unexpected error -> Other Exceptions boolean postProxyPerformed = false ; // Create Proxy event ProxyEvent e = new ProxyEvent ( incomingRequest ) ; // Event pre-proxy this . eventManager . fire ( EventManager . EVENT_PROXY_PRE , e ) ; // Return immediately if exit is requested by extension if ( e . isExit ( ) ) { return e . getResponse ( ) ; } logAction ( "proxy" , relUrl , renderers ) ; String url = ResourceUtils . getHttpUrlWithQueryString ( relUrl , driverRequest , true ) ; OutgoingRequest outgoingRequest = requestExecutor . createOutgoingRequest ( driverRequest , url , true ) ; headerManager . copyHeaders ( driverRequest , outgoingRequest ) ; try { CloseableHttpResponse response = requestExecutor . execute ( outgoingRequest ) ; response = headerManager . copyHeaders ( outgoingRequest , incomingRequest , response ) ; e . setResponse ( response ) ; // Perform rendering e . setResponse ( performRendering ( relUrl , driverRequest , e . getResponse ( ) , renderers ) ) ; // Event post-proxy // This must be done before calling sendResponse to ensure response // can still be changed. postProxyPerformed = true ; this . eventManager . fire ( EventManager . EVENT_PROXY_POST , e ) ; // Send request to the client. return e . getResponse ( ) ; } catch ( HttpErrorPage errorPage ) { e . setErrorPage ( errorPage ) ; // On error returned by the proxy request, perform rendering on the // error page. CloseableHttpResponse response = e . getErrorPage ( ) . getHttpResponse ( ) ; response = headerManager . copyHeaders ( outgoingRequest , incomingRequest , response ) ; e . setErrorPage ( new HttpErrorPage ( performRendering ( relUrl , driverRequest , response , renderers ) ) ) ; // Event post-proxy // This must be done before throwing exception to ensure response // can still be changed. postProxyPerformed = true ; this . eventManager . fire ( EventManager . EVENT_PROXY_POST , e ) ; throw e . getErrorPage ( ) ; } finally { if ( ! postProxyPerformed ) { this . eventManager . fire ( EventManager . EVENT_PROXY_POST , e ) ; } } }
Retrieves a resource from the provider application and transforms it using the Renderer passed as a parameter .