Author: ssmiweve Date: 2008-04-15 14:36:29 +0200 (Tue, 15 Apr 2008) New Revision: 6446
Modified: branches/2.17/ branches/2.17/data-model-api/src/main/java/no/sesat/search/datamodel/DataModelFactory.java branches/2.17/generic.sesam/pom.xml branches/2.17/pom.xml 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 6392-6445 via svnmerge from http://sesat.no/svn/sesat-kernel/branches/2.16 ........ r6417 | ssmiweve | 2008-04-14 22:21:33 +0200 (Mon, 14 Apr 2008) | 2 lines SEARCH-4613 - generic.sesam.no configuration files are loaded through apache ........ r6440 | ssmiweve | 2008-04-15 13:42:19 +0200 (Tue, 15 Apr 2008) | 1 line SEARCH-4613 - generic.sesam.no configuration files are loaded through apache ........ 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-6391 /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-6445 /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/data-model-api/src/main/java/no/sesat/search/datamodel/DataModelFactory.java =================================================================== --- branches/2.17/data-model-api/src/main/java/no/sesat/search/datamodel/DataModelFactory.java 2008-04-15 12:31:19 UTC (rev 6445) +++ branches/2.17/data-model-api/src/main/java/no/sesat/search/datamodel/DataModelFactory.java 2008-04-15 12:36:29 UTC (rev 6446) @@ -1,4 +1,4 @@ -/* Copyright (2007) Schibsted Søk AS +/* Copyright (2007-2008) Schibsted Søk AS * This file is part of SESAT. * * SESAT is free software: you can redistribute it and/or modify @@ -186,7 +186,13 @@ final String clsName = siteConf.getProperty(DATA_MODEL_FACTORY_IMPL); LOG.info("constructing for " + cxt.getSite() + " instance of " + clsName); - + + if(null == clsName){ + throw new SiteKeyedFactoryInstantiationException( + "Couldn't find " + DATA_MODEL_FACTORY_IMPL + " in " + siteConf.getProperties().toString(), + new NullPointerException()); + } + @SuppressWarnings("unchecked") final Class<DataModelFactory> cls = (Class<DataModelFactory>) Class.forName(clsName); Modified: branches/2.17/generic.sesam/pom.xml =================================================================== --- branches/2.17/generic.sesam/pom.xml 2008-04-15 12:31:19 UTC (rev 6445) +++ branches/2.17/generic.sesam/pom.xml 2008-04-15 12:36:29 UTC (rev 6446) @@ -379,7 +379,7 @@ <build><pluginManagement /></build> <properties> - <sesam.site>generic.sesam.no</sesam.site> + <sesam.site>generic.sesam</sesam.site> <!-- QR Servers --> <newsQueryServerURL>http://10.16.195.250:15100</newsQueryServerURL> Modified: branches/2.17/pom.xml =================================================================== --- branches/2.17/pom.xml 2008-04-15 12:31:19 UTC (rev 6445) +++ branches/2.17/pom.xml 2008-04-15 12:36:29 UTC (rev 6446) @@ -323,7 +323,6 @@ <id>gamma</id> <activation /> <properties> - <sesam.site.generic>generic.sesam.no</sesam.site.generic> <sesam.site.default>${sesam.site.generic}</sesam.site.default> <!-- IMPORTANT: production cannot handle writing to sesam.log at a lower threshold --> <log.level>WARN</log.level> 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-15 12:31:19 UTC (rev 6445) +++ branches/2.17/site-spi/src/main/java/no/sesat/search/site/Site.java 2008-04-15 12:36:29 UTC (rev 6446) @@ -1,4 +1,4 @@ -/* Copyright (2005-2007) Schibsted Søk AS +/* Copyright (2005-2008) Schibsted Søk AS * This file is part of SESAT. * * SESAT is free software: you can redistribute it and/or modify @@ -50,7 +50,10 @@ * While a SiteContext is a context required to use a Site. **/ public interface Context extends BaseContext{ - /** Get the name of the parent site. **/ + /** Get the name of the parent site. + * @param siteContext that can provide the current site the code is within. + * @return the name of the parent site. + */ String getParentSiteName(SiteContext siteContext); } @@ -106,16 +109,16 @@ uniqueName = null; parent = null; } - + /** Creates a new instance of Site. * A null Context will result in a parentSiteName == siteName */ private Site(final Context cxt, final String theSiteName, final Locale theLocale) { - - + + try{ INSTANCES_LOCK.writeLock().lock(); - + LOG.info("Site(cxt, " + theSiteName + ", " + theLocale + ')'); assert null != theSiteName; assert null != theLocale; @@ -137,18 +140,37 @@ } }; - final String parentSiteName = null != cxt ? cxt.getParentSiteName(siteContext) : siteName; - parent = null == parentSiteName || ensureTrailingSlash(parentSiteName).equals(siteName) - ? constructingDefault ? null : DEFAULT - : Site.valueOf(cxt, parentSiteName, theLocale); + final String tsParentNameNoPort = null != parentSiteName + ? ensureTrailingSlash(parentSiteName.replaceAll(":.*$", "")) + : null; + LOG.error(siteName + " parent is " + parentSiteName); + + if(constructingDefault){ + parent = null; + + }else{ + LOG.error("Default-check-> " + DEFAULT.getName() + " ?= " + + (null != parentSiteName ? ensureTrailingSlash(parentSiteName) : "null")); + + final boolean invalidParent = null == parentSiteName + // also avoid any incest + || siteName.equals(tsParentNameNoPort) + // and detect ahead the link to the grandfather of all "generic.sesam" + || ensureTrailingSlash(parentSiteName).equals(DEFAULT.getName()); + + parent = invalidParent + ? DEFAULT + : Site.valueOf(cxt, parentSiteName, theLocale); + } + assert null != parent || constructingDefault : "Parent must exist for all Sites except the DEFAULT"; - + // register in global pool. INSTANCES.put(uniqueName, this); - + }finally{ INSTANCES_LOCK.writeLock().unlock(); } @@ -156,8 +178,8 @@ /** the parent to this site. - * returns null if we are the DEFAULT site. - **/ + * @return site null if we are the DEFAULT site. + */ public Site getParent(){ return parent; } @@ -212,7 +234,7 @@ */ @Override public boolean equals(final Object obj) { - + return obj instanceof Site ? uniqueName.equals(((Site)obj).uniqueName) : super.equals(obj); @@ -230,29 +252,25 @@ * A "www." prefix will be automatically ignored. * @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. */ public static Site valueOf(final Context cxt, final String siteName, final Locale locale) { Site site = null; - - // Tweak the port is SERVER_PORT has been explicitly set. - final String correctedPortSiteName = SERVER_PORT > 0 && siteName.indexOf(':') > 0 - ? siteName.substring(0, siteName.indexOf(':') + 1) + SERVER_PORT - : siteName; // Strip www. from siteName - final String realSiteName = ensureTrailingSlash(correctedPortSiteName.replaceAll("www.", "")); + final String realSiteName = ensureTrailingSlash(siteName.replaceAll("www.", "")); // Look for existing instances try{ INSTANCES_LOCK.readLock().lock(); site = INSTANCES.get(getUniqueName(realSiteName,locale)); - + }finally{ INSTANCES_LOCK.readLock().unlock(); } - + // construct a new instance if (null == site && null != cxt) { site = new Site(cxt, realSiteName, locale); @@ -264,28 +282,28 @@ final Properties props = new Properties(); final InputStream is = Site.class.getResourceAsStream('/' + CORE_CONF_FILE); - + try { if(null != is){ props.load(is); is.close(); } - + } catch (IOException ex) { - LOG.fatal(FATAL_CANT_FIND_DEFAULT_SITE, ex); + LOG.fatal(FATAL_CANT_FIND_DEFAULT_SITE, ex); } - + final Level oLevel = LOG.getLevel(); LOG.setLevel(Level.ALL); final String defaultSiteName = props.getProperty(DEFAULT_SITE_KEY, System.getProperty(DEFAULT_SITE_KEY)); LOG.info("defaultSiteName: " + defaultSiteName); - - final String defaultSiteLocaleName + + final String defaultSiteLocaleName = props.getProperty(DEFAULT_SITE_LOCALE_KEY, System.getProperty(DEFAULT_SITE_LOCALE_KEY)); LOG.info("defaultSiteLocaleName: " + defaultSiteLocaleName); - - final String defaultSitePort + + final String defaultSitePort = props.getProperty(DEFAULT_SERVER_PORT_KEY, System.getProperty(DEFAULT_SERVER_PORT_KEY)); LOG.info("defaultSitePort: " + defaultSitePort); @@ -312,14 +330,20 @@ /** the server's actual port. **/ public static final int SERVER_PORT; - /** TODO comment me. **/ + /** Get a uniqueName given a pair of siteName and locale. + * Used internally and before construction of any new Site. + * + * @param siteName + * @param locale + * @return + */ public static String getUniqueName(final String siteName, final Locale locale) { - + return siteName + '[' + locale.getDisplayName() + ']'; } private static String ensureTrailingSlash(final String theSiteName) { - + return theSiteName.endsWith("/") ? theSiteName : theSiteName + '/'; 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-15 12:31:19 UTC (rev 6445) +++ branches/2.17/war/src/main/java/no/sesat/search/http/filters/SiteLocatorFilter.java 2008-04-15 12:36:29 UTC (rev 6446) @@ -313,12 +313,16 @@ // 2) "UseCanonicalName Off" to assign ServerName from client's request. final String vhost = getServerName(servletRequest); + // Tweak the port if SERVER_PORT has been explicitly set. (We may have gone through Apache or Cisco LB). + final String correctedVhost = Site.SERVER_PORT > 0 && vhost.indexOf(':') > 0 + ? vhost.substring(0, vhost.indexOf(':') + 1) + Site.SERVER_PORT + : vhost; - LOG.trace(DEBUG_REQUESTED_VHOST + vhost); + LOG.trace(DEBUG_REQUESTED_VHOST + correctedVhost); // 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, vhost, locale); + final Site result = Site.valueOf(SITE_CONTEXT, correctedVhost, locale); final SiteConfiguration.Context siteConfCxt = new SiteConfiguration.Context(){ public PropertiesLoader newPropertiesLoader( final SiteContext siteCxt, @@ -353,16 +357,16 @@ case 3: LOG.trace(result+INFO_USING_DEFAULT_LOCALE + prefLocale[0] + '_' + prefLocale[1] + '_' + prefLocale[2]); - return Site.valueOf(SITE_CONTEXT, vhost, new 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, vhost, new 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, vhost, new Locale(prefLocale[0])); + return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0])); } } _______________________________________________ Kernel-commits mailing list [email protected] http://sesat.no/mailman/listinfo/kernel-commits
