From: <vga...@us...> - 2010-04-15 20:09:16
|
Revision: 689 http://treebase.svn.sourceforge.net/treebase/?rev=689&view=rev Author: vgapeyev Date: 2010-04-15 20:09:08 +0000 (Thu, 15 Apr 2010) Log Message: ----------- Added JNDI parameter tb2/SmtpHost. This fixes SF#2977860 Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/TreebaseUtil.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PasswordFormController.java trunk/treebase-web/src/main/webapp/META-INF/context.xml.example trunk/treebase-web/src/main/webapp/WEB-INF/web.xml Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/TreebaseUtil.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/TreebaseUtil.java 2010-04-15 19:39:53 UTC (rev 688) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/TreebaseUtil.java 2010-04-15 20:09:08 UTC (rev 689) @@ -45,6 +45,7 @@ private static final Logger LOGGER = Logger.getLogger(TreebaseUtil.class); private static String mPurlBase; private static String mSiteUrl; + private static String mSmtpHost; private TreebaseUtil() { super(); @@ -431,41 +432,25 @@ return date + " GMT"; } + - /** - * This method returns the domain name (possibly with port number) - * which can be used to construct URLs by prefixing with "http://" - * and suffixing with the full path (e.g. "/treebase-web") + /** Looks up a JNDI Environment parameter that carries a string value. * - * @return domain name */ - /*-- - public static String getPurlBase() { - if ( null == mPurlDomain ) { - Properties properties = new Properties(); - try { - properties.load( - TreebaseUtil.class - .getClassLoader() - .getResourceAsStream("treebase.properties")); - LOGGER.info("properties loaded successfully"); - mPurlDomain = properties.getProperty("treebase.purl.domain"); - LOGGER.info("domain name: "+mPurlDomain); - } catch (FileNotFoundException e) { - LOGGER.warn("FileNotFoundException: " + e.getMessage()); - e.printStackTrace(); - } catch (IOException e) { - LOGGER.warn("IOException: "+e.getMessage()); - e.printStackTrace(); - } - return mPurlDomain; + private static String lookupJndiEnvironmentString(String name, String fallback) { + String result = fallback; + try { + InitialContext ic = new InitialContext(); + result = (String) ic.lookup("java:comp/env/" + name); + } catch (NamingException e) { + LOGGER.info("Failure looking up " + name + " via JNDI"); + e.printStackTrace(); } - else { - return mPurlDomain; - } + return result; } -*/ + + /** * Returns the base URL of the PURL service associated with this Treebase instance, * which can be used to construct full PURLs by suffixing with a PhyloWS command, e.g. "/study/TB2:S1925" @@ -473,21 +458,10 @@ * @return the base URL of the PURL service */ public static String getPurlBase() { - if (null != mPurlBase) - return mPurlBase; - else { - try { - mPurlBase = "http://DUMMY_PURL_BASE/"; - InitialContext ic = new InitialContext(); - mPurlBase = (String) ic.lookup("java:comp/env/tb2/PurlBase"); - } catch (NamingException e) { - LOGGER.info("Failure looking up tb2/PurlBase via JNDI"); - e.printStackTrace(); - } - return mPurlBase; - } + if (null == mPurlBase) + mPurlBase = lookupJndiEnvironmentString("tb2/PurlBase", "http://DUMMY_PURL_BASE/"); + return mPurlBase; } - /** * Returns the base URL of this Treebase instance, by looking it up in Tomcat via JNDI. @@ -495,22 +469,23 @@ * @return the base URL of of this Treebase instance */ public static String getSiteUrl() { - if (null != mSiteUrl) - return mSiteUrl; - else { - try { - mSiteUrl = "http://DUMMY_SITE_URL/"; - InitialContext ic = new InitialContext(); - mSiteUrl = (String) ic.lookup("java:comp/env/tb2/SiteUrl"); - } catch (NamingException e) { - LOGGER.info("Failure looking up tb2/SiteUrl via JNDI"); - e.printStackTrace(); - } - return mSiteUrl; - } + if (null == mSiteUrl) + mSiteUrl = lookupJndiEnvironmentString("tb2/SiteUrl", "http://DUMMY.SITE.COM/"); + return mSiteUrl; } + + /** + * + * @return the SMTP host to use for automated email + */ + public static String getSmtpHost() { + if (null == mSmtpHost) + mSmtpHost = lookupJndiEnvironmentString("tb2/SmtpHost", "smtp.DUMMY.HOST"); + return mSmtpHost; + } + /** * This method appends header information upon formatting to the nexus file. * Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PasswordFormController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PasswordFormController.java 2010-04-15 19:39:53 UTC (rev 688) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/PasswordFormController.java 2010-04-15 20:09:08 UTC (rev 689) @@ -107,7 +107,7 @@ // create mail session Properties props = new Properties(); - props.put("mail.smtp.host", "smtp.ucsd.edu"); + props.put("mail.smtp.host", TreebaseUtil.getSmtpHost()); Session mailSession = Session.getDefaultInstance(props,null); // create email message header information Modified: trunk/treebase-web/src/main/webapp/META-INF/context.xml.example =================================================================== --- trunk/treebase-web/src/main/webapp/META-INF/context.xml.example 2010-04-15 19:39:53 UTC (rev 688) +++ trunk/treebase-web/src/main/webapp/META-INF/context.xml.example 2010-04-15 20:09:08 UTC (rev 689) @@ -37,6 +37,10 @@ type="java.lang.String" override="false" description="The base URL of a PURL service that redirects to this Treebase instance."/> + <Environment name="tb2/SmtpHost" value="smtp.YOUR.SERVER.ORG" + type="java.lang.String" override="false" + description="Host name of an SMTP server that your instance can use without authentication."/> + </Context> Modified: trunk/treebase-web/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/web.xml 2010-04-15 19:39:53 UTC (rev 688) +++ trunk/treebase-web/src/main/webapp/WEB-INF/web.xml 2010-04-15 20:09:08 UTC (rev 689) @@ -73,6 +73,11 @@ <env-entry-type>java.lang.String</env-entry-type> </env-entry> + <env-entry> + <description>Host name of an SMTP server that your instance can use without authentication.</description> + <env-entry-name>tb2/SmtpHost</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + </env-entry> <!-- ========================================================== --> <!-- List of Filters --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |