From: <ath...@us...> - 2014-03-27 16:02:13
|
Revision: 1591 http://sourceforge.net/p/webassembletool/code/1591 Author: athaveau Date: 2014-03-27 16:02:11 +0000 (Thu, 27 Mar 2014) Log Message: ----------- #299 : always enable temporary cache and fix the cache key to avoid driver conflicts Modified Paths: -------------- trunk/esigate-app-aggregator/src/test/java/org/esigate/test/cases/AggregatorTest.java trunk/esigate-core/src/main/java/org/esigate/Driver.java trunk/esigate-core/src/main/java/org/esigate/http/ResourceUtils.java Added Paths: ----------- trunk/esigate-app-aggregated1/src/main/webapp/block1.html trunk/esigate-app-aggregated1/src/main/webapp/blocks.html trunk/esigate-app-aggregated2/src/main/webapp/block1.html trunk/esigate-app-aggregator/src/test/resources/blocks.html Added: trunk/esigate-app-aggregated1/src/main/webapp/block1.html =================================================================== --- trunk/esigate-app-aggregated1/src/main/webapp/block1.html (rev 0) +++ trunk/esigate-app-aggregated1/src/main/webapp/block1.html 2014-03-27 16:02:11 UTC (rev 1591) @@ -0,0 +1 @@ +aggregated1 \ No newline at end of file Added: trunk/esigate-app-aggregated1/src/main/webapp/blocks.html =================================================================== --- trunk/esigate-app-aggregated1/src/main/webapp/blocks.html (rev 0) +++ trunk/esigate-app-aggregated1/src/main/webapp/blocks.html 2014-03-27 16:02:11 UTC (rev 1591) @@ -0,0 +1,3 @@ +<!--$includeblock$default$block1.html$--><!--$endincludeblock$--> +<!--$includeblock$aggregated2$block1.html$--><!--$endincludeblock$--> +<!--$includeblock$aggregated2$block1.html$--><!--$endincludeblock$--> Added: trunk/esigate-app-aggregated2/src/main/webapp/block1.html =================================================================== --- trunk/esigate-app-aggregated2/src/main/webapp/block1.html (rev 0) +++ trunk/esigate-app-aggregated2/src/main/webapp/block1.html 2014-03-27 16:02:11 UTC (rev 1591) @@ -0,0 +1 @@ +aggregated2 \ No newline at end of file Modified: trunk/esigate-app-aggregator/src/test/java/org/esigate/test/cases/AggregatorTest.java =================================================================== --- trunk/esigate-app-aggregator/src/test/java/org/esigate/test/cases/AggregatorTest.java 2014-03-27 13:40:30 UTC (rev 1590) +++ trunk/esigate-app-aggregator/src/test/java/org/esigate/test/cases/AggregatorTest.java 2014-03-27 16:02:11 UTC (rev 1591) @@ -79,6 +79,9 @@ public void testBlock() throws Exception { doSimpleTest("block.html"); } + public void testBlocks2Drivers() throws Exception { + doSimpleTest("blocks.html","blocks.html"); + } public void testBlockGzip() throws Exception { doSimpleTest("block-gzip.html", "block.html"); Added: trunk/esigate-app-aggregator/src/test/resources/blocks.html =================================================================== --- trunk/esigate-app-aggregator/src/test/resources/blocks.html (rev 0) +++ trunk/esigate-app-aggregator/src/test/resources/blocks.html 2014-03-27 16:02:11 UTC (rev 1591) @@ -0,0 +1,3 @@ +aggregated1 +aggregated2 +aggregated2 \ No newline at end of file Modified: trunk/esigate-core/src/main/java/org/esigate/Driver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Driver.java 2014-03-27 13:40:30 UTC (rev 1590) +++ trunk/esigate-core/src/main/java/org/esigate/Driver.java 2014-03-27 16:02:11 UTC (rev 1591) @@ -22,6 +22,8 @@ import java.util.Properties; import org.apache.commons.io.output.StringBuilderWriter; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.entity.ContentType; @@ -49,7 +51,7 @@ * Main class used to retrieve data from a provider application using HTTP requests. Data can be retrieved as binary * streams or as String for text data. To improve performance, the Driver uses a cache that can be configured depending * on the needs. - * + * * @author Francois-Xavier Bonnet * @author Nicolas Richeton * @author Sylvain Sicard @@ -90,18 +92,18 @@ return driver; } - public DriverBuilder setName(String name) { - this.name = name; + public DriverBuilder setName(String n) { + this.name = n; return this; } - public DriverBuilder setProperties(Properties properties) { - this.properties = properties; + public DriverBuilder setProperties(Properties p) { + this.properties = p; return this; } - public DriverBuilder setRequestExecutorBuilder(RequestExecutorBuilder requestExecutorBuilder) { - this.requestExecutorBuilder = requestExecutorBuilder; + public DriverBuilder setRequestExecutorBuilder(RequestExecutorBuilder builder) { + this.requestExecutorBuilder = builder; return this; } @@ -116,7 +118,7 @@ /** * Get current event manager for this driver instance. - * + * * @return event manager. */ public EventManager getEventManager() { @@ -125,7 +127,7 @@ /** * Perform rendering on a single url content, and append result to "writer". - * + * * @param pageUrl * Address of the page containing the template * @param incomingRequest @@ -147,29 +149,28 @@ // 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 - CloseableHttpResponse response = null; - String currentValue = null; - // Get from cache to prevent multiple request to the same url if // multiple fragments are used. - boolean cacheable = "GET".equalsIgnoreCase(incomingRequest.getRequestLine().getMethod()); - if (cacheable) { - currentValue = incomingRequest.getAttribute(resultingPageUrl); - response = incomingRequest.getAttribute(CACHE_RESPONSE_PREFIX + resultingPageUrl); - } + String cacheKey = CACHE_RESPONSE_PREFIX + targetUrl; + Pair<String, CloseableHttpResponse> cachedValue = incomingRequest.getAttribute(cacheKey); // content and response were not in cache - if (currentValue == null) { - String targetUrl = ResourceUtils.getHttpUrlWithQueryString(resultingPageUrl, driverRequest, false); + if (cachedValue == null) { response = requestExecutor.createAndExecuteRequest(driverRequest, targetUrl, false); currentValue = HttpResponseUtils.toString(response, this.eventManager); // Cache - if (cacheable) { - incomingRequest.setAttribute(resultingPageUrl, currentValue); - incomingRequest.setAttribute(CACHE_RESPONSE_PREFIX + resultingPageUrl, response); - } + cachedValue = new ImmutablePair<String, CloseableHttpResponse>(currentValue, + response); + incomingRequest.setAttribute(cacheKey, cachedValue); } + currentValue = cachedValue.getKey(); + response = cachedValue.getValue(); logAction("render", pageUrl, renderers); @@ -187,7 +188,7 @@ * This methods log at the INFO level. * <p> * You should only call this method if INFO level is enabled. - * + * * <pre> * if (LOG.isInfoEnabled()) { * logAction(pageUrl, renderers); @@ -200,7 +201,7 @@ * current page url. * @param renderers * array of renderers - * + * */ private void logAction(String action, String onUrl, Renderer[] renderers) { if (LOG.isInfoEnabled()) { @@ -215,7 +216,7 @@ /** * Retrieves a resource from the provider application and transforms it using the Renderer passed as a parameter. - * + * * @param relUrl * the relative URL to the resource * @param request @@ -295,7 +296,7 @@ * Performs rendering on an HttpResponse. * <p> * Rendering is only performed if page can be parsed. - * + * * @param pageUrl * The remove url from which the body was retrieved. * @param originalRequest @@ -336,7 +337,7 @@ /** * Performs rendering (apply a render list) on an http response body (as a String). - * + * * @param pageUrl * The remove url from which the body was retrieved. * @param originalRequest @@ -379,7 +380,7 @@ * <p> * This may be supported in future versions (testing is needed). For the time being, changing configuration settings * after getting access through this method is <b>UNSUPPORTED</b> and <b>SHOULD NOT</b> be used. - * + * * @return current configuration */ public DriverConfiguration getConfiguration() { Modified: trunk/esigate-core/src/main/java/org/esigate/http/ResourceUtils.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/http/ResourceUtils.java 2014-03-27 13:40:30 UTC (rev 1590) +++ trunk/esigate-core/src/main/java/org/esigate/http/ResourceUtils.java 2014-03-27 16:02:11 UTC (rev 1591) @@ -35,10 +35,7 @@ private static String buildQueryString(DriverRequest originalRequest, boolean proxy) { StringBuilder queryString = new StringBuilder(Parameters.SMALL_BUFFER_SIZE); - String charset = originalRequest.getCharacterEncoding(); - if (charset == null) { - charset = "ISO-8859-1"; - } + String originalQuerystring = UriUtils.getRawQuery(originalRequest.getRequestLine().getUri()); if (proxy && originalQuerystring != null) { // Remove jsessionid from request if it is present This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |