From: <sbe...@us...> - 2011-11-11 10:38:42
|
Revision: 674 http://webassembletool.svn.sourceforge.net/webassembletool/?rev=674&view=rev Author: sbernatsky Date: 2011-11-11 10:38:36 +0000 (Fri, 11 Nov 2011) Log Message: ----------- cleanup: Parser instances aren't thread-safe -> make them class members from static finals Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/esi/EsiFragmentRenderer.java trunk/esigate-core/src/main/java/org/esigate/esi/EsiRenderer.java trunk/esigate-core/src/main/java/org/esigate/tags/BlockRenderer.java trunk/esigate-core/src/main/java/org/esigate/tags/TemplateRenderer.java Modified: trunk/esigate-core/src/main/java/org/esigate/esi/EsiFragmentRenderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/esi/EsiFragmentRenderer.java 2011-11-11 10:17:10 UTC (rev 673) +++ trunk/esigate-core/src/main/java/org/esigate/esi/EsiFragmentRenderer.java 2011-11-11 10:38:36 UTC (rev 674) @@ -20,7 +20,9 @@ */ public class EsiFragmentRenderer implements Renderer, Appendable { private final static Logger LOG = LoggerFactory.getLogger(EsiFragmentRenderer.class); - private final static Parser PARSER = new Parser(Pattern.compile("(<esi:[^>]*>)|(</esi:[^>]*>)"), FragmentElement.TYPE); + private final static Pattern PATTERN = Pattern.compile("(<esi:[^>]*>)|(</esi:[^>]*>)"); + + private final Parser parser = new Parser(PATTERN, FragmentElement.TYPE); private final String page; private final String name; private boolean write; @@ -47,7 +49,7 @@ if (content == null) { return; } - PARSER.parse(content, this); + parser.parse(content, this); } public Appendable append(CharSequence csq) throws IOException { Modified: trunk/esigate-core/src/main/java/org/esigate/esi/EsiRenderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/esi/EsiRenderer.java 2011-11-11 10:17:10 UTC (rev 673) +++ trunk/esigate-core/src/main/java/org/esigate/esi/EsiRenderer.java 2011-11-11 10:38:36 UTC (rev 674) @@ -24,33 +24,31 @@ * @author Francois-Xavier Bonnet */ public class EsiRenderer implements Renderer, Appendable { - private final static Parser PARSER = new Parser(Pattern - .compile("(<esi:[^>]*>)|(</esi:[^>]*>)|(<!--esi)|(-->)"), - IncludeElement.TYPE, Comment.TYPE, CommentElement.TYPE, - RemoveElement.TYPE, VarsElement.TYPE, ChooseElement.TYPE, - WhenElement.TYPE, OtherwiseElement.TYPE, TryElement.TYPE, - AttemptElement.TYPE, ExceptElement.TYPE, InlineElement.TYPE); - private Writer out; + private final static Pattern PATTERN = Pattern.compile("(<esi:[^>]*>)|(</esi:[^>]*>)|(<!--esi)|(-->)"); + + private final Parser parser = new Parser(PATTERN, + IncludeElement.TYPE, Comment.TYPE, CommentElement.TYPE, RemoveElement.TYPE, + VarsElement.TYPE, ChooseElement.TYPE, WhenElement.TYPE, OtherwiseElement.TYPE, + TryElement.TYPE, AttemptElement.TYPE, ExceptElement.TYPE, InlineElement.TYPE); private final HttpServletRequest request; private final HttpServletResponse response; private final Driver driver; + private Writer out; - public EsiRenderer(HttpServletRequest request, - HttpServletResponse response, Driver driver) { + public EsiRenderer(HttpServletRequest request, HttpServletResponse response, Driver driver) { this.request = request; this.response = response; this.driver = driver; } /** {@inheritDoc} */ - public void render(ResourceContext requestContext, String content, - Writer out) throws IOException, HttpErrorPage { + public void render(ResourceContext requestContext, String content, Writer out) throws IOException, HttpErrorPage { this.out = out; if (content == null) { return; } - PARSER.setRequest(request); - PARSER.parse(content, this); + parser.setRequest(request); + parser.parse(content, this); } public HttpServletRequest getRequest() { Modified: trunk/esigate-core/src/main/java/org/esigate/tags/BlockRenderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/tags/BlockRenderer.java 2011-11-11 10:17:10 UTC (rev 673) +++ trunk/esigate-core/src/main/java/org/esigate/tags/BlockRenderer.java 2011-11-11 10:38:36 UTC (rev 674) @@ -21,7 +21,9 @@ */ public class BlockRenderer implements Renderer, Appendable { private final static Logger LOG = LoggerFactory.getLogger(BlockRenderer.class); - private final static Parser PARSER = new Parser(Pattern.compile("<!--\\$[^>]*\\$-->"), BlockElement.TYPE); + private final static Pattern PATTERN = Pattern.compile("<!--\\$[^>]*\\$-->"); + + private final Parser parser = new Parser(PATTERN, BlockElement.TYPE); private final String page; private final String name; private boolean write; @@ -55,7 +57,7 @@ if (name == null) { out.write(content); } else { - PARSER.parse(content, this); + parser.parse(content, this); } } Modified: trunk/esigate-core/src/main/java/org/esigate/tags/TemplateRenderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/tags/TemplateRenderer.java 2011-11-11 10:17:10 UTC (rev 673) +++ trunk/esigate-core/src/main/java/org/esigate/tags/TemplateRenderer.java 2011-11-11 10:38:36 UTC (rev 674) @@ -5,7 +5,6 @@ import java.util.Map; import java.util.regex.Pattern; - import org.esigate.HttpErrorPage; import org.esigate.Renderer; import org.esigate.ResourceContext; @@ -32,10 +31,9 @@ */ public class TemplateRenderer implements Renderer, Appendable { private final static Logger LOG = LoggerFactory.getLogger(TemplateRenderer.class); - private final static Parser PARSER = new Parser(Pattern - .compile("<!--\\$[^>]*\\$-->"), TemplateElement.TYPE, - ParamElement.TYPE); + private final static Pattern PATTERN = Pattern.compile("<!--\\$[^>]*\\$-->"); + private final Parser parser = new Parser(PATTERN, TemplateElement.TYPE, ParamElement.TYPE); private final String page; private final String name; private final Map<String, String> params; @@ -65,7 +63,7 @@ } } } else { - PARSER.parse(content, this); + parser.parse(content, this); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fxb...@us...> - 2012-11-23 16:53:25
|
Revision: 919 http://webassembletool.svn.sourceforge.net/webassembletool/?rev=919&view=rev Author: fxbonnet Date: 2012-11-23 16:53:19 +0000 (Fri, 23 Nov 2012) Log Message: ----------- Fixed warnings on missing javadoc, unused imports and variables. Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/api/HttpRequest.java trunk/esigate-core/src/main/java/org/esigate/authentication/RemoteUserAuthenticationHandler.java trunk/esigate-core/src/main/java/org/esigate/authentication/RequestAuthenticationHandler.java trunk/esigate-core/src/main/java/org/esigate/cache/BasicCacheStorage.java trunk/esigate-core/src/main/java/org/esigate/cache/EhcacheCacheStorage.java trunk/esigate-core/src/main/java/org/esigate/cache/ManagedCacheStorage.java trunk/esigate-core/src/main/java/org/esigate/cache/MemcachedCacheStorage.java trunk/esigate-core/src/main/java/org/esigate/extension/Extension.java trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java trunk/esigate-core/src/main/java/org/esigate/filter/Filter.java trunk/esigate-core/src/main/java/org/esigate/util/UriUtils.java Modified: trunk/esigate-core/src/main/java/org/esigate/api/HttpRequest.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/api/HttpRequest.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/api/HttpRequest.java 2012-11-23 16:53:19 UTC (rev 919) @@ -15,7 +15,6 @@ package org.esigate.api; -import java.io.IOException; import java.io.InputStream; import org.apache.http.Header; Modified: trunk/esigate-core/src/main/java/org/esigate/authentication/RemoteUserAuthenticationHandler.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/authentication/RemoteUserAuthenticationHandler.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/authentication/RemoteUserAuthenticationHandler.java 2012-11-23 16:53:19 UTC (rev 919) @@ -34,10 +34,12 @@ public class RemoteUserAuthenticationHandler extends GenericAuthentificationHandler { + @Override public boolean needsNewRequest(HttpResponse response, HttpRequest httpRequest) { return false; } + @Override public void preRequest(GenericHttpRequest request, HttpRequest httpRequest) { UserContext userContext = HttpRequestHelper.getUserContext(httpRequest); String remoteUser = null; @@ -57,6 +59,7 @@ } + @Override public boolean beforeProxy(HttpRequest httpRequest) { return true; } Modified: trunk/esigate-core/src/main/java/org/esigate/authentication/RequestAuthenticationHandler.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/authentication/RequestAuthenticationHandler.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/authentication/RequestAuthenticationHandler.java 2012-11-23 16:53:19 UTC (rev 919) @@ -56,10 +56,12 @@ private final List<String> requestAttributes = new ArrayList<String>(); private String headerPrefix = "X-ATTR-"; + @Override public boolean beforeProxy(HttpRequest httpRequest) { return true; } + @Override public void init( Properties properties) { // Attributes for session String sessionAttributesProperty = properties.getProperty("forwardSessionAttributes"); @@ -92,10 +94,12 @@ } } + @Override public boolean needsNewRequest(HttpResponse response, HttpRequest httpRequest) { return false; } + @Override public void preRequest(GenericHttpRequest request, HttpRequest httpRequest) { if (logger.isDebugEnabled()) { logger.debug("preRequest"); Modified: trunk/esigate-core/src/main/java/org/esigate/cache/BasicCacheStorage.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/BasicCacheStorage.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/cache/BasicCacheStorage.java 2012-11-23 16:53:19 UTC (rev 919) @@ -21,6 +21,7 @@ public class BasicCacheStorage extends CacheStorage { + @Override public void init(Properties properties) { CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties); impl = new BasicHttpCacheStorage(cacheConfig); Modified: trunk/esigate-core/src/main/java/org/esigate/cache/EhcacheCacheStorage.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/EhcacheCacheStorage.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/cache/EhcacheCacheStorage.java 2012-11-23 16:53:19 UTC (rev 919) @@ -26,6 +26,7 @@ public class EhcacheCacheStorage extends CacheStorage { public final static String DEFAULT_CACHE_NAME = "EsiGate"; + @Override public void init(Properties properties) { String cacheName = Parameters.EHCACHE_CACHE_NAME_PROPERTY.getValueString(properties); String configurationFileName = Parameters.EHCACHE_CONFIGURATION_FILE_PROPERTY.getValueString(properties); Modified: trunk/esigate-core/src/main/java/org/esigate/cache/ManagedCacheStorage.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/ManagedCacheStorage.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/cache/ManagedCacheStorage.java 2012-11-23 16:53:19 UTC (rev 919) @@ -21,6 +21,7 @@ public class ManagedCacheStorage extends CacheStorage { + @Override public void init(Properties properties) { CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties); impl = new ManagedHttpCacheStorage(cacheConfig); Modified: trunk/esigate-core/src/main/java/org/esigate/cache/MemcachedCacheStorage.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/MemcachedCacheStorage.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/cache/MemcachedCacheStorage.java 2012-11-23 16:53:19 UTC (rev 919) @@ -32,6 +32,7 @@ import org.esigate.Parameters; public class MemcachedCacheStorage extends CacheStorage { + @Override public void init(Properties properties) { Collection<String> serverStringList = Parameters.MEMCACHED_SERVERS_PROPERTY.getValueList(properties); if (serverStringList.isEmpty()) Modified: trunk/esigate-core/src/main/java/org/esigate/extension/Extension.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/Extension.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/extension/Extension.java 2012-11-23 16:53:19 UTC (rev 919) @@ -34,6 +34,7 @@ * Initialize the extension using the given properties. * <p> * Extensions may register to events during the init phase. + * @param driver * * @param properties */ Modified: trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java 2012-11-23 16:53:19 UTC (rev 919) @@ -43,10 +43,10 @@ * * @param properties * @param parameter + * @param d * * @param <T> * class which extends Extension - * @param clazz * class which extends Extension * @return instance of {@link Extension} or null. */ @@ -80,7 +80,7 @@ * @param properties * @param parameter * @param d - * @return + * @return the extension list */ @SuppressWarnings("unchecked") public final static <T extends Extension> List<T> getExtensions( Modified: trunk/esigate-core/src/main/java/org/esigate/filter/Filter.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/filter/Filter.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/filter/Filter.java 2012-11-23 16:53:19 UTC (rev 919) @@ -15,8 +15,6 @@ package org.esigate.filter; -import java.util.Properties; - import org.apache.http.HttpResponse; import org.apache.http.protocol.HttpContext; import org.esigate.api.HttpRequest; @@ -37,9 +35,6 @@ void postRequest(GenericHttpRequest httpRequest, HttpResponse response, HttpContext httpContext, HttpRequest originalRequest); Filter EMPTY = new Filter() { - public void init(Properties properties) { - } - public void preRequest(GenericHttpRequest request, HttpContext httpContext, HttpRequest originalRequest) { } Modified: trunk/esigate-core/src/main/java/org/esigate/util/UriUtils.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/util/UriUtils.java 2012-11-23 16:48:08 UTC (rev 918) +++ trunk/esigate-core/src/main/java/org/esigate/util/UriUtils.java 2012-11-23 16:53:19 UTC (rev 919) @@ -25,7 +25,7 @@ public static URI createURI(final String scheme, final String host, int port, final String path, final String query, final String fragment) { try { - return URIUtils.createURI(scheme, host, port, path, query, fragment); + return new URI(scheme, null, host, port, path, query, fragment); } catch (URISyntaxException e) { throw new InvalidUriException(e); } @@ -69,7 +69,8 @@ } /** - * Translates an URL by replacing the beginning like in the example passed as parameters + * Translates an URL by replacing the beginning like in the example passed + * as parameters * * @param sourceUrl * @param sourceContext @@ -78,7 +79,8 @@ * @throws MalformedURLException */ public final static String translateUrl(String sourceUrl, String sourceContext, String targetContext) throws MalformedURLException { - // Find what has been replaced at the beginning of sourceContext to transform it to targetContext + // Find what has been replaced at the beginning of sourceContext to + // transform it to targetContext String commonSuffix = StringUtils.reverse(StringUtils.getCommonPrefix(StringUtils.reverse(sourceContext), StringUtils.reverse(targetContext))); String sourcePrefix = StringUtils.removeEnd(sourceContext, commonSuffix); String targetPrefix = StringUtils.removeEnd(targetContext, commonSuffix); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2012-11-27 07:52:39
|
Revision: 923 http://webassembletool.svn.sourceforge.net/webassembletool/?rev=923&view=rev Author: nricheton Date: 2012-11-27 07:52:27 +0000 (Tue, 27 Nov 2012) Log Message: ----------- 0000076: Redesign / document EsiGate entry points (extensions) https://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=76 Added Render event Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Driver.java trunk/esigate-core/src/main/java/org/esigate/Parameters.java trunk/esigate-core/src/main/java/org/esigate/events/EventManager.java trunk/esigate-core/src/main/java/org/esigate/events/impl/FetchEvent.java trunk/esigate-core/src/main/java/org/esigate/events/impl/FragmentEvent.java Added Paths: ----------- trunk/esigate-core/src/main/java/org/esigate/events/impl/RenderEvent.java trunk/esigate-core/src/main/java/org/esigate/extension/ResourceFixup.java Modified: trunk/esigate-core/src/main/java/org/esigate/Driver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Driver.java 2012-11-26 07:48:28 UTC (rev 922) +++ trunk/esigate-core/src/main/java/org/esigate/Driver.java 2012-11-27 07:52:27 UTC (rev 923) @@ -35,13 +35,13 @@ import org.esigate.events.EventManager; import org.esigate.events.impl.FragmentEvent; import org.esigate.events.impl.ProxyEvent; +import org.esigate.events.impl.RenderEvent; import org.esigate.extension.ExtensionFactory; import org.esigate.http.GenericHttpRequest; import org.esigate.http.HttpClientHelper; import org.esigate.http.HttpResponseUtils; import org.esigate.http.RequestCookieStore; import org.esigate.http.ResourceUtils; -import org.esigate.renderers.ResourceFixupRenderer; import org.esigate.util.HttpRequestHelper; import org.esigate.vars.VariablesResolver; import org.slf4j.Logger; @@ -129,23 +129,27 @@ request); String currentValue = getResourceAsString(resultingpage, request); - // Fix resources - if (config.isFixResources()) { - String baseUrl = HttpRequestHelper.getBaseUrl(request).toString(); - ResourceFixupRenderer fixup = new ResourceFixupRenderer(baseUrl, - config.getVisibleBaseURL(baseUrl), page, - config.getFixMode()); - StringWriter stringWriter = new StringWriter(); - fixup.render(request, currentValue, stringWriter); - currentValue = stringWriter.toString(); - } + // Start rendering. + RenderEvent renderEvent= new RenderEvent(); + renderEvent.originalRequest = request; + renderEvent.remoteUrl = page; + // Create renderer list from parameters. Ensure at least an additional + // renderer can be added at no cost. + renderEvent.renderers = new ArrayList<Renderer>( + renderers.length + 1); + renderEvent.renderers.addAll(Arrays.asList(renderers)); + + eventManager.fire(EventManager.EVENT_RENDER_PRE, renderEvent); + // Process all renderers - for (Renderer renderer : renderers) { + for (Renderer renderer : renderEvent.renderers) { StringWriter stringWriter = new StringWriter(); renderer.render(request, currentValue, stringWriter); currentValue = stringWriter.toString(); } + eventManager.fire(EventManager.EVENT_RENDER_POST, renderEvent); + writer.append(currentValue); } @@ -221,23 +225,26 @@ LOG.debug("'{}' is text : will apply renderers.", relUrl); String currentValue = HttpResponseUtils.toString(httpResponse); - List<Renderer> listOfRenderers = new ArrayList<Renderer>( + // Start rendering + RenderEvent renderEvent= new RenderEvent(); + renderEvent.originalRequest = request; + renderEvent.remoteUrl = relUrl; + // Create renderer list from parameters. Ensure at least an additional + // renderer can be added at no cost. + renderEvent.renderers = new ArrayList<Renderer>( renderers.length + 1); - if (config.isFixResources()) { - String baseUrl = HttpRequestHelper.getBaseUrl(request) - .toString(); - ResourceFixupRenderer fixup = new ResourceFixupRenderer( - baseUrl, config.getVisibleBaseURL(baseUrl), relUrl, - config.getFixMode()); - listOfRenderers.add(fixup); - } - listOfRenderers.addAll(Arrays.asList(renderers)); - - for (Renderer renderer : listOfRenderers) { + renderEvent.renderers.addAll(Arrays.asList(renderers)); + + eventManager.fire(EventManager.EVENT_RENDER_PRE, renderEvent); + for (Renderer renderer : renderEvent.renderers) { StringWriter stringWriter = new StringWriter(); renderer.render(request, currentValue, stringWriter); currentValue = stringWriter.toString(); } + eventManager.fire(EventManager.EVENT_RENDER_POST, renderEvent); + + + // Write the result to the OutpuStream using default charset // ISO-8859-1 if not defined String charsetName = HttpResponseUtils Modified: trunk/esigate-core/src/main/java/org/esigate/Parameters.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2012-11-26 07:48:28 UTC (rev 922) +++ trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2012-11-27 07:52:27 UTC (rev 923) @@ -20,6 +20,7 @@ import org.esigate.cookie.DefaultCookieManager; import org.esigate.extension.FetchLogging; import org.esigate.extension.FragmentLogging; +import org.esigate.extension.ResourceFixup; import org.esigate.util.Parameter; /** @@ -73,7 +74,7 @@ public static final String ROUNDROBIN = "roundrobin"; // Extensions - public static final Parameter EXTENSIONS = new Parameter("extensions", FragmentLogging.class.getName()+","+FetchLogging.class.getName()+","+RemoteUserAuthenticationHandler.class.getName());; + public static final Parameter EXTENSIONS = new Parameter("extensions", FragmentLogging.class.getName()+","+FetchLogging.class.getName()+","+RemoteUserAuthenticationHandler.class.getName()+","+ResourceFixup.class.getName());; public static final Parameter FILTER = new Parameter("filter", null); Modified: trunk/esigate-core/src/main/java/org/esigate/events/EventManager.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/events/EventManager.java 2012-11-26 07:48:28 UTC (rev 922) +++ trunk/esigate-core/src/main/java/org/esigate/events/EventManager.java 2012-11-27 07:52:27 UTC (rev 923) @@ -33,11 +33,19 @@ * <li>{@link EventManager#EVENT_FRAGMENT_PRE} : before retrieving a fragment.</li> * <li>{@link EventManager#EVENT_FRAGMENT_POST} : after retrieving a fragment.</li> * </ul> - * <p>Fetch events : An HTTP call is made to a remote backend. + * <p> + * Fetch events : An HTTP call is made to a remote backend. * <ul> * <li>{@link EventManager#EVENT_FETCH_PRE} : before creating the HTTP call.</li> * <li>{@link EventManager#EVENT_FETCH_POST} : after we receive the response.</li> * </ul> + * <p> + * Render events : Renderers are applied to the current page. This event can be + * used to inject additional renderers. + * <ul> + * <li>{@link EventManager#EVENT_RENDER_PRE} : before applying renderers</li> + * <li>{@link EventManager#EVENT_RENDER_POST} : after applying renderers</li> + * </ul> * * @author Nicolas Richeton */ @@ -58,6 +66,11 @@ public static EventDefinition EVENT_PROXY_POST = new EventDefinition( "org.esigate.proxy-post", EventDefinition.TYPE_POST); + public static EventDefinition EVENT_RENDER_PRE = new EventDefinition( + "org.esigate.render-pre", EventDefinition.TYPE_DEFAULT); + public static EventDefinition EVENT_RENDER_POST = new EventDefinition( + "org.esigate.render-post", EventDefinition.TYPE_POST); + private static final Logger LOG = LoggerFactory .getLogger(EventManager.class); @@ -135,7 +148,7 @@ List<IEventListener> eventListeners = listenerMappings .get(eventDefinition); - // Not listeners at all for this event + // No listeners at all for this event if (eventListeners == null) return; Modified: trunk/esigate-core/src/main/java/org/esigate/events/impl/FetchEvent.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/events/impl/FetchEvent.java 2012-11-26 07:48:28 UTC (rev 922) +++ trunk/esigate-core/src/main/java/org/esigate/events/impl/FetchEvent.java 2012-11-27 07:52:27 UTC (rev 923) @@ -5,6 +5,12 @@ import org.apache.http.protocol.HttpContext; import org.esigate.events.Event; +/** + * Fetch event : when a new HTTP call is made to get a new block/template (Cache miss). + * + * @author Nicolas Richeton + * + */ public class FetchEvent extends Event { public HttpResponse httpResponse; /** Modified: trunk/esigate-core/src/main/java/org/esigate/events/impl/FragmentEvent.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/events/impl/FragmentEvent.java 2012-11-26 07:48:28 UTC (rev 922) +++ trunk/esigate-core/src/main/java/org/esigate/events/impl/FragmentEvent.java 2012-11-27 07:52:27 UTC (rev 923) @@ -6,7 +6,9 @@ import org.esigate.http.GenericHttpRequest; /** - * Fetch event : when a new HTTP call is made to get a new block/template. + * Fragment event : when a fragment is required for rendering. This may start a + * fetch event in case of a cache miss. Else the fragment is retrived from the + * cache. * * @author Nicolas Richeton * @@ -30,7 +32,7 @@ * The new HTTP call details. */ public GenericHttpRequest httpRequest; - + /** * The request which was received by ESIgate. */ Added: trunk/esigate-core/src/main/java/org/esigate/events/impl/RenderEvent.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/events/impl/RenderEvent.java (rev 0) +++ trunk/esigate-core/src/main/java/org/esigate/events/impl/RenderEvent.java 2012-11-27 07:52:27 UTC (rev 923) @@ -0,0 +1,20 @@ +package org.esigate.events.impl; + +import java.util.List; + +import org.esigate.Renderer; +import org.esigate.api.HttpRequest; +import org.esigate.events.Event; + +/** + * Render event : when renderers are applied on the page. + * + * @author Nicolas Richeton + * + */ +public class RenderEvent extends Event { + + public List<Renderer> renderers; + public String remoteUrl; + public HttpRequest originalRequest; +} Added: trunk/esigate-core/src/main/java/org/esigate/extension/ResourceFixup.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/ResourceFixup.java (rev 0) +++ trunk/esigate-core/src/main/java/org/esigate/extension/ResourceFixup.java 2012-11-27 07:52:27 UTC (rev 923) @@ -0,0 +1,48 @@ +package org.esigate.extension; + +import java.util.Properties; + +import org.esigate.Driver; +import org.esigate.DriverConfiguration; +import org.esigate.events.Event; +import org.esigate.events.EventDefinition; +import org.esigate.events.EventManager; +import org.esigate.events.IEventListener; +import org.esigate.events.impl.RenderEvent; +import org.esigate.renderers.ResourceFixupRenderer; +import org.esigate.util.HttpRequestHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ResourceFixup implements Extension, IEventListener { + private static final Logger LOG = LoggerFactory + .getLogger(ResourceFixup.class); + private Driver driver; + private DriverConfiguration config; + + public boolean event(EventDefinition id, Event event) { + + RenderEvent renderEvent = (RenderEvent) event; + // Fix resources + if (config.isFixResources()) { + String baseUrl = HttpRequestHelper.getBaseUrl( + renderEvent.originalRequest).toString(); + ResourceFixupRenderer fixup = new ResourceFixupRenderer(baseUrl, + config.getVisibleBaseURL(baseUrl), renderEvent.remoteUrl, + config.getFixMode()); + + // Add fixup renderer as first renderer. + renderEvent.renderers.add(0, fixup); + } + + // Continue processing + return true; + } + + public void init(Driver driver, Properties properties) { + this.driver = driver; + this.config = driver.getConfiguration(); + driver.getEventManager().register(EventManager.EVENT_RENDER_PRE, this); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2012-12-13 19:00:14
|
Revision: 970 http://webassembletool.svn.sourceforge.net/webassembletool/?rev=970&view=rev Author: nricheton Date: 2012-12-13 19:00:06 +0000 (Thu, 13 Dec 2012) Log Message: ----------- 0000140: Ability to remove 'Via' header https://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=140 Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Parameters.java trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java Modified: trunk/esigate-core/src/main/java/org/esigate/Parameters.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2012-12-13 18:52:52 UTC (rev 969) +++ trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2012-12-13 19:00:06 UTC (rev 970) @@ -20,8 +20,8 @@ import org.esigate.cookie.DefaultCookieManager; import org.esigate.extension.FetchLogging; import org.esigate.extension.FragmentLogging; +import org.esigate.extension.ResourceFixup; import org.esigate.extension.XPoweredBy; -import org.esigate.extension.ResourceFixup; import org.esigate.util.Parameter; /** @@ -85,6 +85,7 @@ public final static Parameter MAX_OBJECT_SIZE = new Parameter("maxObjectSize", "1000000"); public final static Parameter CACHE_STORAGE = new Parameter("cacheStorage", BasicCacheStorage.class.getName()); public final static Parameter X_CACHE_HEADER = new Parameter("xCacheHeader", "false"); + public final static Parameter VIA_HEADER = new Parameter("viaHeader", "true"); // Forced caching public final static Parameter TTL = new Parameter("ttl", "0"); Modified: trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java 2012-12-13 18:52:52 UTC (rev 969) +++ trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java 2012-12-13 19:00:06 UTC (rev 970) @@ -54,12 +54,14 @@ private int staleWhileRevalidate; private int ttl; private boolean xCacheHeader; + private boolean viaHeader; public void init(Properties properties) { staleIfError = Parameters.STALE_IF_ERROR.getValueInt(properties); staleWhileRevalidate = Parameters.STALE_WHILE_REVALIDATE.getValueInt(properties); ttl = Parameters.TTL.getValueInt(properties); xCacheHeader = Parameters.X_CACHE_HEADER.getValueBoolean(properties); + viaHeader = Parameters.X_CACHE_HEADER.getValueBoolean(properties); } private abstract class HttpClientWrapper implements HttpClient { @@ -247,7 +249,8 @@ httpResponse.addHeader("X-Cache", xCacheString); } } - // FIXME remove empty entity to avoid NullPointerException in + + // FIXME remove empty entity to avoid NullPointerException in // org.apache.http.impl.client.cache.CacheEntity.writeTo(CacheEntity.java:82) HttpEntity entity = httpResponse.getEntity(); if (entity != null && entity.getContentLength() == 0) { @@ -258,6 +261,11 @@ } httpResponse.setEntity(null); } + + // Remove Via header + if( !viaHeader && httpResponse.containsHeader("Via")){ + httpResponse.removeHeaders("Via"); + } } }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sbe...@us...> - 2011-11-14 11:00:50
|
Revision: 677 http://webassembletool.svn.sourceforge.net/webassembletool/?rev=677&view=rev Author: sbernatsky Date: 2011-11-14 11:00:44 +0000 (Mon, 14 Nov 2011) Log Message: ----------- cleanup Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/esi/Comment.java trunk/esigate-core/src/main/java/org/esigate/esi/TryElement.java trunk/esigate-core/src/main/java/org/esigate/xml/XpathRenderer.java trunk/esigate-core/src/main/java/org/esigate/xml/XsltRenderer.java Modified: trunk/esigate-core/src/main/java/org/esigate/esi/Comment.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/esi/Comment.java 2011-11-14 10:02:33 UTC (rev 676) +++ trunk/esigate-core/src/main/java/org/esigate/esi/Comment.java 2011-11-14 11:00:44 UTC (rev 677) @@ -28,24 +28,29 @@ super(TYPE); } + @Override public void doStartTag(String tag, Appendable parent, ElementStack stack) { this.parent = parent; } + @Override public boolean isClosed() { return false; } + @Override public Appendable append(CharSequence csq) throws IOException { parent.append(csq); return this; } + @Override public Appendable append(char c) throws IOException { parent.append(c); return this; } + @Override public Appendable append(CharSequence csq, int start, int end) throws IOException { parent.append(csq, start, end); return this; Modified: trunk/esigate-core/src/main/java/org/esigate/esi/TryElement.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/esi/TryElement.java 2011-11-14 10:02:33 UTC (rev 676) +++ trunk/esigate-core/src/main/java/org/esigate/esi/TryElement.java 2011-11-14 11:00:44 UTC (rev 677) @@ -12,8 +12,6 @@ }; - private boolean condition; - private boolean hasCondition; private boolean includeInside; TryElement() { @@ -28,26 +26,9 @@ this.includeInside = includeInside; } + @Override protected void parseTag(Tag tag, Appendable parent, ElementStack stack) { - condition = false; - hasCondition = false; + this.includeInside = false; } - public boolean hasCondition() { - return hasCondition; - } - - public boolean isCondition() { - return condition; - } - - public void setCondition(boolean condition) { - this.condition = condition; - hasCondition = true; - } - - public void setHasCondition(boolean hasCondition) { - this.hasCondition = hasCondition; - } - } Modified: trunk/esigate-core/src/main/java/org/esigate/xml/XpathRenderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/xml/XpathRenderer.java 2011-11-14 10:02:33 UTC (rev 676) +++ trunk/esigate-core/src/main/java/org/esigate/xml/XpathRenderer.java 2011-11-14 11:00:44 UTC (rev 677) @@ -7,7 +7,6 @@ import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; @@ -22,7 +21,6 @@ import nu.validator.htmlparser.common.XmlViolationPolicy; import nu.validator.htmlparser.dom.HtmlDocumentBuilder; -import org.esigate.HttpErrorPage; import org.esigate.Renderer; import org.esigate.ResourceContext; import org.w3c.dom.Document; @@ -40,51 +38,40 @@ */ public class XpathRenderer implements Renderer { private final static HtmlNamespaceContext HTML_NAMESPACE_CONTEXT = new HtmlNamespaceContext(); - private final static XPathFactory X_PATH_FACTORY = XPathFactory - .newInstance(); - private final static TransformerFactory TRANSFORMER_FACTORY = TransformerFactory - .newInstance(); + private final static XPathFactory X_PATH_FACTORY = XPathFactory.newInstance(); + private final static TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(); private final XPathExpression expr; - private String outputMethod = "xml"; + private final String outputMethod; public XpathRenderer(String xpath) { - XPath xpathObj = X_PATH_FACTORY.newXPath(); - xpathObj.setNamespaceContext(HTML_NAMESPACE_CONTEXT); + this(xpath, "xml"); + } + + public XpathRenderer(String xpath, String outputMethod) { try { - expr = xpathObj.compile(xpath); + XPath xpathObj = X_PATH_FACTORY.newXPath(); + xpathObj.setNamespaceContext(HTML_NAMESPACE_CONTEXT); + this.expr = xpathObj.compile(xpath); + this.outputMethod = outputMethod; } catch (XPathExpressionException e) { - throw new ProcessingFailedException( - "failed to compile XPath expression", e); + throw new ProcessingFailedException("failed to compile XPath expression", e); } } - public XpathRenderer(String xpath, String outputMethod) { - this(xpath); - this.outputMethod = outputMethod; - } - /** {@inheritDoc} */ - public void render(ResourceContext requestContext, String src, Writer out) - throws IOException, HttpErrorPage { + public void render(ResourceContext requestContext, String src, Writer out) throws IOException { try { - HtmlDocumentBuilder htmlDocumentBuilder = new HtmlDocumentBuilder( - XmlViolationPolicy.ALLOW); - htmlDocumentBuilder - .setDoctypeExpectation(DoctypeExpectation.NO_DOCTYPE_ERRORS); - Document document = htmlDocumentBuilder.parse(new InputSource( - new StringReader(src))); + HtmlDocumentBuilder htmlDocumentBuilder = new HtmlDocumentBuilder(XmlViolationPolicy.ALLOW); + htmlDocumentBuilder.setDoctypeExpectation(DoctypeExpectation.NO_DOCTYPE_ERRORS); + Document document = htmlDocumentBuilder.parse(new InputSource(new StringReader(src))); Node xpathed = (Node) expr.evaluate(document, XPathConstants.NODE); Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, - "yes"); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, outputMethod); Source source = new DOMSource(xpathed); transformer.transform(source, new StreamResult(out)); } catch (XPathExpressionException e) { - throw new ProcessingFailedException( - "Failed to evaluate XPath expression", e); - } catch (TransformerConfigurationException e) { - throw new ProcessingFailedException("Unable to parse source", e); + throw new ProcessingFailedException("Failed to evaluate XPath expression", e); } catch (TransformerException e) { throw new ProcessingFailedException("Unable to parse source", e); } catch (SAXException e) { Modified: trunk/esigate-core/src/main/java/org/esigate/xml/XsltRenderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/xml/XsltRenderer.java 2011-11-14 10:02:33 UTC (rev 676) +++ trunk/esigate-core/src/main/java/org/esigate/xml/XsltRenderer.java 2011-11-14 11:00:44 UTC (rev 677) @@ -20,7 +20,6 @@ import nu.validator.htmlparser.sax.HtmlParser; import org.apache.commons.io.IOUtils; -import org.esigate.HttpErrorPage; import org.esigate.Renderer; import org.esigate.ResourceContext; import org.xml.sax.InputSource; @@ -35,8 +34,7 @@ * @author Francois-Xavier Bonnet */ public class XsltRenderer implements Renderer { - private final static TransformerFactory TRANSFORMER_FACTORY = TransformerFactory - .newInstance(); + private final static TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(); private final Transformer transformer; /** @@ -50,8 +48,7 @@ public XsltRenderer(String template, ServletContext ctx) throws IOException { InputStream templateStream = ctx.getResourceAsStream(template); if (templateStream == null) { - throw new ProcessingFailedException("Template " + template - + " not found"); + throw new ProcessingFailedException("Template " + template + " not found"); } transformer = createTransformer(templateStream); } @@ -67,28 +64,22 @@ transformer = createTransformer(templateStream); } - private Transformer createTransformer(InputStream templateStream) - throws IOException { + private static Transformer createTransformer(InputStream templateStream) throws IOException { try { - return TRANSFORMER_FACTORY.newTransformer(new StreamSource( - templateStream)); + return TRANSFORMER_FACTORY.newTransformer(new StreamSource(templateStream)); } catch (TransformerConfigurationException e) { - throw new ProcessingFailedException( - "Failed to create XSLT template", e); + throw new ProcessingFailedException("Failed to create XSLT template", e); } finally { templateStream.close(); } } /** {@inheritDoc} */ - public void render(ResourceContext requestContext, String src, Writer out) - throws IOException, HttpErrorPage { + public void render(ResourceContext requestContext, String src, Writer out) throws IOException { try { HtmlParser htmlParser = new HtmlParser(XmlViolationPolicy.ALLOW); - htmlParser - .setDoctypeExpectation(DoctypeExpectation.NO_DOCTYPE_ERRORS); - Source source = new SAXSource(htmlParser, new InputSource( - new StringReader(src))); + htmlParser.setDoctypeExpectation(DoctypeExpectation.NO_DOCTYPE_ERRORS); + Source source = new SAXSource(htmlParser, new InputSource(new StringReader(src))); transformer.transform(source, new StreamResult(out)); } catch (TransformerException e) { throw new ProcessingFailedException("Failed to transform source", e); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sbe...@us...> - 2011-12-16 09:58:46
|
Revision: 766 http://webassembletool.svn.sourceforge.net/webassembletool/?rev=766&view=rev Author: sbernatsky Date: 2011-12-16 09:58:36 +0000 (Fri, 16 Dec 2011) Log Message: ----------- fix some findbug issues Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/cache/CacheEntry.java trunk/esigate-core/src/main/java/org/esigate/cache/CacheOutput.java trunk/esigate-core/src/main/java/org/esigate/cache/CachedResponseSummary.java trunk/esigate-core/src/main/java/org/esigate/cache/DefaultCacheStorage.java trunk/esigate-core/src/main/java/org/esigate/esi/ReplaceElement.java trunk/esigate-core/src/main/java/org/esigate/http/CookieAdapter.java trunk/esigate-core/src/main/java/org/esigate/servlet/RewriteProxyServlet.java Modified: trunk/esigate-core/src/main/java/org/esigate/cache/CacheEntry.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/CacheEntry.java 2011-12-14 14:32:52 UTC (rev 765) +++ trunk/esigate-core/src/main/java/org/esigate/cache/CacheEntry.java 2011-12-16 09:58:36 UTC (rev 766) @@ -388,16 +388,14 @@ } // Cleanup - if (System.currentTimeMillis() - lastClean > CLEAN_DELAY) { - // Ensure only a single thread starts cleaning. - synchronized (this) { - if (System.currentTimeMillis() - lastClean > CLEAN_DELAY) { - for (CachedResponseSummary summary : responseSummaries) { - // Delete no longer existing responses. - getCacheResponseAndClean(summary); - } - lastClean = System.currentTimeMillis(); + // Ensure only a single thread starts cleaning. + synchronized (this) { + if (System.currentTimeMillis() - lastClean > CLEAN_DELAY) { + for (CachedResponseSummary summary : responseSummaries) { + // Delete no longer existing responses. + getCacheResponseAndClean(summary); } + lastClean = System.currentTimeMillis(); } } } Modified: trunk/esigate-core/src/main/java/org/esigate/cache/CacheOutput.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/CacheOutput.java 2011-12-14 14:32:52 UTC (rev 765) +++ trunk/esigate-core/src/main/java/org/esigate/cache/CacheOutput.java 2011-12-16 09:58:36 UTC (rev 766) @@ -115,7 +115,7 @@ * * @return true if content size exceeds maxSize */ - public boolean isTooBig() { + public synchronized boolean isTooBig() { return tooBig; } Modified: trunk/esigate-core/src/main/java/org/esigate/cache/CachedResponseSummary.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/CachedResponseSummary.java 2011-12-14 14:32:52 UTC (rev 765) +++ trunk/esigate-core/src/main/java/org/esigate/cache/CachedResponseSummary.java 2011-12-16 09:58:36 UTC (rev 766) @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.Date; +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -30,6 +31,7 @@ int statusCode, String statusMessage) { super(headers, statusCode, statusMessage); this.cacheKey = cacheKey; + this.requestHeaders = new HashMap<String, String>(); } @Override @@ -99,8 +101,8 @@ @Override public String getRequestHeader(String key) { for (Entry<String, String> entry : requestHeaders.entrySet()) { - if (key.equalsIgnoreCase(entry.getKey().toString())) { - return entry.getValue().toString(); + if (key.equalsIgnoreCase(entry.getKey())) { + return entry.getValue(); } } Modified: trunk/esigate-core/src/main/java/org/esigate/cache/DefaultCacheStorage.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/DefaultCacheStorage.java 2011-12-14 14:32:52 UTC (rev 765) +++ trunk/esigate-core/src/main/java/org/esigate/cache/DefaultCacheStorage.java 2011-12-16 09:58:36 UTC (rev 766) @@ -6,6 +6,9 @@ import java.util.PriorityQueue; import java.util.Properties; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + public class DefaultCacheStorage implements CacheStorage { private static final Comparator<CacheEntry> CACHE_ENTRY_COMPARATOR = new Comparator<CacheEntry>() { public int compare(CacheEntry o1, CacheEntry o2) { @@ -95,6 +98,14 @@ } @Override + public int hashCode() { + return new HashCodeBuilder() + .append(key) + .append(ttl) + .toHashCode(); + } + + @Override public boolean equals(Object obj) { if (this == obj) { return true; @@ -102,28 +113,16 @@ if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof CacheEntry)) { return false; } + CacheEntry other = (CacheEntry) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - if (ttl != other.ttl) { - return false; - } - if (value == null) { - if (other.value != null) { - return false; - } - } else if (!value.equals(other.value)) { - return false; - } - return true; + return new EqualsBuilder() + .append(key, other.key) + .append(ttl, other.ttl) + .append(value, other.value) + .isEquals(); } } Modified: trunk/esigate-core/src/main/java/org/esigate/esi/ReplaceElement.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/esi/ReplaceElement.java 2011-12-14 14:32:52 UTC (rev 765) +++ trunk/esigate-core/src/main/java/org/esigate/esi/ReplaceElement.java 2011-12-16 09:58:36 UTC (rev 766) @@ -40,7 +40,7 @@ } else { parent.characters(result, 0, result.length()); } - parent = null; + buf = null; } Modified: trunk/esigate-core/src/main/java/org/esigate/http/CookieAdapter.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/http/CookieAdapter.java 2011-12-14 14:32:52 UTC (rev 765) +++ trunk/esigate-core/src/main/java/org/esigate/http/CookieAdapter.java 2011-12-16 09:58:36 UTC (rev 766) @@ -11,79 +11,66 @@ import org.esigate.cookie.CustomCookieStore; class CookieAdapter { - - public static CookieStore convertCookieStore(CustomCookieStore customStore) - { - return new Adapter(customStore); + + public static CookieStore convertCookieStore(CustomCookieStore customStore) { + return new Adapter(customStore); } - - public static org.apache.http.cookie.Cookie toApacheCookie(Cookie cookie) - { - org.apache.http.cookie.Cookie newCookie = new BasicClientCookie2(cookie.getName(), cookie.getValue()); - if(cookie != null){ - ((BasicClientCookie2)newCookie).setComment(cookie.getComment()); - ((BasicClientCookie2)newCookie).setCommentURL(cookie.getCommentURL()); - ((BasicClientCookie2)newCookie).setDomain(cookie.getDomain()); - ((BasicClientCookie2)newCookie).setExpiryDate(cookie.getExpiryDate()); - ((BasicClientCookie2)newCookie).setPath(cookie.getPath()); - ((BasicClientCookie2)newCookie).setPorts(cookie.getPorts()); - ((BasicClientCookie2)newCookie).setSecure(cookie.isSecure()); - ((BasicClientCookie2)newCookie).setVersion(cookie.getVersion()); - } + + public static org.apache.http.cookie.Cookie toApacheCookie(Cookie cookie) { + BasicClientCookie2 newCookie = new BasicClientCookie2(cookie.getName(), cookie.getValue()); + newCookie.setComment(cookie.getComment()); + newCookie.setCommentURL(cookie.getCommentURL()); + newCookie.setDomain(cookie.getDomain()); + newCookie.setExpiryDate(cookie.getExpiryDate()); + newCookie.setPath(cookie.getPath()); + newCookie.setPorts(cookie.getPorts()); + newCookie.setSecure(cookie.isSecure()); + newCookie.setVersion(cookie.getVersion()); + return newCookie; - } - - public static Cookie toCustomCookie(org.apache.http.cookie.Cookie cookie) - { - Cookie newCookie = new BasicClientCookie(cookie.getName(), cookie.getValue()); - if(cookie != null){ - ((BasicClientCookie)newCookie).setComment(cookie.getComment()); - ((BasicClientCookie)newCookie).setCommentURL(cookie.getCommentURL()); - ((BasicClientCookie)newCookie).setDomain(cookie.getDomain()); - ((BasicClientCookie)newCookie).setExpiryDate(cookie.getExpiryDate()); - ((BasicClientCookie)newCookie).setPath(cookie.getPath()); - ((BasicClientCookie)newCookie).setPorts(cookie.getPorts()); - ((BasicClientCookie)newCookie).setSecure(cookie.isSecure()); - ((BasicClientCookie)newCookie).setVersion(cookie.getVersion()); - } - return newCookie; - + public static Cookie toCustomCookie(org.apache.http.cookie.Cookie cookie) { + BasicClientCookie newCookie = new BasicClientCookie(cookie.getName(), cookie.getValue()); + newCookie.setComment(cookie.getComment()); + newCookie.setCommentURL(cookie.getCommentURL()); + newCookie.setDomain(cookie.getDomain()); + newCookie.setExpiryDate(cookie.getExpiryDate()); + newCookie.setPath(cookie.getPath()); + newCookie.setPorts(cookie.getPorts()); + newCookie.setSecure(cookie.isSecure()); + newCookie.setVersion(cookie.getVersion()); + + return newCookie; } - + private static class Adapter implements CookieStore { - - private CustomCookieStore customStore; - - private Adapter(CustomCookieStore customStore){ + private final CustomCookieStore customStore; + + private Adapter(CustomCookieStore customStore) { this.customStore = customStore; } - + public void addCookie(org.apache.http.cookie.Cookie cookie) { - customStore.addCookie(toCustomCookie(cookie)); + customStore.addCookie(toCustomCookie(cookie)); } - + public List<org.apache.http.cookie.Cookie> getCookies() { - List<Cookie> customCookieList = customStore.getCookies(); - List<org.apache.http.cookie.Cookie> cookiesList = - new ArrayList<org.apache.http.cookie.Cookie>(customCookieList.size()); - - for(Cookie cookie : customCookieList) - { + List<org.apache.http.cookie.Cookie> cookiesList = new ArrayList<org.apache.http.cookie.Cookie>(customCookieList.size()); + for (Cookie cookie : customCookieList) { cookiesList.add(toApacheCookie(cookie)); } return cookiesList; } - + public boolean clearExpired(Date date) { return customStore.clearExpired(date); } - + public void clear() { customStore.clear(); } - + } } Modified: trunk/esigate-core/src/main/java/org/esigate/servlet/RewriteProxyServlet.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/servlet/RewriteProxyServlet.java 2011-12-14 14:32:52 UTC (rev 765) +++ trunk/esigate-core/src/main/java/org/esigate/servlet/RewriteProxyServlet.java 2011-12-16 09:58:36 UTC (rev 766) @@ -4,6 +4,7 @@ import java.io.InputStream; import java.net.URL; import java.util.ArrayList; +import java.util.Map.Entry; import java.util.Properties; import java.util.TreeMap; import java.util.regex.Matcher; @@ -218,10 +219,10 @@ @Override public void init(ServletConfig config) throws ServletException { TreeMap<String, ReverseConfiguration> confTree = new TreeMap<String, ReverseConfiguration>(); + InputStream propertiesInput = null; try { // Open configuration file. - InputStream propertiesInput = RewriteProxyServlet.class - .getResourceAsStream("/org/esigate/rewrite-proxy.properties"); + propertiesInput = RewriteProxyServlet.class.getResourceAsStream("/org/esigate/rewrite-proxy.properties"); // Load properties Properties properties = new Properties(); @@ -229,13 +230,14 @@ propertiesInput.close(); // Loop on properties. - for (Object key : properties.keySet()) { + for (Entry<Object, Object> entry : properties.entrySet()) { + String key = (String) entry.getKey(); // Get line content. - String[] keySplitted = ((String) key).split("\\."); + String[] keySplitted = key.split("\\."); String rule = keySplitted[0]; String attribute = keySplitted[1]; - String value = properties.getProperty((String) key); + String value = (String) entry.getValue(); // Create configuration instance if necessary. ReverseConfiguration currentConf = confTree.get(rule); @@ -276,6 +278,14 @@ configuration.addAll(confTree.values()); } catch (IOException e) { throw new ServletException(e); + } finally { + if (propertiesInput != null) { + try { + propertiesInput.close(); + } catch (IOException e) { + LOG.error("failed to close stream", e); + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-08-02 18:43:29
|
Revision: 1291 http://sourceforge.net/p/webassembletool/code/1291 Author: nricheton Date: 2013-08-02 18:43:27 +0000 (Fri, 02 Aug 2013) Log Message: ----------- cleanup/warnings/javadoc Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java Modified: trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java 2013-08-02 18:37:27 UTC (rev 1290) +++ trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java 2013-08-02 18:43:27 UTC (rev 1291) @@ -40,6 +40,12 @@ * @author Nicolas Richeton */ public class DriverFactory { + + /** + * System property used to specify of esigate configuration, outside of the + * classpath. + */ + public static final String PROP_CONF_LOCATION = "esigate.config"; private static IndexedInstances INSTANCES = new IndexedInstances(new HashMap<String, Driver>()); private static final String DEFAULT_INSTANCE_NAME = "default"; private static final Logger LOG = LoggerFactory.getLogger(DriverFactory.class); @@ -60,13 +66,13 @@ try { // Load from environment - String envPath = System.getProperty("esigate.config"); + String envPath = System.getProperty(PROP_CONF_LOCATION); if (envPath != null) { try { LOG.info("Scanning configuration {}", envPath); inputStream = new FileInputStream(new File(envPath)); } catch (FileNotFoundException e) { - LOG.error("Can't read file {} (from -Desigate.config)", envPath, e); + LOG.error("Can't read file {} (from -D"+PROP_CONF_LOCATION+")", envPath, e); } } @@ -143,7 +149,7 @@ */ public final static void configure(Properties props) { Properties defaultProperties = new Properties(); - + HashMap<String, Properties> driversProps = new HashMap<String, Properties>(); for (Enumeration<?> enumeration = props.propertyNames(); enumeration.hasMoreElements();) { String propertyName = (String) enumeration.nextElement(); @@ -228,7 +234,7 @@ * @param url * The requested url * @return - * @throws HttpErrorPage + * @throws HttpErrorPage */ public static Driver getInstanceFor(String scheme, String host, String url) throws HttpErrorPage { for (UriMapping mapping : INSTANCES.getUrimappings().keySet()) { @@ -238,7 +244,7 @@ } // If no match, return default instance. - throw new HttpErrorPage(404, "Not found", "No mapping defined for this url."); + throw new HttpErrorPage(404, "Not found", "No mapping defined for this url."); } /** @@ -286,12 +292,12 @@ INSTANCES = new IndexedInstances(newInstances); } - + /** * Ensure configuration has been loaded at least once. Helps to prevent * delay on first call because of initialization. */ - public static void ensureConfigured(){ + public static void ensureConfigured() { // Just trigger static init. } } Modified: trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2013-08-02 18:37:27 UTC (rev 1290) +++ trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2013-08-02 18:43:27 UTC (rev 1291) @@ -47,7 +47,8 @@ * The wait time (ms) between to check for configuration change. * */ - public static Parameter CONFIG_RELOAD_DELAY = new Parameter("configReloadDelay", String.valueOf(DEFAULT_RELOAD_DELAY)); + public static Parameter CONFIG_RELOAD_DELAY = new Parameter("configReloadDelay", + String.valueOf(DEFAULT_RELOAD_DELAY)); // Do not poll too fast. (ms). private static final int SPEED_LIMIT = 100; @@ -93,7 +94,7 @@ // Do nothing if configuration is loaded from the classpath if (configuration == null) { - LOG.warn("Cannot reload configuration from classpath. Please use -Desigate.config"); + LOG.warn("Cannot reload configuration from classpath. Please use -D" + DriverFactory.PROP_CONF_LOCATION); return; } @@ -111,7 +112,8 @@ CONFIG_RELOAD_DELAY.getValueString(properties)); } - LOG.info("Will reload configuration every {}ms if {} is modified", Long.valueOf(delay), configuration.getAbsoluteFile()); + LOG.info("Will reload configuration every {}ms if {} is modified", Long.valueOf(delay), + configuration.getAbsoluteFile()); } // This static block ensure thread is started only once. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-10-22 18:13:25
|
Revision: 1426 http://sourceforge.net/p/webassembletool/code/1426 Author: nricheton Date: 2013-10-22 18:13:22 +0000 (Tue, 22 Oct 2013) Log Message: ----------- 0000264: Replace StringWriter by StringBuilderWriter for better performance http://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=264 Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Driver.java trunk/esigate-core/src/main/java/org/esigate/HttpErrorPage.java trunk/esigate-core/src/main/java/org/esigate/Renderer.java Modified: trunk/esigate-core/src/main/java/org/esigate/Driver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Driver.java 2013-10-22 13:07:21 UTC (rev 1425) +++ trunk/esigate-core/src/main/java/org/esigate/Driver.java 2013-10-22 18:13:22 UTC (rev 1426) @@ -16,7 +16,6 @@ package org.esigate; import java.io.IOException; -import java.io.StringWriter; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -26,6 +25,7 @@ import java.util.Map; import java.util.Properties; +import org.apache.commons.io.output.StringBuilderWriter; import org.apache.http.HttpEntity; import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpHeaders; @@ -373,8 +373,9 @@ this.eventManager.fire(EventManager.EVENT_RENDER_PRE, renderEvent); for (Renderer renderer : renderEvent.renderers) { - StringWriter stringWriter = new StringWriter(); + StringBuilderWriter stringWriter = new StringBuilderWriter(1024); renderer.render(originalRequest, currentBody, stringWriter); + stringWriter.close(); currentBody = stringWriter.toString(); } this.eventManager.fire(EventManager.EVENT_RENDER_POST, renderEvent); Modified: trunk/esigate-core/src/main/java/org/esigate/HttpErrorPage.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/HttpErrorPage.java 2013-10-22 13:07:21 UTC (rev 1425) +++ trunk/esigate-core/src/main/java/org/esigate/HttpErrorPage.java 2013-10-22 18:13:22 UTC (rev 1426) @@ -17,9 +17,9 @@ import java.io.IOException; import java.io.PrintWriter; -import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import org.apache.commons.io.output.StringBuilderWriter; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -32,14 +32,24 @@ import org.apache.http.util.EntityUtils; /** - * Exception thrown when an error occurred retrieving a resource + * Exception thrown when an error occurred retrieving a resource. + * <p> + * This exception can include a HTTP response (with error page body) or a String + * body. * * @author Francois-Xavier Bonnet + * @author Nicolas Richeton */ public class HttpErrorPage extends Exception { private static final long serialVersionUID = 1L; private final HttpResponse httpResponse; + /** + * Create an HTTP error page exception from an Http response. + * + * @param httpResponse + * backend response. + */ public HttpErrorPage(HttpResponse httpResponse) { super(httpResponse.getStatusLine().getStatusCode() + " " + httpResponse.getStatusLine().getReasonPhrase()); this.httpResponse = httpResponse; @@ -55,14 +65,24 @@ byteArrayEntity.setContentEncoding(contentEncoding); memoryEntity = byteArrayEntity; } catch (IOException e) { - StringWriter out = new StringWriter(); - e.printStackTrace(new PrintWriter(out)); + StringBuilderWriter out = new StringBuilderWriter(512); + PrintWriter pw = new PrintWriter(out); + e.printStackTrace(pw); + pw.close(); memoryEntity = new StringEntity(out.toString(), ContentType.getOrDefault(httpEntity)); } this.httpResponse.setEntity(memoryEntity); } } + /** + * Create an HTTP response from a String content wich will be used as the + * response entity. + * + * @param statusCode + * @param statusMessage + * @param content + */ public HttpErrorPage(int statusCode, String statusMessage, String content) { super(statusCode + " " + statusMessage); this.httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusMessage)); @@ -74,22 +94,38 @@ } } + /** + * Create an HTTP response from an exception. This exception stack trace + * will be showed to the end user. + * + * @param statusCode + * @param statusMessage + * @param exception + */ public HttpErrorPage(int statusCode, String statusMessage, Exception exception) { super(statusCode + " " + statusMessage, exception); this.httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusMessage)); - StringWriter out = new StringWriter(); - exception.printStackTrace(new PrintWriter(out)); + StringBuilderWriter out = new StringBuilderWriter(512); + PrintWriter pw = new PrintWriter(out); + exception.printStackTrace(pw); String content = out.toString(); try { this.httpResponse.setEntity(new StringEntity(content, "UTF-8")); } catch (UnsupportedEncodingException e) { // This should not happen as UTF-8 is always supported throw new RuntimeException(e); + } finally { + pw.close(); } } + /** + * Get HTTP response enclosed in this exception. + * + * @return HTTP response + */ public HttpResponse getHttpResponse() { - return httpResponse; + return this.httpResponse; } } Modified: trunk/esigate-core/src/main/java/org/esigate/Renderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Renderer.java 2013-10-22 13:07:21 UTC (rev 1425) +++ trunk/esigate-core/src/main/java/org/esigate/Renderer.java 2013-10-22 18:13:22 UTC (rev 1426) @@ -30,11 +30,13 @@ /** * Renders provided source and writes results to the output * + * * @param originalRequest * @param src * source to be rendered * @param out - * output destination + * output destination. This writer is not thread-safe, use proper + * synchronization if writing output from multiple threads. * @throws IOException * @throws HttpErrorPage */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-10-28 12:32:18
|
Revision: 1449 http://sourceforge.net/p/webassembletool/code/1449 Author: nricheton Date: 2013-10-28 12:32:15 +0000 (Mon, 28 Oct 2013) Log Message: ----------- Cleanup Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Driver.java trunk/esigate-core/src/main/java/org/esigate/DriverConfiguration.java trunk/esigate-core/src/main/java/org/esigate/HttpErrorPage.java trunk/esigate-core/src/main/java/org/esigate/Renderer.java trunk/esigate-core/src/main/java/org/esigate/RequestExecutor.java trunk/esigate-core/src/main/java/org/esigate/UserContext.java trunk/esigate-core/src/main/java/org/esigate/aggregator/Adapter.java trunk/esigate-core/src/main/java/org/esigate/aggregator/AggregateRenderer.java trunk/esigate-core/src/main/java/org/esigate/aggregator/AggregationSyntaxException.java trunk/esigate-core/src/main/java/org/esigate/aggregator/ElementAttributes.java trunk/esigate-core/src/main/java/org/esigate/package-info.java Modified: trunk/esigate-core/src/main/java/org/esigate/Driver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Driver.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/Driver.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -50,7 +50,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. + * depending on the needs. * * @author Francois-Xavier Bonnet * @author Nicolas Richeton Modified: trunk/esigate-core/src/main/java/org/esigate/DriverConfiguration.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/DriverConfiguration.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/DriverConfiguration.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -30,13 +30,13 @@ import org.esigate.url.StickySessionBaseUrlRetrieveStrategy; /** - * Driver configuration parameters + * Driver configuration parameters. * * @author Francois-Xavier Bonnet * @author Nicolas Richeton */ public class DriverConfiguration { - + private final String instanceName; private final String uriEncoding; private final boolean fixResources; @@ -147,7 +147,7 @@ } /** - * Get the URI mappings for this driver instance + * Get the URI mappings for this driver instance. * * @return The URI mappings for this driver instance. */ Modified: trunk/esigate-core/src/main/java/org/esigate/HttpErrorPage.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/HttpErrorPage.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/HttpErrorPage.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -34,98 +34,98 @@ /** * Exception thrown when an error occurred retrieving a resource. * <p> - * This exception can include a HTTP response (with error page body) or a String - * body. + * This exception can include a HTTP response (with error page body) or a String body. * * @author Francois-Xavier Bonnet * @author Nicolas Richeton */ public class HttpErrorPage extends Exception { - private static final long serialVersionUID = 1L; - private final HttpResponse httpResponse; + private static final long serialVersionUID = 1L; + private final HttpResponse httpResponse; - /** - * Create an HTTP error page exception from an Http response. - * - * @param httpResponse - * backend response. - */ - public HttpErrorPage(HttpResponse httpResponse) { - super(httpResponse.getStatusLine().getStatusCode() + " " + httpResponse.getStatusLine().getReasonPhrase()); - this.httpResponse = httpResponse; - // Consume the entity and replace it with an in memory Entity - HttpEntity httpEntity = httpResponse.getEntity(); - HttpEntity memoryEntity; - if (httpEntity != null) { - try { - byte[] content = EntityUtils.toByteArray(httpEntity); - ByteArrayEntity byteArrayEntity = new ByteArrayEntity(content, ContentType.get(httpEntity)); - Header contentEncoding = httpEntity.getContentEncoding(); - if (contentEncoding != null) - byteArrayEntity.setContentEncoding(contentEncoding); - memoryEntity = byteArrayEntity; - } catch (IOException e) { - StringBuilderWriter out = new StringBuilderWriter(512); - PrintWriter pw = new PrintWriter(out); - e.printStackTrace(pw); - pw.close(); - memoryEntity = new StringEntity(out.toString(), ContentType.getOrDefault(httpEntity)); - } - this.httpResponse.setEntity(memoryEntity); - } - } + /** + * Create an HTTP error page exception from an Http response. + * + * @param httpResponse + * backend response. + */ + public HttpErrorPage(HttpResponse httpResponse) { + super(httpResponse.getStatusLine().getStatusCode() + " " + httpResponse.getStatusLine().getReasonPhrase()); + this.httpResponse = httpResponse; + // Consume the entity and replace it with an in memory Entity + HttpEntity httpEntity = httpResponse.getEntity(); + HttpEntity memoryEntity; + if (httpEntity != null) { + try { + byte[] content = EntityUtils.toByteArray(httpEntity); + ByteArrayEntity byteArrayEntity = new ByteArrayEntity(content, ContentType.get(httpEntity)); + Header contentEncoding = httpEntity.getContentEncoding(); + if (contentEncoding != null) { + byteArrayEntity.setContentEncoding(contentEncoding); + } + memoryEntity = byteArrayEntity; + } catch (IOException e) { + StringBuilderWriter out = new StringBuilderWriter(512); + PrintWriter pw = new PrintWriter(out); + e.printStackTrace(pw); + pw.close(); + memoryEntity = new StringEntity(out.toString(), ContentType.getOrDefault(httpEntity)); + } + this.httpResponse.setEntity(memoryEntity); + } + } - /** - * Create an HTTP response from a String content wich will be used as the - * response entity. - * - * @param statusCode - * @param statusMessage - * @param content - */ - public HttpErrorPage(int statusCode, String statusMessage, String content) { - super(statusCode + " " + statusMessage); - this.httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusMessage)); - try { - this.httpResponse.setEntity(new StringEntity(content, "UTF-8")); - } catch (UnsupportedEncodingException e) { - // This should not happen as UTF-8 is always supported - throw new RuntimeException(e); - } - } + /** + * Create an HTTP response from a String content wich will be used as the response entity. + * + * @param statusCode + * @param statusMessage + * @param content + */ + public HttpErrorPage(int statusCode, String statusMessage, String content) { + super(statusCode + " " + statusMessage); + this.httpResponse = + new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusMessage)); + try { + this.httpResponse.setEntity(new StringEntity(content, "UTF-8")); + } catch (UnsupportedEncodingException e) { + // This should not happen as UTF-8 is always supported + throw new RuntimeException(e); + } + } - /** - * Create an HTTP response from an exception. This exception stack trace - * will be showed to the end user. - * - * @param statusCode - * @param statusMessage - * @param exception - */ - public HttpErrorPage(int statusCode, String statusMessage, Exception exception) { - super(statusCode + " " + statusMessage, exception); - this.httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusMessage)); - StringBuilderWriter out = new StringBuilderWriter(512); - PrintWriter pw = new PrintWriter(out); - exception.printStackTrace(pw); - String content = out.toString(); - try { - this.httpResponse.setEntity(new StringEntity(content, "UTF-8")); - } catch (UnsupportedEncodingException e) { - // This should not happen as UTF-8 is always supported - throw new RuntimeException(e); - } finally { - pw.close(); - } - } + /** + * Create an HTTP response from an exception. This exception stack trace will be showed to the end user. + * + * @param statusCode + * @param statusMessage + * @param exception + */ + public HttpErrorPage(int statusCode, String statusMessage, Exception exception) { + super(statusCode + " " + statusMessage, exception); + this.httpResponse = + new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusMessage)); + StringBuilderWriter out = new StringBuilderWriter(512); + PrintWriter pw = new PrintWriter(out); + exception.printStackTrace(pw); + String content = out.toString(); + try { + this.httpResponse.setEntity(new StringEntity(content, "UTF-8")); + } catch (UnsupportedEncodingException e) { + // This should not happen as UTF-8 is always supported + throw new RuntimeException(e); + } finally { + pw.close(); + } + } - /** - * Get HTTP response enclosed in this exception. - * - * @return HTTP response - */ - public HttpResponse getHttpResponse() { - return this.httpResponse; - } + /** + * Get HTTP response enclosed in this exception. + * + * @return HTTP response + */ + public HttpResponse getHttpResponse() { + return this.httpResponse; + } } Modified: trunk/esigate-core/src/main/java/org/esigate/Renderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Renderer.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/Renderer.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -27,18 +27,19 @@ */ public interface Renderer { - /** - * Renders provided source and writes results to the output - * - * - * @param originalRequest - * @param src - * source to be rendered - * @param out - * output destination. This writer is not thread-safe, use proper - * synchronization if writing output from multiple threads. - * @throws IOException - * @throws HttpErrorPage - */ - void render(HttpEntityEnclosingRequest originalRequest, String src, Writer out) throws IOException, HttpErrorPage; + /** + * Renders provided source and writes results to the output. + * + * + * @param originalRequest + * request received by esigate. + * @param src + * source to be rendered + * @param out + * output destination. This writer is not thread-safe, use proper synchronization if writing output from + * multiple threads. + * @throws IOException + * @throws HttpErrorPage + */ + void render(HttpEntityEnclosingRequest originalRequest, String src, Writer out) throws IOException, HttpErrorPage; } Modified: trunk/esigate-core/src/main/java/org/esigate/RequestExecutor.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/RequestExecutor.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/RequestExecutor.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -25,21 +25,21 @@ public interface RequestExecutor { - public HttpResponse createAndExecuteRequest(HttpEntityEnclosingRequest request, String url, boolean b) throws HttpErrorPage; + HttpResponse createAndExecuteRequest(HttpEntityEnclosingRequest request, String url, boolean b) throws HttpErrorPage; - public HttpResponse executeSingleRequest(GenericHttpRequest httpRequest); + HttpResponse executeSingleRequest(GenericHttpRequest httpRequest); public interface RequestExecutorBuilder { - public RequestExecutorBuilder setEventManager(EventManager eventManager); + RequestExecutorBuilder setEventManager(EventManager eventManager); - public RequestExecutorBuilder setDriver(Driver driver); + RequestExecutorBuilder setDriver(Driver driver); - public RequestExecutorBuilder setProperties(Properties properties); + RequestExecutorBuilder setProperties(Properties properties); - public RequestExecutorBuilder setContentTypeHelper(ContentTypeHelper contentTypeHelper); + RequestExecutorBuilder setContentTypeHelper(ContentTypeHelper contentTypeHelper); - public RequestExecutor build(); + RequestExecutor build(); } Modified: trunk/esigate-core/src/main/java/org/esigate/UserContext.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/UserContext.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/UserContext.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -27,10 +27,10 @@ * * @author Francois-Xavier Bonnet * @author Nicolas Richeton - * + * */ public class UserContext { - private final static String USER_KEY = "user"; + private static final String USER_KEY = "user"; private final HttpRequest httpRequest; private final String key; @@ -59,7 +59,7 @@ setAttribute(USER_KEY, user); } - /** + /* * @see java.lang.Object#toString() */ @Override Modified: trunk/esigate-core/src/main/java/org/esigate/aggregator/Adapter.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/aggregator/Adapter.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/aggregator/Adapter.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -1,6 +1,6 @@ package org.esigate.aggregator; -import java.io.IOException; +import java.io.IOException; import org.esigate.parser.Element; Modified: trunk/esigate-core/src/main/java/org/esigate/aggregator/AggregateRenderer.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/aggregator/AggregateRenderer.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/aggregator/AggregateRenderer.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -24,22 +24,18 @@ import org.esigate.Renderer; import org.esigate.parser.Parser; - /** * Parses a page to find tags to be replaced by contents from other providers. * * Sample syntax used for includes : * <ul> * <li> - * <!--$includeblock$provider$page$blockname$--><!--$endincludeblock$ - * --></li> - * <li><!--$includetemplate$provider$page$templatename$--><!-- - * $endincludetemplate$--></li> + * <!--$includeblock$provider$page$blockname$--><!--$endincludeblock$ --></li> + * <li><!--$includetemplate$provider$page$templatename$--><!-- $endincludetemplate$--></li> * <li><!--$beginput$name$--><!--$endput$--></li> * </ul> * - * Sample syntax used inside included contents for template and block - * definition: + * Sample syntax used inside included contents for template and block definition: * <ul> * <li><!--$beginblock$name$--></li> * <li><!--$begintemplate$name$--></li> @@ -50,42 +46,41 @@ * @author Francois-Xavier Bonnet */ public class AggregateRenderer implements Renderer, Appendable { - /** Generic pattern for all the tags we want to look for. */ - private final static Pattern PATTERN = Pattern.compile("<!--\\$[^>]*\\$-->"); + /** Generic pattern for all the tags we want to look for. */ + private static final Pattern PATTERN = Pattern.compile("<!--\\$[^>]*\\$-->"); - private final Parser parser = new Parser(PATTERN, - IncludeBlockElement.TYPE, IncludeTemplateElement.TYPE, PutElement.TYPE); - private Writer out; + private final Parser parser = new Parser(PATTERN, IncludeBlockElement.TYPE, IncludeTemplateElement.TYPE, + PutElement.TYPE); + private Writer out; + /** {@inheritDoc} */ + @Override + public void render(HttpEntityEnclosingRequest httpRequest, String content, Writer out) throws IOException, + HttpErrorPage { + this.out = out; + if (content == null) { + return; + } + parser.setHttpRequest(httpRequest); + parser.parse(content, this); + } - /** {@inheritDoc} */ - @Override - public void render(HttpEntityEnclosingRequest httpRequest, String content, Writer out) throws IOException, HttpErrorPage { - this.out = out; - if (content == null) { - return; - } - parser.setHttpRequest(httpRequest); - parser.parse(content, this); - } + @Override + public Appendable append(CharSequence csq) throws IOException { + out.append(csq); + return this; + } - @Override - public Appendable append(CharSequence csq) throws IOException { - out.append(csq); - return this; - } + @Override + public Appendable append(char c) throws IOException { + out.append(c); + return this; + } - @Override - public Appendable append(char c) throws IOException { - out.append(c); - return this; - } + @Override + public Appendable append(CharSequence csq, int start, int end) throws IOException { + out.append(csq, start, end); + return this; + } - @Override - public Appendable append(CharSequence csq, int start, int end) - throws IOException { - out.append(csq, start, end); - return this; - } - } Modified: trunk/esigate-core/src/main/java/org/esigate/aggregator/AggregationSyntaxException.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/aggregator/AggregationSyntaxException.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/aggregator/AggregationSyntaxException.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -1,16 +1,17 @@ package org.esigate.aggregator; - /** - * Exception thrown when an HTML document contains WAT tags with invalid - * arguments + * Exception thrown when an HTML document contains WAT tags with invalid arguments. * * @author Francois-Xavier Bonnet */ public class AggregationSyntaxException extends RuntimeException { private static final long serialVersionUID = 1L; - /** @param string Error message */ + /** + * @param string + * Error message + */ public AggregationSyntaxException(String string) { super(string); } Modified: trunk/esigate-core/src/main/java/org/esigate/aggregator/ElementAttributes.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/aggregator/ElementAttributes.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/aggregator/ElementAttributes.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -3,28 +3,30 @@ import org.esigate.Driver; /** - * Element Attributes + * Element Attributes. + * * @author athaveau */ class ElementAttributes { /** - * Driver attribut + * Driver attribut. */ private Driver driver; /** - * page attribut + * page attribut. */ private String page; - + /** - * name attribut + * name attribut. */ private String name; /** - * Constructor + * Constructor. + * * @param driver * @param page * @param name @@ -35,8 +37,6 @@ this.name = name; } - - public Driver getDriver() { return driver; } @@ -49,5 +49,4 @@ return page; } - } Modified: trunk/esigate-core/src/main/java/org/esigate/package-info.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/package-info.java 2013-10-28 12:23:41 UTC (rev 1448) +++ trunk/esigate-core/src/main/java/org/esigate/package-info.java 2013-10-28 12:32:15 UTC (rev 1449) @@ -1,7 +1,9 @@ /** - * Provides a taglib that can be used inside JSPs to define templates and blocks of content. One may choose not to use these tags and directly insert HTML comments into the pages.<br /> - * Provides as well a servlet filter to handle the user context passed by the calling application. It is not necessary to use this filter if the pages do no vary depending on the user context. - * + * Provides a taglib that can be used inside JSPs to define templates and blocks of content. + * One may choose not to use these tags and directly insert HTML comments into the pages.<br /> + * Provides as well a servlet filter to handle the user context passed by the calling application. + * It is not necessary to use this filter if the pages do no vary depending on the user context. + * */ package org.esigate; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fxb...@us...> - 2014-01-27 10:56:39
|
Revision: 1549 http://sourceforge.net/p/webassembletool/code/1549 Author: fxbonnet Date: 2014-01-27 10:56:35 +0000 (Mon, 27 Jan 2014) Log Message: ----------- 0000291: Enable ConfigReloadOnChange extension even without esigate.config system property defined https://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=291 Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java Modified: trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java 2014-01-27 10:17:49 UTC (rev 1548) +++ trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java 2014-01-27 10:56:35 UTC (rev 1549) @@ -18,10 +18,10 @@ import static org.apache.commons.lang3.StringUtils.defaultIfBlank; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -74,38 +74,15 @@ InputStream extInputStream = null; try { - // Load from environment - String envPath = System.getProperty(PROP_CONF_LOCATION); - if (envPath != null) { - try { - LOG.info("Scanning configuration {}", envPath); - inputStream = new FileInputStream(new File(envPath)); - } catch (FileNotFoundException e) { - LOG.error("Can't read file {} (from -D" + PROP_CONF_LOCATION + ")", envPath, e); - } - } + URL configUrl = getConfigUrl(); - if (inputStream == null) { - LOG.info("Scanning configuration {}", "/esigate.properties"); - inputStream = DriverFactory.class.getResourceAsStream("/esigate.properties"); - } - - // For backward compatibility - if (inputStream == null) { - LOG.info("Scanning configuration /{}/{}", DriverFactory.class.getPackage().getName().replace(".", "/"), - "driver.properties"); - inputStream = DriverFactory.class.getResourceAsStream("driver.properties"); - } - if (inputStream == null) { - LOG.info("Scanning configuration {}", "/net/webassembletool/driver.properties"); - inputStream = DriverFactory.class.getResourceAsStream("/net/webassembletool/driver.properties"); - } - - if (inputStream == null) { + if (configUrl == null) { throw new ConfigurationException("esigate.properties configuration file " + "was not found in the classpath"); } + inputStream = configUrl.openStream(); + // load driver-ext.properties if exists LOG.info("Scanning configuration {}", "/esigate-ext.properties"); extInputStream = DriverFactory.class.getClassLoader().getResourceAsStream("/esigate-ext.properties"); @@ -306,4 +283,39 @@ configure(); } } + + /** + * @return The URL of the configuration file. + */ + public static URL getConfigUrl() { + URL configUrl = null; + // Load from environment + String envPath = System.getProperty(PROP_CONF_LOCATION); + if (envPath != null) { + try { + LOG.info("Scanning configuration {}", envPath); + configUrl = new File(envPath).toURI().toURL(); + } catch (MalformedURLException e) { + LOG.error("Can't read file {} (from -D" + PROP_CONF_LOCATION + ")", envPath, e); + } + } + + if (configUrl == null) { + LOG.info("Scanning configuration {}", "/esigate.properties"); + configUrl = DriverFactory.class.getResource("/esigate.properties"); + } + + // For backward compatibility + if (configUrl == null) { + LOG.info("Scanning configuration /{}/{}", DriverFactory.class.getPackage().getName().replace(".", "/"), + "driver.properties"); + configUrl = DriverFactory.class.getResource("driver.properties"); + } + if (configUrl == null) { + LOG.info("Scanning configuration {}", "/net/webassembletool/driver.properties"); + configUrl = DriverFactory.class.getResource("/net/webassembletool/driver.properties"); + } + return configUrl; + } + } Modified: trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2014-01-27 10:17:49 UTC (rev 1548) +++ trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2014-01-27 10:56:35 UTC (rev 1549) @@ -15,6 +15,8 @@ package org.esigate.extension; import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; import java.util.Properties; import org.esigate.Driver; @@ -119,8 +121,21 @@ String envPath = System.getProperty("esigate.config"); if (envPath != null) { configuration = new File(envPath); + } else { + URL configUrl = DriverFactory.getConfigUrl(); + if (configUrl != null && "file".equalsIgnoreCase(configUrl.getProtocol())) { + try { + configuration = new File(configUrl.toURI()); + } catch (URISyntaxException e) { + LOG.error("Unable to access configuration file", e); + } + } } + if (configuration != null && configuration.exists()) { + lastModified = configuration.lastModified(); + } + // Start watcher fileWatcher.start(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fxb...@us...> - 2012-12-21 11:45:50
|
Revision: 991 http://webassembletool.svn.sourceforge.net/webassembletool/?rev=991&view=rev Author: fxbonnet Date: 2012-12-21 11:45:41 +0000 (Fri, 21 Dec 2012) Log Message: ----------- 0000141: Socket read timeout causes a stacktrace and may leak connection https://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=141 Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Driver.java trunk/esigate-core/src/main/java/org/esigate/http/HttpClientHelper.java trunk/esigate-core/src/main/java/org/esigate/http/HttpResponseUtils.java trunk/esigate-core/src/main/java/org/esigate/test/TestUtils.java Added Paths: ----------- trunk/esigate-core/src/main/java/org/esigate/http/IOExceptionHandler.java Modified: trunk/esigate-core/src/main/java/org/esigate/Driver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Driver.java 2012-12-21 11:02:03 UTC (rev 990) +++ trunk/esigate-core/src/main/java/org/esigate/Driver.java 2012-12-21 11:45:41 UTC (rev 991) @@ -250,9 +250,8 @@ * the target resource * @return the content of the url * @throws HttpErrorPage - * @throws IOException */ - protected String getResourceAsString(String url, HttpEntityEnclosingRequest originalRequest) throws HttpErrorPage, IOException { + protected String getResourceAsString(String url, HttpEntityEnclosingRequest originalRequest) throws HttpErrorPage { String result; url = VariablesResolver.replaceAllVariables(url, originalRequest); url = ResourceUtils.getHttpUrlWithQueryString(url, originalRequest, false); @@ -326,7 +325,7 @@ return httpClientHelper.execute(httpRequest); } - private HttpResponse execute(GenericHttpRequest httpRequest) throws HttpErrorPage, IOException { + private HttpResponse execute(GenericHttpRequest httpRequest) throws HttpErrorPage { HttpResponse httpResponse = executeSingleRequest(httpRequest); // Handle errors. if (httpResponse == null) { Modified: trunk/esigate-core/src/main/java/org/esigate/http/HttpClientHelper.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/http/HttpClientHelper.java 2012-12-21 11:02:03 UTC (rev 990) +++ trunk/esigate-core/src/main/java/org/esigate/http/HttpClientHelper.java 2012-12-21 11:45:41 UTC (rev 991) @@ -16,7 +16,6 @@ package org.esigate.http; import java.io.IOException; -import java.net.SocketTimeoutException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.util.Arrays; @@ -32,7 +31,6 @@ import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; -import org.apache.http.HttpVersion; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; @@ -41,9 +39,6 @@ import org.apache.http.client.params.ClientPNames; import org.apache.http.client.params.CookiePolicy; import org.apache.http.client.protocol.ClientContext; -import org.apache.http.conn.ConnectTimeoutException; -import org.apache.http.conn.ConnectionPoolTimeoutException; -import org.apache.http.conn.HttpHostConnectException; import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; @@ -52,7 +47,6 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.message.BasicHttpResponse; -import org.apache.http.message.BasicStatusLine; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.DefaultedHttpParams; import org.apache.http.params.HttpConnectionParams; @@ -257,31 +251,11 @@ result = new BasicHttpResponse(response.getStatusLine()); headerManager.copyHeaders(httpRequest, originalRequest, response, result); result.setEntity(response.getEntity()); - } catch (HttpHostConnectException e) { - int statusCode = HttpStatus.SC_BAD_GATEWAY; - String statusText = "Connection refused"; - LOG.warn(httpRequest.getRequestLine() + " -> " + statusCode + " " + statusText); - result = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); - } catch (ConnectionPoolTimeoutException e) { - int statusCode = HttpStatus.SC_GATEWAY_TIMEOUT; - String statusText = "Connection pool timeout"; - LOG.warn(httpRequest.getRequestLine() + " -> " + statusCode + " " + statusText); - result = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); - } catch (ConnectTimeoutException e) { - int statusCode = HttpStatus.SC_GATEWAY_TIMEOUT; - String statusText = "Connect timeout"; - LOG.warn(httpRequest.getRequestLine() + " -> " + statusCode + " " + statusText); - result = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); - } catch (SocketTimeoutException e) { - int statusCode = HttpStatus.SC_GATEWAY_TIMEOUT; - String statusText = "Socket timeout"; - LOG.warn(httpRequest.getRequestLine() + " -> " + statusCode + " " + statusText); - result = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); } catch (IOException e) { int statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; String statusText = "Error retrieving URL"; - LOG.warn(httpRequest.getRequestLine() + " -> " + statusCode + " " + statusText, e); - result = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); + LOG.warn(httpRequest.getRequestLine() + " -> " + statusCode + " " + statusText); + result = IOExceptionHandler.toHttpResponse(e); } // FIXME workaround for a bug in http client cache that does not // keep params in response Modified: trunk/esigate-core/src/main/java/org/esigate/http/HttpResponseUtils.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/http/HttpResponseUtils.java 2012-12-21 11:02:03 UTC (rev 990) +++ trunk/esigate-core/src/main/java/org/esigate/http/HttpResponseUtils.java 2012-12-21 11:45:41 UTC (rev 991) @@ -32,6 +32,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.impl.cookie.BrowserCompatSpec; import org.apache.http.util.EntityUtils; +import org.esigate.HttpErrorPage; import org.esigate.util.UriUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,7 +101,7 @@ } } - public static String toString(HttpResponse httpResponse) throws IOException { + public static String toString(HttpResponse httpResponse) throws HttpErrorPage { HttpEntity httpEntity = httpResponse.getEntity(); String result; if (httpEntity == null) { @@ -118,7 +119,11 @@ throw new UnsupportedContentEncodingException("Content-encoding \"" + contentEncoding + "\" is not supported"); } } - result = EntityUtils.toString(httpEntity); + try { + result = EntityUtils.toString(httpEntity); + } catch (IOException e) { + throw new HttpErrorPage(IOExceptionHandler.toHttpResponse(e)); + } } return removeSessionId(result, httpResponse); } Added: trunk/esigate-core/src/main/java/org/esigate/http/IOExceptionHandler.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/http/IOExceptionHandler.java (rev 0) +++ trunk/esigate-core/src/main/java/org/esigate/http/IOExceptionHandler.java 2012-12-21 11:45:41 UTC (rev 991) @@ -0,0 +1,60 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.esigate.http; + +import java.io.IOException; +import java.net.SocketException; +import java.net.SocketTimeoutException; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.HttpVersion; +import org.apache.http.conn.ConnectTimeoutException; +import org.apache.http.conn.ConnectionPoolTimeoutException; +import org.apache.http.conn.HttpHostConnectException; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; + +public class IOExceptionHandler { + public final static HttpResponse toHttpResponse(IOException exception) { + if (exception instanceof HttpHostConnectException) { + int statusCode = HttpStatus.SC_BAD_GATEWAY; + String statusText = "Connection refused"; + return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); + } else if (exception instanceof ConnectionPoolTimeoutException) { + int statusCode = HttpStatus.SC_GATEWAY_TIMEOUT; + String statusText = "Connection pool timeout"; + return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); + } else if (exception instanceof ConnectTimeoutException) { + int statusCode = HttpStatus.SC_GATEWAY_TIMEOUT; + String statusText = "Connect timeout"; + return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); + } else if (exception instanceof SocketTimeoutException) { + int statusCode = HttpStatus.SC_GATEWAY_TIMEOUT; + String statusText = "Socket timeout"; + return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); + } else if (exception instanceof SocketException) { + int statusCode = HttpStatus.SC_BAD_GATEWAY; + String statusText = "Socket Exception"; + return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); + } else { + int statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; + String statusText = "Error retrieving URL"; + return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusText)); + } + } + +} Property changes on: trunk/esigate-core/src/main/java/org/esigate/http/IOExceptionHandler.java ___________________________________________________________________ Added: svn:executable + * Modified: trunk/esigate-core/src/main/java/org/esigate/test/TestUtils.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/test/TestUtils.java 2012-12-21 11:02:03 UTC (rev 990) +++ trunk/esigate-core/src/main/java/org/esigate/test/TestUtils.java 2012-12-21 11:45:41 UTC (rev 991) @@ -19,7 +19,6 @@ import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpResponse; -import org.apache.http.ParseException; import org.apache.http.cookie.Cookie; import org.esigate.HttpErrorPage; import org.esigate.http.HttpResponseUtils; @@ -44,7 +43,7 @@ return mediator.getHttpResponse(); } - public final static String getResponseBodyAsString(HttpEntityEnclosingRequest request) throws ParseException, IOException { + public final static String getResponseBodyAsString(HttpEntityEnclosingRequest request) throws HttpErrorPage { MockMediator mediator = (MockMediator) HttpRequestHelper.getMediator(request); HttpResponse response = mediator.getHttpResponse(); return HttpResponseUtils.toString(response); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-03-08 10:19:57
|
Revision: 1058 http://sourceforge.net/p/webassembletool/code/1058 Author: nricheton Date: 2013-03-08 10:19:54 +0000 (Fri, 08 Mar 2013) Log Message: ----------- 0000187: Unit tests does not fire fetch events https://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=187 Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Driver.java trunk/esigate-core/src/main/java/org/esigate/http/HttpClientHelper.java Modified: trunk/esigate-core/src/main/java/org/esigate/Driver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Driver.java 2013-02-27 16:03:13 UTC (rev 1057) +++ trunk/esigate-core/src/main/java/org/esigate/Driver.java 2013-03-08 10:19:54 UTC (rev 1058) @@ -63,9 +63,10 @@ private final DriverConfiguration config; private HttpClientHelper httpClientHelper; private final List<String> parsableContentTypes; - private final EventManager eventManager = new EventManager(); + private final EventManager eventManager ; - private Driver(Properties properties, String name) { + private Driver(Properties properties, String name, EventManager eventManagerParam) { + this.eventManager = eventManagerParam; config = new DriverConfiguration(name, properties); // Load extensions. ExtensionFactory.getExtensions(properties, Parameters.EXTENSIONS, this); @@ -82,13 +83,13 @@ } public Driver(String name, Properties properties) { - this(properties, name); + this(properties, name, new EventManager()); CookieManager cookieManager = ExtensionFactory.getExtension(properties, Parameters.COOKIE_MANAGER, this); httpClientHelper = new HttpClientHelper(eventManager, cookieManager, properties); } public Driver(String name, Properties properties, HttpClientHelper httpClientHelper) { - this(properties, name); + this(properties, name, httpClientHelper.getEventManager()); this.httpClientHelper = httpClientHelper; } Modified: trunk/esigate-core/src/main/java/org/esigate/http/HttpClientHelper.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/http/HttpClientHelper.java 2013-02-27 16:03:13 UTC (rev 1057) +++ trunk/esigate-core/src/main/java/org/esigate/http/HttpClientHelper.java 2013-03-08 10:19:54 UTC (rev 1058) @@ -75,7 +75,7 @@ private final boolean preserveHost; private CookieManager cookieManager; private HttpClient httpClient; - private EventManager eventManager; + private EventManager eventManager = null; private HeaderManager headerManager; private final int connectTimeout; private final int socketTimeout; @@ -257,4 +257,13 @@ return event.httpResponse; } + /** + * Get the Event manager used to create the HttpClientHelper. + * + * @return current EventManager or null if no cacheDecorator was used. + */ + public EventManager getEventManager() { + return eventManager; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-03-20 08:13:18
|
Revision: 1084 http://sourceforge.net/p/webassembletool/code/1084 Author: nricheton Date: 2013-03-20 08:13:15 +0000 (Wed, 20 Mar 2013) Log Message: ----------- 0000195: Make AggregatorRenderer optional using esigate.properties https://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=195 Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Parameters.java trunk/esigate-core/src/main/java/org/esigate/servlet/AggregatorServlet.java Added Paths: ----------- trunk/esigate-core/src/main/java/org/esigate/extension/Aggregate.java trunk/esigate-core/src/main/java/org/esigate/extension/Esi.java Modified: trunk/esigate-core/src/main/java/org/esigate/Parameters.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2013-03-20 07:29:36 UTC (rev 1083) +++ trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2013-03-20 08:13:15 UTC (rev 1084) @@ -18,6 +18,8 @@ import org.esigate.authentication.RemoteUserAuthenticationHandler; import org.esigate.cache.BasicCacheStorage; import org.esigate.cookie.DefaultCookieManager; +import org.esigate.extension.Aggregate; +import org.esigate.extension.Esi; import org.esigate.extension.FetchLogging; import org.esigate.extension.FragmentLogging; import org.esigate.extension.ResourceFixup; @@ -75,7 +77,13 @@ public static final String ROUNDROBIN = "roundrobin"; // Extensions - public static final Parameter EXTENSIONS = new Parameter("extensions", FragmentLogging.class.getName()+","+FetchLogging.class.getName()+","+RemoteUserAuthenticationHandler.class.getName()+","+ResourceFixup.class.getName()+","+XPoweredBy.class.getName());; + public static final Parameter EXTENSIONS = new Parameter("extensions", + FragmentLogging.class.getName() + "," + + FetchLogging.class.getName() + "," + + RemoteUserAuthenticationHandler.class.getName() + "," + + ResourceFixup.class.getName() + "," + + XPoweredBy.class.getName() + "," + Esi.class.getName() + + "," + Aggregate.class.getName()); public static final Parameter FILTER = new Parameter("filter", null); @@ -97,7 +105,7 @@ // when no cache directive at all, nothing is cached by default public final static Parameter HEURISTIC_DEFAULT_LIFETIME_SECS = new Parameter("heuristicDefaultLifetimeSecs", "0"); - // Backgroung revalidation + // Background revalidation public final static Parameter STALE_WHILE_REVALIDATE = new Parameter("staleWhileRevalidate", "0"); public final static Parameter STALE_IF_ERROR = new Parameter("staleIfError", "0"); public final static Parameter MIN_ASYNCHRONOUS_WORKERS = new Parameter("minAsynchronousWorkers", "0"); Added: trunk/esigate-core/src/main/java/org/esigate/extension/Aggregate.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/Aggregate.java (rev 0) +++ trunk/esigate-core/src/main/java/org/esigate/extension/Aggregate.java 2013-03-20 08:13:15 UTC (rev 1084) @@ -0,0 +1,38 @@ +package org.esigate.extension; + +import java.util.Properties; + +import org.esigate.Driver; +import org.esigate.aggregator.AggregateRenderer; +import org.esigate.events.Event; +import org.esigate.events.EventDefinition; +import org.esigate.events.EventManager; +import org.esigate.events.IEventListener; +import org.esigate.events.impl.RenderEvent; + +/** + * This extension processes the old esigate directives based on html comments, + * like : + * <p> + * <!--$includeblock$aggregated2$block.html$myblock$--> + * </p> + * see : http://www.esigate.org/html-comments.html for complete syntax. + * + * @author Nicolas Richeton + * @deprecated These directives are replaced by the ESI syntax and extension. + */ +public class Aggregate implements Extension, IEventListener { + + public boolean event(EventDefinition id, Event event) { + RenderEvent renderEvent = (RenderEvent) event; + renderEvent.renderers.add(new AggregateRenderer()); + + // Continue processing + return true; + } + + public void init(Driver driver, Properties properties) { + driver.getEventManager().register(EventManager.EVENT_RENDER_PRE, this); + } + +} Added: trunk/esigate-core/src/main/java/org/esigate/extension/Esi.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/Esi.java (rev 0) +++ trunk/esigate-core/src/main/java/org/esigate/extension/Esi.java 2013-03-20 08:13:15 UTC (rev 1084) @@ -0,0 +1,35 @@ +package org.esigate.extension; + +import java.util.Properties; + +import org.esigate.Driver; +import org.esigate.esi.EsiRenderer; +import org.esigate.events.Event; +import org.esigate.events.EventDefinition; +import org.esigate.events.EventManager; +import org.esigate.events.IEventListener; +import org.esigate.events.impl.RenderEvent; + +/** + * This extension processes ESI directives, like : + * <p> + * <esi:include src="$(PROVIDER{cms})/news" fragment="news_1"/> + * + * + * @author Nicolas Richeton + */ +public class Esi implements Extension, IEventListener { + + public boolean event(EventDefinition id, Event event) { + RenderEvent renderEvent = (RenderEvent) event; + renderEvent.renderers.add(new EsiRenderer()); + + // Continue processing + return true; + } + + public void init(Driver driver, Properties properties) { + driver.getEventManager().register(EventManager.EVENT_RENDER_PRE, this); + } + +} Modified: trunk/esigate-core/src/main/java/org/esigate/servlet/AggregatorServlet.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/servlet/AggregatorServlet.java 2013-03-20 07:29:36 UTC (rev 1083) +++ trunk/esigate-core/src/main/java/org/esigate/servlet/AggregatorServlet.java 2013-03-20 08:13:15 UTC (rev 1084) @@ -30,8 +30,6 @@ import org.esigate.Driver; import org.esigate.DriverFactory; import org.esigate.HttpErrorPage; -import org.esigate.aggregator.AggregateRenderer; -import org.esigate.esi.EsiRenderer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -115,7 +113,7 @@ // Process ressource HttpServletMediator mediator = new HttpServletMediator(request, response, getServletContext()); try { - getDriver(targetProvider).proxy(relUrl, mediator.getHttpRequest(), new AggregateRenderer(), new EsiRenderer()); + getDriver(targetProvider).proxy(relUrl, mediator.getHttpRequest()); } catch (HttpErrorPage e) { mediator.sendResponse(e.getHttpResponse()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-03-27 14:29:20
|
Revision: 1098 http://sourceforge.net/p/webassembletool/code/1098 Author: nricheton Date: 2013-03-27 14:29:17 +0000 (Wed, 27 Mar 2013) Log Message: ----------- 0000184: Page encoding broken when charset is missing in http headers https://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=184 Renamed EncodingEvent to ReadEntityEvent Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/events/EventManager.java trunk/esigate-core/src/main/java/org/esigate/extension/HtmlCharsetProcessor.java trunk/esigate-core/src/main/java/org/esigate/http/HttpResponseUtils.java Added Paths: ----------- trunk/esigate-core/src/main/java/org/esigate/events/impl/ReadEntityEvent.java Modified: trunk/esigate-core/src/main/java/org/esigate/events/EventManager.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/events/EventManager.java 2013-03-27 14:16:22 UTC (rev 1097) +++ trunk/esigate-core/src/main/java/org/esigate/events/EventManager.java 2013-03-27 14:29:17 UTC (rev 1098) @@ -49,7 +49,7 @@ * <p> * Encoding event : response is read using the charset declared by HTTP headers. * <ul> - * <li>{@link EventManager#EVENT_ENCODING} : after reading response using the default encoding</li> + * <li>{@link EventManager#EVENT_READ_ENTITY} : after reading response using the default encoding</li> * </ul> * * @author Nicolas Richeton @@ -76,8 +76,8 @@ public static EventDefinition EVENT_RENDER_POST = new EventDefinition( "org.esigate.render-post", EventDefinition.TYPE_POST); - public static EventDefinition EVENT_ENCODING = new EventDefinition( - "org.esigate.encoding.", EventDefinition.TYPE_DEFAULT); + public static EventDefinition EVENT_READ_ENTITY = new EventDefinition( + "org.esigate.readEntity.", EventDefinition.TYPE_DEFAULT); private static final Logger LOG = LoggerFactory .getLogger(EventManager.class); Copied: trunk/esigate-core/src/main/java/org/esigate/events/impl/ReadEntityEvent.java (from rev 1095, trunk/esigate-core/src/main/java/org/esigate/events/impl/EncodingEvent.java) =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/events/impl/ReadEntityEvent.java (rev 0) +++ trunk/esigate-core/src/main/java/org/esigate/events/impl/ReadEntityEvent.java 2013-03-27 14:29:17 UTC (rev 1098) @@ -0,0 +1,22 @@ +package org.esigate.events.impl; + +import java.nio.charset.Charset; + +import org.apache.http.HttpResponse; +import org.esigate.events.Event; + +/** + * Encoding event : when a HTTP response is read as String. + * + * @author Nicolas Richeton + * + */ +public class ReadEntityEvent extends Event { + public HttpResponse httpResponse; + public String mimeType; + public Charset charset; + public byte[] rawEntityContent; + public String entityContent; +} + + Modified: trunk/esigate-core/src/main/java/org/esigate/extension/HtmlCharsetProcessor.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/HtmlCharsetProcessor.java 2013-03-27 14:16:22 UTC (rev 1097) +++ trunk/esigate-core/src/main/java/org/esigate/extension/HtmlCharsetProcessor.java 2013-03-27 14:29:17 UTC (rev 1098) @@ -10,7 +10,7 @@ import org.esigate.events.EventDefinition; import org.esigate.events.EventManager; import org.esigate.events.IEventListener; -import org.esigate.events.impl.EncodingEvent; +import org.esigate.events.impl.ReadEntityEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,23 +27,23 @@ @Override public boolean event(EventDefinition id, Event event) { - EncodingEvent encodingEvent = (EncodingEvent) event; + ReadEntityEvent readEntityEvent = (ReadEntityEvent) event; Charset charset = null; - LOG.debug("Content mime type is {}", encodingEvent.mimeType); + LOG.debug("Content mime type is {}", readEntityEvent.mimeType); // Detect on supported MIME types. - if ("text/html".equals(encodingEvent.mimeType) - || "application/xhtml+xml".equals(encodingEvent.mimeType)) { + if ("text/html".equals(readEntityEvent.mimeType) + || "application/xhtml+xml".equals(readEntityEvent.mimeType)) { LOG.debug("Supported MIME type, parsing content"); - Matcher m = PATTERN_META_HTML5.matcher(encodingEvent.entityContent); + Matcher m = PATTERN_META_HTML5.matcher(readEntityEvent.entityContent); if (m.matches()) { LOG.debug("Found HTML5 charset"); charset = Charset.forName(m.group(1)); } - m = PATTERN_META_HTML4_XHTML.matcher(encodingEvent.entityContent); + m = PATTERN_META_HTML4_XHTML.matcher(readEntityEvent.entityContent); if (m.matches()) { LOG.debug("Found HTML/XHTML charset"); charset = Charset.forName(m.group(1)); @@ -51,12 +51,12 @@ } // If another charset was found, update String object - if (charset != null && !charset.equals(encodingEvent.charset)) { - LOG.debug("Changing charset fom {} to {}", encodingEvent.charset, + if (charset != null && !charset.equals(readEntityEvent.charset)) { + LOG.debug("Changing charset fom {} to {}", readEntityEvent.charset, charset); - encodingEvent.charset = charset; - encodingEvent.entityContent = new String(encodingEvent.rawEntityContent, - encodingEvent.charset); + readEntityEvent.charset = charset; + readEntityEvent.entityContent = new String(readEntityEvent.rawEntityContent, + readEntityEvent.charset); } return true; @@ -64,7 +64,7 @@ @Override public void init(Driver driver, Properties properties) { - driver.getEventManager().register(EventManager.EVENT_ENCODING, this); + driver.getEventManager().register(EventManager.EVENT_READ_ENTITY, this); } } Modified: trunk/esigate-core/src/main/java/org/esigate/http/HttpResponseUtils.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/http/HttpResponseUtils.java 2013-03-27 14:16:22 UTC (rev 1097) +++ trunk/esigate-core/src/main/java/org/esigate/http/HttpResponseUtils.java 2013-03-27 14:29:17 UTC (rev 1098) @@ -37,7 +37,7 @@ import org.apache.http.util.EntityUtils; import org.esigate.HttpErrorPage; import org.esigate.events.EventManager; -import org.esigate.events.impl.EncodingEvent; +import org.esigate.events.impl.ReadEntityEvent; import org.esigate.util.UriUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -129,7 +129,7 @@ } try { - EncodingEvent event = new EncodingEvent(); + ReadEntityEvent event = new ReadEntityEvent(); event.rawEntityContent = EntityUtils.toByteArray(httpEntity); try { @@ -152,7 +152,7 @@ // Allow extensions to detect document encoding if (eventManager != null) { - eventManager.fire(EventManager.EVENT_ENCODING, event); + eventManager.fire(EventManager.EVENT_READ_ENTITY, event); } // Return entityContent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-06-14 06:51:28
|
Revision: 1161 http://sourceforge.net/p/webassembletool/code/1161 Author: nricheton Date: 2013-06-14 06:51:25 +0000 (Fri, 14 Jun 2013) Log Message: ----------- 0000175: Externalize Provider configuration. https://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=175 Default error page when no mapping are defined Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java trunk/esigate-core/src/main/java/org/esigate/Parameters.java trunk/esigate-core/src/main/java/org/esigate/servlet/impl/DriverSelector.java Added Paths: ----------- trunk/esigate-core/src/main/java/org/esigate/extension/ErrorPages.java Modified: trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java 2013-06-13 05:52:00 UTC (rev 1160) +++ trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java 2013-06-14 06:51:25 UTC (rev 1161) @@ -143,6 +143,9 @@ */ public final static void configure(Properties props) { Properties defaultProperties = new Properties(); + // Error page if default provider is not configured. + defaultProperties.put( Parameters.REMOTE_URL_BASE.name, "http://esigate/no-mapping/"); + HashMap<String, Properties> driversProps = new HashMap<String, Properties>(); for (Enumeration<?> enumeration = props.propertyNames(); enumeration.hasMoreElements();) { String propertyName = (String) enumeration.nextElement(); Modified: trunk/esigate-core/src/main/java/org/esigate/Parameters.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2013-06-13 05:52:00 UTC (rev 1160) +++ trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2013-06-14 06:51:25 UTC (rev 1161) @@ -19,6 +19,7 @@ import org.esigate.cache.BasicCacheStorage; import org.esigate.cookie.DefaultCookieManager; import org.esigate.extension.Aggregate; +import org.esigate.extension.ErrorPages; import org.esigate.extension.Esi; import org.esigate.extension.FetchLogging; import org.esigate.extension.FragmentLogging; @@ -81,6 +82,7 @@ public static final Parameter EXTENSIONS = new Parameter("extensions", FragmentLogging.class.getName() + "," + FetchLogging.class.getName() + "," + + ErrorPages.class.getName() + "," + RemoteUserAuthenticationHandler.class.getName() + "," + Esi.class.getName() + "," + Aggregate.class.getName() + "," + ResourceFixup.class.getName() + "," Added: trunk/esigate-core/src/main/java/org/esigate/extension/ErrorPages.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/ErrorPages.java (rev 0) +++ trunk/esigate-core/src/main/java/org/esigate/extension/ErrorPages.java 2013-06-14 06:51:25 UTC (rev 1161) @@ -0,0 +1,72 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.esigate.extension; + +import java.util.Properties; + +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.esigate.Driver; +import org.esigate.events.Event; +import org.esigate.events.EventDefinition; +import org.esigate.events.EventManager; +import org.esigate.events.IEventListener; +import org.esigate.events.impl.FragmentEvent; +import org.esigate.test.http.HttpResponseBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This extension handles internal error pages served directly by esigate. + * <p> + * Supported pages : + * <ul> + * <li>http://esigate/no-mapping/</li> + * </ul> + * + * @author Nicolas Richeton + * + */ +public class ErrorPages implements Extension, IEventListener { + + private static final StringEntity NO_MAPPING = new StringEntity( + "<html><body><h1>Esigate cannot process this request.</h1><h2>No mapping defined for this url.</h2></body></html>", + ContentType.create("text/html", "utf-8")); + private static final Logger LOG = LoggerFactory.getLogger(ErrorPages.class); + + @Override + public void init(Driver driver, Properties properties) { + driver.getEventManager().register(EventManager.EVENT_FRAGMENT_PRE, this); + } + + @Override + public boolean event(EventDefinition id, Event event) { + + FragmentEvent e = (FragmentEvent) event; + + if (EventManager.EVENT_FRAGMENT_PRE.equals(id)) { + LOG.error(e.httpRequest.getRequestLine().getUri()); + if ("http://esigate/no-mapping/".equals(e.httpRequest.getRequestLine().getUri())) { + e.httpResponse = new HttpResponseBuilder().status(404).reason("No mapping defined").entity(NO_MAPPING) + .build(); + return false; + } + } + + // Continue processing + return true; + } +} Modified: trunk/esigate-core/src/main/java/org/esigate/servlet/impl/DriverSelector.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/servlet/impl/DriverSelector.java 2013-06-13 05:52:00 UTC (rev 1160) +++ trunk/esigate-core/src/main/java/org/esigate/servlet/impl/DriverSelector.java 2013-06-14 06:51:25 UTC (rev 1161) @@ -110,19 +110,9 @@ * the very first hit to Esigate (instead of 'on startup'). */ public void touchDriverFactory() { - - // Using getDriver() instead of DriverFactory#configure() to prevent + // Using DriverFactory.getInstance() instead of DriverFactory#configure() to prevent // multiple configuration loading if several servlets are used + DriverFactory.getInstance(); - if (this.webXmlProvider != null) { - // Get defined provider - DriverFactory.getInstance(this.webXmlProvider); - } else if (this.webXmlProviderMappings != null && this.webXmlProviderMappings.size() > 0) { - // Get provider for the first mapping - DriverFactory.getInstance(this.webXmlProviderMappings.values().iterator().next()); - } else { - // Get default provider - // DriverFactory.getInstanceFor(null, null, "/"); - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-07-21 16:26:24
|
Revision: 1248 http://sourceforge.net/p/webassembletool/code/1248 Author: nricheton Date: 2013-07-21 16:26:21 +0000 (Sun, 21 Jul 2013) Log Message: ----------- 0000244: PROXY_POST is not fired on error http://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=244 0000076: Redesign / document EsiGate entry points (extensions) http://sourceforge.net/apps/mantisbt/webassembletool/view.php?id=76 Ability to replace error page or response at the very end of the request processing Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Driver.java trunk/esigate-core/src/main/java/org/esigate/events/impl/ProxyEvent.java Modified: trunk/esigate-core/src/main/java/org/esigate/Driver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Driver.java 2013-07-21 16:21:28 UTC (rev 1247) +++ trunk/esigate-core/src/main/java/org/esigate/Driver.java 2013-07-21 16:26:21 UTC (rev 1248) @@ -67,11 +67,12 @@ private Driver(Properties properties, String name, EventManager eventManagerParam) { this.eventManager = eventManagerParam; - config = new DriverConfiguration(name, properties); + this.config = new DriverConfiguration(name, properties); + this.parsableContentTypes = Parameters.PARSABLE_CONTENT_TYPES.getValueList(properties); + // Load extensions. ExtensionFactory.getExtensions(properties, Parameters.EXTENSIONS, this); - parsableContentTypes = Parameters.PARSABLE_CONTENT_TYPES.getValueList(properties); } public Driver(String name, Properties properties) { @@ -85,6 +86,11 @@ this.httpClientHelper = httpClientHelper; } + /** + * Get current event manager for this driver instance. + * + * @return event manager. + */ public EventManager getEventManager() { return this.eventManager; } @@ -158,13 +164,27 @@ rendererNames }); } + /** + * Set request context informations as request parameters. + * <p> + * + * @see HttpRequest#setParams(org.apache.http.params.HttpParams) + * @param request + * the HTTP request + * @param parameters + * Additional parameters (other than the ones included in the + * request itself). + * @throws HttpErrorPage + * if url base for this request is invalid (remoteBaseUrl or + * baseUrlRetriveStrategy). + */ public void initHttpRequestParams(HttpRequest request, Map<String, String> parameters) throws HttpErrorPage { HttpRequestHelper.setDriver(request, this); HttpRequestHelper.setParameters(request, parameters); - UserContext userContext = new UserContext(request, config.getInstanceName()); + UserContext userContext = new UserContext(request, this.config.getInstanceName()); HttpRequestHelper.setUserContext(request, userContext); try { - URL baseUrl = new URL(config.getBaseUrlRetrieveStrategy().getBaseURL(request)); + URL baseUrl = new URL(this.config.getBaseUrlRetrieveStrategy().getBaseURL(request)); HttpRequestHelper.setBaseUrl(request, baseUrl); } catch (MalformedURLException e) { throw new HttpErrorPage(500, "Internal server error", e); @@ -188,49 +208,66 @@ */ public void proxy(String relUrl, HttpEntityEnclosingRequest request, Renderer... renderers) throws IOException, HttpErrorPage { - initHttpRequestParams(request, null); + // 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; - if (LOG.isInfoEnabled()) { - logAction("render", relUrl, renderers); - } - - HttpRequestHelper.setCharacterEncoding(request, config.getUriEncoding()); - // Create Proxy event ProxyEvent e = new ProxyEvent(); e.originalRequest = request; - // Event pre-proxy - eventManager.fire(EventManager.EVENT_PROXY_PRE, e); + try { + // Event pre-proxy + this.eventManager.fire(EventManager.EVENT_PROXY_PRE, e); + // Return immediately if exit is requested by extension + if (e.exit) { + return; + } - // Return immediately if exit is requested by extension - if (e.exit) { - return; - } + if (LOG.isInfoEnabled()) { + logAction("proxy", relUrl, renderers); + } - String url = ResourceUtils.getHttpUrlWithQueryString(relUrl, e.originalRequest, true); - GenericHttpRequest httpRequest = httpClientHelper.createHttpRequest(request, url, true); + initHttpRequestParams(request, null); + HttpRequestHelper.setCharacterEncoding(request, this.config.getUriEncoding()); + String url = ResourceUtils.getHttpUrlWithQueryString(relUrl, e.originalRequest, true); + GenericHttpRequest httpRequest = this.httpClientHelper.createHttpRequest(request, url, true); + e.response = execute(httpRequest); - try { - // Execute request - HttpResponse httpResponse = execute(httpRequest); - // Perform rendering - httpResponse = performRendering(relUrl, request, httpResponse, renderers); + e.response = performRendering(relUrl, request, e.response, 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. - HttpRequestHelper.getMediator(request).sendResponse(httpResponse); + HttpRequestHelper.getMediator(request).sendResponse(e.response); } catch (HttpErrorPage errorPage) { + e.errorPage = errorPage; + // On error returned by the proxy request, perform rendering on the // error page. - HttpResponse errorResponse = errorPage.getHttpResponse(); - errorResponse = performRendering(relUrl, request, errorResponse, renderers); - throw new HttpErrorPage(errorResponse); + e.errorPage = new HttpErrorPage(performRendering(relUrl, request, e.errorPage.getHttpResponse(), 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.errorPage; + } finally { + if (!postProxyPerformed) { + this.eventManager.fire(EventManager.EVENT_PROXY_POST, e); + } } - - // Event post-proxy - eventManager.fire(EventManager.EVENT_PROXY_POST, e); } /** @@ -323,8 +360,8 @@ } /** - * This method returns the content of an url as a String. The result - * is cached into the request scope in order not to send several requests if + * This method returns the content of an url as a String. The result is + * cached into the request scope in order not to send several requests if * you need several blocks in the same page to build the final page. * * @param url @@ -423,10 +460,29 @@ return false; } + /** + * Execute a HTTP request + * <p> + * No special handling. + * + * @param httpRequest + * HTTP request to execute. + * @return HTTP response. + */ public HttpResponse executeSingleRequest(GenericHttpRequest httpRequest) { - return httpClientHelper.execute(httpRequest); + return this.httpClientHelper.execute(httpRequest); } + /** + * Execute a HTTP request and handle errors as HttpErrorPage exceptions. + * + * @param httpRequest + * HTTP request to execute. + * @return HTTP response + * @throws HttpErrorPage + * if server returned no response or if the response as an error + * status code. + */ private HttpResponse execute(GenericHttpRequest httpRequest) throws HttpErrorPage { HttpResponse httpResponse = executeSingleRequest(httpRequest); // Handle errors. Modified: trunk/esigate-core/src/main/java/org/esigate/events/impl/ProxyEvent.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/events/impl/ProxyEvent.java 2013-07-21 16:21:28 UTC (rev 1247) +++ trunk/esigate-core/src/main/java/org/esigate/events/impl/ProxyEvent.java 2013-07-21 16:26:21 UTC (rev 1248) @@ -16,10 +16,13 @@ package org.esigate.events.impl; import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.esigate.HttpErrorPage; import org.esigate.events.Event; /** - * Proxy Event : Requests received by ESIGate in proxy mode ( standalone application). + * Proxy Event : Requests received by ESIGate in proxy mode ( standalone + * application). * * @author Nicolas Richeton * @@ -29,4 +32,16 @@ * The request which was received by ESIgate. */ public HttpRequest originalRequest; + + /** + * The current response. May be null if no reponse has be created yet or in + * case of error. + */ + public HttpResponse response = null; + + /** + * The current error page. If not null, an error as occured and the error + * page will be sent instead of the response. + */ + public HttpErrorPage errorPage = null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nri...@us...> - 2013-10-28 11:24:32
|
Revision: 1441 http://sourceforge.net/p/webassembletool/code/1441 Author: nricheton Date: 2013-10-28 11:24:29 +0000 (Mon, 28 Oct 2013) Log Message: ----------- Cleanup Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/test/http/HttpRequestBuilder.java trunk/esigate-core/src/main/java/org/esigate/test/http/HttpResponseBuilder.java trunk/esigate-core/src/main/java/org/esigate/url/IpHashBaseUrlRetrieveStrategy.java trunk/esigate-core/src/main/java/org/esigate/url/RoundRobinBaseUrlRetrieveStrategy.java trunk/esigate-core/src/main/java/org/esigate/url/SingleBaseUrlRetrieveStrategy.java trunk/esigate-core/src/main/java/org/esigate/url/StickySessionBaseUrlRetrieveStrategy.java Modified: trunk/esigate-core/src/main/java/org/esigate/test/http/HttpRequestBuilder.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/test/http/HttpRequestBuilder.java 2013-10-28 11:19:11 UTC (rev 1440) +++ trunk/esigate-core/src/main/java/org/esigate/test/http/HttpRequestBuilder.java 2013-10-28 11:24:29 UTC (rev 1441) @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ package org.esigate.test.http; import java.net.URI; @@ -32,63 +46,16 @@ * */ public class HttpRequestBuilder { - ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); - String uriString = "http://localhost/"; - List<Header> headers = new ArrayList<Header>(); - List<Cookie> cookies = new ArrayList<Cookie>(); - HttpEntity entity = null; + private ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); + private String uriString = "http://localhost/"; + private final List<Header> headers = new ArrayList<Header>(); + private final List<Cookie> cookies = new ArrayList<Cookie>(); + private HttpEntity entity = null; private String method = "GET"; - boolean mockMediator = false; - ContainerRequestMediator mediator = null; + private boolean mockMediator = false; + private ContainerRequestMediator mediator = null; - public HttpRequestBuilder uri(String uri) { - this.uriString = uri; - return this; - } - - public HttpRequestBuilder header(String name, String value) { - this.headers.add(new BasicHeader(name, value)); - return this; - } - - public HttpRequestBuilder method(String paramMethod) { - this.method = paramMethod; - return this; - } - - public HttpRequestBuilder protocolVersion(ProtocolVersion paramProtocolVersion) { - this.protocolVersion = paramProtocolVersion; - return this; - } - - public HttpRequestBuilder cookie(String name, String value) { - this.cookies.add(new BasicClientCookie(name, value)); - return this; - } - - public HttpRequestBuilder entity(HttpEntity paramEntity) { - this.entity = paramEntity; - return this; - } - - public HttpRequestBuilder mockMediator() { - - if (this.mediator != null) - throw new IllegalArgumentException("Cannot use both mockMediator and mediator when building HttpRequest"); - - this.mockMediator = true; - return this; - } - - public HttpRequestBuilder mediator(ContainerRequestMediator paramMediator) { - if (this.mockMediator) - throw new IllegalArgumentException("Cannot use both mockMediator and mediator when building HttpRequest"); - - this.mediator = paramMediator; - return this; - } - /** * Build the request as defined in the current builder. * @@ -101,10 +68,11 @@ String host = uri.getHost(); int port = uri.getPort(); request = new BasicHttpEntityEnclosingRequest(this.method, this.uriString, this.protocolVersion); - if (port == -1 || (port == 80 && "http".equals(scheme)) || (port == 443 && "https".equals(scheme))) + if (port == -1 || port == 80 && "http".equals(scheme) || port == 443 && "https".equals(scheme)) { request.setHeader("Host", host); - else + } else { request.setHeader("Host", host + ":" + port); + } for (Header h : this.headers) { request.addHeader(h.getName(), h.getValue()); @@ -115,13 +83,15 @@ } ContainerRequestMediator requestMediator = null; - if (this.mockMediator) + if (this.mockMediator) { requestMediator = new MockMediator(this.uriString); + } - if (this.mediator != null) + if (this.mediator != null) { requestMediator = this.mediator; + } - // Add cookies + // Add cookies // In request header String cookieHeaderValue = StringUtils.EMPTY; for (Cookie c : this.cookies) { @@ -144,4 +114,53 @@ return request; } + + public HttpRequestBuilder cookie(String name, String value) { + this.cookies.add(new BasicClientCookie(name, value)); + return this; + } + + public HttpRequestBuilder entity(HttpEntity paramEntity) { + this.entity = paramEntity; + return this; + } + + public HttpRequestBuilder header(String name, String value) { + this.headers.add(new BasicHeader(name, value)); + return this; + } + + public HttpRequestBuilder mediator(ContainerRequestMediator paramMediator) { + if (this.mockMediator) { + throw new IllegalArgumentException("Cannot use both mockMediator and mediator when building HttpRequest"); + } + + this.mediator = paramMediator; + return this; + } + + public HttpRequestBuilder method(String paramMethod) { + this.method = paramMethod; + return this; + } + + public HttpRequestBuilder mockMediator() { + + if (this.mediator != null) { + throw new IllegalArgumentException("Cannot use both mockMediator and mediator when building HttpRequest"); + } + + this.mockMediator = true; + return this; + } + + public HttpRequestBuilder protocolVersion(ProtocolVersion paramProtocolVersion) { + this.protocolVersion = paramProtocolVersion; + return this; + } + + public HttpRequestBuilder uri(String uri) { + this.uriString = uri; + return this; + } } Modified: trunk/esigate-core/src/main/java/org/esigate/test/http/HttpResponseBuilder.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/test/http/HttpResponseBuilder.java 2013-10-28 11:19:11 UTC (rev 1440) +++ trunk/esigate-core/src/main/java/org/esigate/test/http/HttpResponseBuilder.java 2013-10-28 11:24:29 UTC (rev 1441) @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ package org.esigate.test.http; import java.io.UnsupportedEncodingException; @@ -28,32 +42,25 @@ */ public class HttpResponseBuilder { - ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); - int status = HttpStatus.SC_OK; - String reason = "Ok"; - List<Header> headers = new ArrayList<Header>(); - HttpEntity entity = null; + private ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); + private int status = HttpStatus.SC_OK; + private String reason = "Ok"; + private List<Header> headers = new ArrayList<Header>(); + private HttpEntity entity = null; - public HttpResponseBuilder protocolVersion(ProtocolVersion paramProtocolVersion) { - this.protocolVersion = paramProtocolVersion; - return this; - } + public HttpResponse build() { + BasicHttpResponse response = new BasicHttpResponse(this.protocolVersion, this.status, this.reason); - public HttpResponseBuilder status(int paramStatus) { - this.status = paramStatus; - return this; - } + for (Header h : this.headers) { + response.addHeader(h.getName(), h.getValue()); + } - public HttpResponseBuilder reason(String paramReason) { - this.reason = paramReason; - return this; + if (this.entity != null) { + response.setEntity(this.entity); + } + return response; } - public HttpResponseBuilder header(String name, String value) { - this.headers.add(new BasicHeader(name, value)); - return this; - } - public HttpResponseBuilder entity(HttpEntity paramEntity) { this.entity = paramEntity; if (this.entity.getContentType() != null) { @@ -67,16 +74,23 @@ return this; } - public HttpResponse build() { - BasicHttpResponse response = new BasicHttpResponse(this.protocolVersion, this.status, this.reason); + public HttpResponseBuilder header(String name, String value) { + this.headers.add(new BasicHeader(name, value)); + return this; + } - for (Header h : this.headers) { - response.addHeader(h.getName(), h.getValue()); - } + public HttpResponseBuilder protocolVersion(ProtocolVersion paramProtocolVersion) { + this.protocolVersion = paramProtocolVersion; + return this; + } - if (this.entity != null) { - response.setEntity(this.entity); - } - return response; + public HttpResponseBuilder reason(String paramReason) { + this.reason = paramReason; + return this; } + + public HttpResponseBuilder status(int paramStatus) { + this.status = paramStatus; + return this; + } } Modified: trunk/esigate-core/src/main/java/org/esigate/url/IpHashBaseUrlRetrieveStrategy.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/url/IpHashBaseUrlRetrieveStrategy.java 2013-10-28 11:19:11 UTC (rev 1440) +++ trunk/esigate-core/src/main/java/org/esigate/url/IpHashBaseUrlRetrieveStrategy.java 2013-10-28 11:24:29 UTC (rev 1441) @@ -12,7 +12,6 @@ * limitations under the License. * */ - package org.esigate.url; import org.apache.http.HttpRequest; @@ -28,14 +27,14 @@ @Override public String getBaseURL(HttpRequest originalRequest) { - int index = getHashCode(HttpRequestHelper.getMediator(originalRequest).getRemoteAddr()) % urls.length; - return urls[Math.abs(index)]; + int index = getHashCode(HttpRequestHelper.getMediator(originalRequest).getRemoteAddr()) % this.urls.length; + return this.urls[Math.abs(index)]; } private int getHashCode(String ip) { final int prime = 31; int result = 1; - result = prime * result + ((ip == null) ? 0 : ip.hashCode()); + result = prime * result + (ip == null ? 0 : ip.hashCode()); return result; } Modified: trunk/esigate-core/src/main/java/org/esigate/url/RoundRobinBaseUrlRetrieveStrategy.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/url/RoundRobinBaseUrlRetrieveStrategy.java 2013-10-28 11:19:11 UTC (rev 1440) +++ trunk/esigate-core/src/main/java/org/esigate/url/RoundRobinBaseUrlRetrieveStrategy.java 2013-10-28 11:24:29 UTC (rev 1441) @@ -30,8 +30,8 @@ @Override public String getBaseURL(HttpRequest originalRequest) { - int incremented = counter.incrementAndGet(); - int index = incremented % urls.length; - return urls[Math.abs(index)]; + int incremented = this.counter.incrementAndGet(); + int index = incremented % this.urls.length; + return this.urls[Math.abs(index)]; } } Modified: trunk/esigate-core/src/main/java/org/esigate/url/SingleBaseUrlRetrieveStrategy.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/url/SingleBaseUrlRetrieveStrategy.java 2013-10-28 11:19:11 UTC (rev 1440) +++ trunk/esigate-core/src/main/java/org/esigate/url/SingleBaseUrlRetrieveStrategy.java 2013-10-28 11:24:29 UTC (rev 1441) @@ -28,7 +28,7 @@ @Override public String getBaseURL(HttpRequest originalRequest) { - return baseUrl; + return this.baseUrl; } } Modified: trunk/esigate-core/src/main/java/org/esigate/url/StickySessionBaseUrlRetrieveStrategy.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/url/StickySessionBaseUrlRetrieveStrategy.java 2013-10-28 11:19:11 UTC (rev 1440) +++ trunk/esigate-core/src/main/java/org/esigate/url/StickySessionBaseUrlRetrieveStrategy.java 2013-10-28 11:24:29 UTC (rev 1441) @@ -31,6 +31,10 @@ this.urls = urls; } + private int generateIndex() { + return (int) (Math.random() * this.urls.length); + } + @Override public String getBaseURL(HttpRequest originalRequest) { ContainerRequestMediator mediator = HttpRequestHelper.getMediator(originalRequest); @@ -49,7 +53,7 @@ } catch (Exception e) { index = -1; } - if (index < 0 || index >= urls.length) { + if (index < 0 || index >= this.urls.length) { toGenerate = true; } } else { @@ -62,13 +66,9 @@ mediator.addCookie(cookie); } - return urls[index]; + return this.urls[index]; } - private int generateIndex() { - return (int) (Math.random() * urls.length); - } - private Cookie getEsiSessionCookie(Cookie[] cookies) { Cookie ret = null; if (null != cookies && cookies.length > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ath...@us...> - 2014-03-27 13:39:57
|
Revision: 1589 http://sourceforge.net/p/webassembletool/code/1589 Author: athaveau Date: 2014-03-27 13:39:53 +0000 (Thu, 27 Mar 2014) Log Message: ----------- Checkstyle issues Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/Parameters.java trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java trunk/esigate-core/src/main/java/org/esigate/extension/DefaultCharset.java trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java trunk/esigate-core/src/main/java/org/esigate/extension/monitoring/Metric.java Modified: trunk/esigate-core/src/main/java/org/esigate/Parameters.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2014-03-27 13:25:10 UTC (rev 1588) +++ trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2014-03-27 13:39:53 UTC (rev 1589) @@ -65,7 +65,8 @@ public static final Parameter<String> COOKIE_MANAGER = new ParameterString("cookieManager", DefaultCookieManager.class.getName()); public static final Parameter<Collection<String>> DISCARD_COOKIES = new ParameterCollection("discardCookies"); - public static final Parameter<Collection<String>> STORE_COOKIES_IN_SESSION = new ParameterCollection("storeCookiesInSession"); + public static final Parameter<Collection<String>> STORE_COOKIES_IN_SESSION + = new ParameterCollection("storeCookiesInSession"); public static final Parameter<String> FIX_MODE = new ParameterString("fixMode", "relative"); public static final Parameter<String> VISIBLE_URL_BASE = new ParameterString("visibleUrlBase"); // Possible values for remoteUrlBaseStrategy @@ -84,18 +85,21 @@ public static final Parameter<Boolean> USE_CACHE = new ParameterBoolean("useCache", true); public static final Parameter<Integer> MAX_CACHE_ENTRIES = new ParameterInteger("maxCacheEntries", 1000); public static final Parameter<Integer> MAX_OBJECT_SIZE = new ParameterInteger("maxObjectSize", 1000000); - public static final Parameter<String> CACHE_STORAGE = new ParameterString("cacheStorage", BasicCacheStorage.class.getName()); + public static final Parameter<String> CACHE_STORAGE + = new ParameterString("cacheStorage", BasicCacheStorage.class.getName()); public static final Parameter<Boolean> X_CACHE_HEADER = new ParameterBoolean("xCacheHeader", false); public static final Parameter<Boolean> VIA_HEADER = new ParameterBoolean("viaHeader", true); // Forced caching public static final Parameter<Integer> TTL = new ParameterInteger("ttl", 0); // Heuristic caching - public static final Parameter<Boolean> HEURISTIC_CACHING_ENABLED = new ParameterBoolean("heuristicCachingEnabled", true); + public static final Parameter<Boolean> HEURISTIC_CACHING_ENABLED + = new ParameterBoolean("heuristicCachingEnabled", true); // default value defined in // http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.2.4 public static final Parameter<Float> HEURISTIC_COEFFICIENT = new ParameterFloat("heuristicCoefficient", 0.1f); // when no cache directive at all, nothing is cached by default - public static final Parameter<Integer> HEURISTIC_DEFAULT_LIFETIME_SECS = new ParameterInteger("heuristicDefaultLifetimeSecs", 0); + public static final Parameter<Integer> HEURISTIC_DEFAULT_LIFETIME_SECS + = new ParameterInteger("heuristicDefaultLifetimeSecs", 0); // Background revalidation public static final Parameter<Integer> STALE_WHILE_REVALIDATE = new ParameterInteger("staleWhileRevalidate", 0); public static final Parameter<Integer> STALE_IF_ERROR = new ParameterInteger("staleIfError", 0); @@ -106,10 +110,13 @@ public static final Parameter<Integer> MAX_UPDATE_RETRIES = new ParameterInteger("maxUpdateRetries", 1); public static final Parameter<Integer> REVALIDATION_QUEUE_SIZE = new ParameterInteger("revalidationQueueSize", 100); // EhCache - public static final Parameter<String> EHCACHE_CACHE_NAME_PROPERTY = new ParameterString("ehcache.cacheName", "esigate"); - public static final Parameter<String> EHCACHE_CONFIGURATION_FILE_PROPERTY = new ParameterString("ehcache.configurationFile"); + public static final Parameter<String> EHCACHE_CACHE_NAME_PROPERTY + = new ParameterString("ehcache.cacheName", "esigate"); + public static final Parameter<String> EHCACHE_CONFIGURATION_FILE_PROPERTY + = new ParameterString("ehcache.configurationFile"); // MemCached - public static final Parameter<Collection<String>> MEMCACHED_SERVERS_PROPERTY = new ParameterCollection("memcached.servers"); + public static final Parameter<Collection<String>> MEMCACHED_SERVERS_PROPERTY + = new ParameterCollection("memcached.servers"); // Default size for String or byte buffers used to manipulate html page contents public static final int DEFAULT_BUFFER_SIZE = 1024; // Default size for String or byte buffers used to manipulate small things like tags, cookie, log lines Modified: trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java 2014-03-27 13:25:10 UTC (rev 1588) +++ trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java 2014-03-27 13:39:53 UTC (rev 1589) @@ -50,6 +50,10 @@ private boolean xCacheHeader; private boolean viaHeader; + /** + * Inititalize the instance + * @param properties properties + */ public void init(Properties properties) { staleIfError = Parameters.STALE_IF_ERROR.getValue(properties); staleWhileRevalidate = Parameters.STALE_WHILE_REVALIDATE.getValue(properties); Modified: trunk/esigate-core/src/main/java/org/esigate/extension/DefaultCharset.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/DefaultCharset.java 2014-03-27 13:25:10 UTC (rev 1588) +++ trunk/esigate-core/src/main/java/org/esigate/extension/DefaultCharset.java 2014-03-27 13:39:53 UTC (rev 1589) @@ -43,7 +43,7 @@ */ public class DefaultCharset implements Extension, IEventListener { private static final Logger LOG = LoggerFactory.getLogger(DefaultCharset.class); - + /** default charset */ public static final Parameter<String> PARAM_DEFAULT_CHARSET = new ParameterString("defaultCharset", "ISO-8859-1"); private Collection<String> parsableContentTypes; Modified: trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java 2014-03-27 13:25:10 UTC (rev 1588) +++ trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java 2014-03-27 13:39:53 UTC (rev 1589) @@ -43,9 +43,9 @@ /** * Get an extension as configured in properties. * - * @param properties - * @param parameter - * @param d + * @param properties properties + * @param parameter the class name parameter + * @param d driver * * @param <T> * class which extends Extension class which extends Extension @@ -81,7 +81,8 @@ * @param d * @return the extension list */ - public static <T extends Extension> List<T> getExtensions(Properties properties, Parameter<Collection<String>> parameter, Driver d) { + public static <T extends Extension> List<T> getExtensions(Properties properties, + Parameter<Collection<String>> parameter, Driver d) { Collection<String> className = parameter.getValue(properties); List<T> finalResult = new ArrayList<T>(); for (String cName : className) { Modified: trunk/esigate-core/src/main/java/org/esigate/extension/monitoring/Metric.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/monitoring/Metric.java 2014-03-27 13:25:10 UTC (rev 1588) +++ trunk/esigate-core/src/main/java/org/esigate/extension/monitoring/Metric.java 2014-03-27 13:39:53 UTC (rev 1589) @@ -56,12 +56,12 @@ private Driver driver; @Override - public void init(Driver driver, Properties properties) { + public void init(Driver d, Properties properties) { LOG.debug("Initialize Metric"); driver.getEventManager().register(EventManager.EVENT_PROXY_POST, this); driver.getEventManager().register(EventManager.EVENT_FETCH_POST, this); - this.driver = driver; + this.driver = d; reporter = Slf4jReporter .forRegistry(this.metric) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ath...@us...> - 2014-04-17 08:05:43
|
Revision: 1596 http://sourceforge.net/p/webassembletool/code/1596 Author: athaveau Date: 2014-04-17 08:05:40 +0000 (Thu, 17 Apr 2014) Log Message: ----------- #305 : hot reload variables Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java trunk/esigate-core/src/main/java/org/esigate/vars/VariablesResolver.java Modified: trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2014-04-14 11:42:15 UTC (rev 1595) +++ trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2014-04-17 08:05:40 UTC (rev 1596) @@ -17,6 +17,7 @@ import org.esigate.Driver; import org.esigate.DriverFactory; import org.esigate.util.Parameter; +import org.esigate.vars.VariablesResolver; import org.esigate.util.ParameterLong; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +57,9 @@ protected static final Logger LOG = LoggerFactory.getLogger(ConfigReloadOnChange.class); private static File configuration = null; - private static long lastModified = -1; + private static File variables = null; + private static long configLastModified = -1; + private static long varsLastModified = -1; private static long delay = DEFAULT_RELOAD_DELAY; // this variable will be used in the future, when extension supports @@ -67,9 +70,10 @@ @Override public void run() { while (!stop) { + // configuration if (configuration != null && configuration.exists()) { - if (configuration.lastModified() != lastModified) { - lastModified = configuration.lastModified(); + if (configuration.lastModified() != configLastModified) { + configLastModified = configuration.lastModified(); // Reload LOG.warn("Configuration file changed : reloading."); @@ -77,6 +81,17 @@ } } + // variables + if (variables != null && variables.exists()){ + if (variables.lastModified() != varsLastModified) { + varsLastModified = variables.lastModified(); + + // Reload + LOG.warn("Variables file changed : reloading."); + VariablesResolver.configure(); + } + } + // Wait before checking again try { Thread.sleep(delay); @@ -133,9 +148,23 @@ } if (configuration != null && configuration.exists()) { - lastModified = configuration.lastModified(); + configLastModified = configuration.lastModified(); } + // variables + URL variablesUrl = VariablesResolver.getVariablessUrl(); + if (variablesUrl != null && "file".equalsIgnoreCase(variablesUrl.getProtocol())) { + try { + variables = new File(variablesUrl.toURI()); + } catch (URISyntaxException e) { + LOG.error("Unable to access variables file", e); + } + } + + if (variables != null && variables.exists()) { + varsLastModified = variables.lastModified(); + } + // Start watcher fileWatcher.start(); } Modified: trunk/esigate-core/src/main/java/org/esigate/vars/VariablesResolver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/vars/VariablesResolver.java 2014-04-14 11:42:15 UTC (rev 1595) +++ trunk/esigate-core/src/main/java/org/esigate/vars/VariablesResolver.java 2014-04-17 08:05:40 UTC (rev 1596) @@ -15,12 +15,6 @@ package org.esigate.vars; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.apache.commons.lang3.StringUtils; import org.apache.http.cookie.Cookie; import org.esigate.ConfigurationException; @@ -32,6 +26,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Manage variables replacement. * @@ -56,9 +57,16 @@ } /** + * Loads variables from properties + */ + public static void configure(Properties props) { + properties = props; + } + + /** * Loads variables according to default configuration file org/esigate/vars.properties. */ - private static void configure() { + public static void configure() { InputStream inputStream = null; try { LOG.debug("Loading esigate-vars.properties file"); @@ -84,6 +92,17 @@ } /** + * @return The URL of the variables file. + */ + public static URL getVariablessUrl() { + URL varsUrl = Driver.class.getResource("/esigate-vars.properties"); + if (varsUrl == null){ + varsUrl = Driver.class.getResource("vars.properties"); + } + return varsUrl; + } + + /** * Regexp to find variables */ private static final Pattern VAR_PATTERN = Pattern.compile("\\$\\((.*?)\\)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |