Author: ssmiweve Date: 2008-04-19 20:06:49 +0200 (Sat, 19 Apr 2008) New Revision: 6500
Modified: branches/2.17/ branches/2.17/site-spi/src/main/java/no/sesat/search/site/Site.java branches/2.17/war/src/main/java/no/sesat/search/http/filters/SiteLocatorFilter.java Log: Merged revisions 6493-6499 via svnmerge from http://sesat.no/svn/sesat-kernel/branches/2.16 ........ r6497 | ssmiweve | 2008-04-19 15:33:14 +0200 (Sat, 19 Apr 2008) | 2 lines SEARCH-4647 - Faulty host lookup leading to seemingly infinite loop + high load = crashed server. ........ Property changes on: branches/2.17 ___________________________________________________________________ Name: svnmerge-integrated - /branches/2.10:1-4690,4692-4745 /branches/2.11:1-4933 /branches/2.12:1-5051,5053-5106 /branches/2.13:1-5378 /branches/2.14:1-5508 /branches/2.15:1-5995 /branches/2.16:1-6492 /branches/2.6:1-3877 /branches/2.7:1-4160 /branches/2.8:1-4446 /branches/2.9:1-4626 /branches/MAP_SEARCHv2:1-4544 + /branches/2.10:1-4690,4692-4745 /branches/2.11:1-4933 /branches/2.12:1-5051,5053-5106 /branches/2.13:1-5378 /branches/2.14:1-5508 /branches/2.15:1-5995 /branches/2.16:1-6499 /branches/2.6:1-3877 /branches/2.7:1-4160 /branches/2.8:1-4446 /branches/2.9:1-4626 /branches/MAP_SEARCHv2:1-4544 Modified: branches/2.17/site-spi/src/main/java/no/sesat/search/site/Site.java =================================================================== --- branches/2.17/site-spi/src/main/java/no/sesat/search/site/Site.java 2008-04-19 13:44:13 UTC (rev 6499) +++ branches/2.17/site-spi/src/main/java/no/sesat/search/site/Site.java 2008-04-19 18:06:49 UTC (rev 6500) @@ -32,6 +32,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import no.schibstedsok.commons.ioc.BaseContext; import org.apache.log4j.Level; +import no.sesat.search.site.config.ResourceLoadException; import org.apache.log4j.Logger; /** A Site object identifies a Skin + Locale pairing. @@ -123,6 +124,7 @@ /** Creates a new instance of Site. * A null Context will result in a parentSiteName == siteName + * @throws IllegalArgumentException when there exists no skin matching the theSiteName argument. */ private Site(final Context cxt, final String theSiteName, final Locale theLocale) { @@ -151,9 +153,10 @@ final String parentSiteName; if(null != cxt){ - parentSiteName = null != cxt.getParentSiteName(siteContext) - ? ensureTrailingSlash(cxt.getParentSiteName(siteContext)) - : null; + // cxt.getParentSiteName(siteContext) is an expensive call due to resource load every call. + final String psn = cxt.getParentSiteName(siteContext); + parentSiteName = null != psn ? ensureTrailingSlash(psn) : null; + }else{ parentSiteName = siteName; } @@ -268,7 +271,8 @@ * @param cxt the cxt to use during creation. null will prevent constructing a new site. * @param siteName the virtual host name. * @param locale the locale desired - * @return the site bean. + * @throws IllegalArgumentException when there exists no skin matching the siteName argument. + * @return the site instance. never null. */ public static Site valueOf(final Context cxt, final String siteName, final Locale locale) { @@ -281,7 +285,7 @@ final String uniqueName = getUniqueName(realSiteName,locale); try{ INSTANCES_LOCK.readLock().lock(); - LOG.debug("INSTANCES.get(" + uniqueName + ")"); + LOG.trace("INSTANCES.get(" + uniqueName + ")"); site = INSTANCES.get(uniqueName); }finally{ Modified: branches/2.17/war/src/main/java/no/sesat/search/http/filters/SiteLocatorFilter.java =================================================================== --- branches/2.17/war/src/main/java/no/sesat/search/http/filters/SiteLocatorFilter.java 2008-04-19 13:44:13 UTC (rev 6499) +++ branches/2.17/war/src/main/java/no/sesat/search/http/filters/SiteLocatorFilter.java 2008-04-19 18:06:49 UTC (rev 6500) @@ -69,7 +69,6 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a> * @version $Id$ */ - public final class SiteLocatorFilter implements Filter { // Constants ----------------------------------------------------- @@ -91,7 +90,9 @@ private static final String UNKNOWN = "unknown"; - private static final String CONFIGURATION_RESOURCE= "/conf/" + Site.CONFIGURATION_FILE; + // Any request coming into Sesat with /conf/ is immediately returned as a 404. + // It should have been directed to a skin. + private static final String CONFIGURATION_RESOURCE= "/conf/"; /** Changes to this list must also change the ProxyPass|ProxyPassReverse configuration in httpd.conf **/ private static final Collection<String> EXTERNAL_DIRS = @@ -99,7 +100,9 @@ PUBLISH_DIR, "/css/", "/images/", "/javascript/" })); - /** The context that we'll need to use every invocation of doFilter(..) **/ + /** The context that we'll need to use every invocation of doFilter(..). + * @throws IllegalArgumentException when there exists no skin matching the siteContext.getSite() argument. + **/ public static final Site.Context SITE_CONTEXT = new Site.Context(){ public String getParentSiteName(final SiteContext siteContext) { // we have to do this manually instead of using SiteConfiguration, @@ -108,14 +111,13 @@ final Properties props = new Properties(); final PropertiesLoader loader = UrlResourceLoader.newPropertiesLoader(siteContext, Site.CONFIGURATION_FILE, props); - try{ - loader.abut(); - return props.getProperty(Site.PARENT_SITE_KEY); - - }catch(ResourceLoadException rle){ - LOG.fatal("BROKEN SITE HIERARCHY." + rle.getMessage()); - throw new VirtualMachineError(rle.getMessage()){}; + + loader.abut(); + final String parentName = props.getProperty(Site.PARENT_SITE_KEY); + if(null == parentName && 0 == props.size()){ + throw new IllegalArgumentException("Invalid site " + siteContext.getSite()); } + return parentName; } }; @@ -167,9 +169,9 @@ if(request instanceof HttpServletRequest) { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final HttpServletResponse httpServletResponse = (HttpServletResponse) response; - if (httpServletRequest.getRequestURI().endsWith(CONFIGURATION_RESOURCE)){ + if (httpServletRequest.getRequestURI().contains(CONFIGURATION_RESOURCE)){ /* We are looping, looking for a site search which does not exsist */ - LOG.debug("We are looping, looking for a site search which does not exist"); + LOG.info("We are looping, looking for a site search which does not exist"); httpServletResponse.reset(); httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); return; @@ -304,7 +306,7 @@ /** The method to obtain the correct Site from the request. * It only returns a site with a locale supported by that site. ** @param servletRequest - * @return + * @return the site instance. or null if no such skin has been deployed. */ public static Site getSite(final ServletRequest servletRequest) { // find the current site. Since we are behind a ajp13 connection request.getServerName() won't work! @@ -322,52 +324,58 @@ // Construct the site object off the browser's locale, even if it won't finally be used. final Locale locale = servletRequest.getLocale(); - final Site result = Site.valueOf(SITE_CONTEXT, correctedVhost, locale); - final SiteConfiguration.Context siteConfCxt = new SiteConfiguration.Context(){ - public PropertiesLoader newPropertiesLoader( - final SiteContext siteCxt, - final String resource, - final Properties properties) { + final Site result; + try{ + result = Site.valueOf(SITE_CONTEXT, correctedVhost, locale); + + final SiteConfiguration.Context siteConfCxt = new SiteConfiguration.Context(){ + public PropertiesLoader newPropertiesLoader( + final SiteContext siteCxt, + final String resource, + final Properties properties) { - return UrlResourceLoader.newPropertiesLoader(siteCxt, resource, properties); + return UrlResourceLoader.newPropertiesLoader(siteCxt, resource, properties); + } + public Site getSite() { + return result; + } + }; + final SiteConfiguration siteConf = SiteConfiguration.instanceOf(siteConfCxt); + servletRequest.setAttribute(SiteConfiguration.NAME_KEY, siteConf); + + if(LOG.isTraceEnabled()){ // MessageFormat.format(..) is expensive + LOG.trace(MessageFormat.format( + LOCALE_DETAILS, locale.getLanguage(), locale.getCountry(), locale.getVariant())); } - public Site getSite() { + + // Check if the browser's locale is supported by this skin. Use it if so. + if( siteConf.isSiteLocaleSupported(locale) ){ return result; } - }; - final SiteConfiguration siteConf = SiteConfiguration.instanceOf(siteConfCxt); - servletRequest.setAttribute(SiteConfiguration.NAME_KEY, siteConf); - if(LOG.isTraceEnabled()){ // MessageFormat.format(..) is expensive - LOG.trace(MessageFormat.format( - LOCALE_DETAILS, locale.getLanguage(), locale.getCountry(), locale.getVariant())); - } - - // Check if the browser's locale is supported by this skin. Use it if so. - if( siteConf.isSiteLocaleSupported(locale) ){ - return result; - } - - // Use the skin's default locale. For some reason that fails use JVM's default. - final String[] prefLocale = null != siteConf.getProperty(SiteConfiguration.SITE_LOCALE_DEFAULT) - ? siteConf.getProperty(SiteConfiguration.SITE_LOCALE_DEFAULT).split("_") - : new String[]{Locale.getDefault().toString()}; + // Use the skin's default locale. For some reason that fails use JVM's default. + final String[] prefLocale = null != siteConf.getProperty(SiteConfiguration.SITE_LOCALE_DEFAULT) + ? siteConf.getProperty(SiteConfiguration.SITE_LOCALE_DEFAULT).split("_") + : new String[]{Locale.getDefault().toString()}; - switch(prefLocale.length){ + switch(prefLocale.length){ - case 3: - LOG.trace(result+INFO_USING_DEFAULT_LOCALE + prefLocale[0] + '_' + prefLocale[1] + '_' + prefLocale[2]); - return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0], prefLocale[1], prefLocale[2])); + case 3: + LOG.trace(result+INFO_USING_DEFAULT_LOCALE + prefLocale[0] + '_' + prefLocale[1] + '_' + prefLocale[2]); + return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0], prefLocale[1], prefLocale[2])); - case 2: - LOG.trace(result+INFO_USING_DEFAULT_LOCALE + prefLocale[0] + '_' + prefLocale[1]); - return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0], prefLocale[1])); + case 2: + LOG.trace(result+INFO_USING_DEFAULT_LOCALE + prefLocale[0] + '_' + prefLocale[1]); + return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0], prefLocale[1])); - case 1: - default: - LOG.trace(result+INFO_USING_DEFAULT_LOCALE + prefLocale[0]); - return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0])); + case 1: + default: + LOG.trace(result+INFO_USING_DEFAULT_LOCALE + prefLocale[0]); + return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0])); + } + }catch(IllegalArgumentException iae){ + return null; } } @@ -430,22 +438,28 @@ LOG.trace("doBeforeProcessing()"); final Site site = getSite(request); + + if(null != site){ - final DataModel dataModel = getDataModel(request); + final DataModel dataModel = getDataModel(request); - if (null != dataModel && !dataModel.getSite().getSite().equals(site)) { - LOG.warn(WARN_FAULTY_BROWSER + dataModel.getBrowser().getUserAgent().getXmlEscaped()); - // DataModelFilter will correct it - } + if (null != dataModel && !dataModel.getSite().getSite().equals(site)) { + LOG.warn(WARN_FAULTY_BROWSER + dataModel.getBrowser().getUserAgent().getXmlEscaped()); + // DataModelFilter will correct it + } - request.setAttribute(Site.NAME_KEY, site); - request.setAttribute("startTime", FindResource.START_TIME); - MDC.put(Site.NAME_KEY, site.getName()); - MDC.put("UNIQUE_ID", getRequestId(request)); + request.setAttribute(Site.NAME_KEY, site); + request.setAttribute("startTime", FindResource.START_TIME); + MDC.put(Site.NAME_KEY, site.getName()); + MDC.put("UNIQUE_ID", getRequestId(request)); + + /* Setting default encoding */ + request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); - /* Setting default encoding */ - request.setCharacterEncoding("UTF-8"); - response.setCharacterEncoding("UTF-8"); + }else{ + throw new ServletException("SiteLocatorFilter with no Site :-("); + } } private void doAfterProcessing(final ServletRequest request, final ServletResponse response) _______________________________________________ Kernel-commits mailing list [email protected] http://sesat.no/mailman/listinfo/kernel-commits
