Hmm i tried it but it now work.. has to do some changes to get it compile. I also add a few log() calls but i can not find the logs anyway ? I thought this logs will be shown in the mailet logs.. create a patch of what i changed and attach it here..
I also use a own table named DOMAIN with the column DOMAIN_NAME.. thx Am Donnerstag, den 02.03.2006, 18:35 +0100 schrieb Stefano Bagnara: > Pierre Smits wrote: > > Norman, > > > > It does not work with the latest trunk. I have tested that. It has been > > developed with version 2.2.0 in mind a while back by Daniel Perry before > > there was even a hint of 2.3.x > > I never used that patch, but I just looked the sources and I think it > should work with James trunk too. > Maybe the line numbers are not good, but the added code should work. > > Try a manual merge and let me know if you have problem with missing > methods/components. > > Stefano > > PS: It's unlikely that the patch will be included in james 2.3.0. Maybe > we'll include a modular way to find out the servernames but not exactly > this (this patch add an "ugly" dependency between James main component > and a db table with a structure specific to the virtuser mailet) > > >> > >> Anyone has this patch working with the latest trunk ? It seems not to work > >> here :-( > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > !EXCUBATOR:2,44072d3b187375736718770!
--- src/java/org/apache/james/JamesOriginal.java 2006-03-02 15:12:42.000000000 +0100 +++ src/java/org/apache/james/James.java 2006-03-02 20:51:51.000000000 +0100 @@ -19,6 +19,7 @@ import org.apache.avalon.cornerstone.services.store.Store; import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; @@ -34,6 +35,8 @@ import org.apache.avalon.framework.service.Serviceable; import org.apache.commons.collections.ReferenceMap; +import org.apache.james.Constants; +import org.apache.james.JamesMBean; import org.apache.james.context.AvalonContextUtilities; import org.apache.james.core.MailHeaders; import org.apache.james.core.MailImpl; @@ -72,6 +75,14 @@ import java.util.Map; import java.util.Vector; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector; +import org.apache.avalon.excalibur.datasource.DataSourceComponent; +import org.apache.james.util.JDBCUtil; + /** * Core class for JAMES. Provides three primary services: * <br> 1) Instantiates resources, such as user repository, and protocol @@ -80,10 +91,10 @@ * <br> 3) Provides container services for Mailets * * - * @version This is $Revision: 366800 $ + * @version This is $Revision: 1.1 $ */ -public class JamesOriginal +public class James extends AbstractLogEnabled implements Contextualizable, Serviceable, Configurable, JamesMBean, Initializable, MailServer, MailetContext { @@ -184,6 +195,13 @@ */ protected Mailet localDeliveryMailet; + + /** + * The database and table to use for checking virtual domains. + */ + private String domainTable = null; + + /** * @see org.apache.avalon.framework.context.Contextualizable#contextualize(Context) */ @@ -258,6 +276,13 @@ getLogger().info("Local host is: " + hostName); // Get the domains and hosts served by this instance + + try { + domainTable = (String) getAttribute("domainTable"); + } catch (Exception e) { + domainTable = ""; + } + serverNames = new HashSet(); Configuration serverConf = conf.getChild("servernames"); if (serverConf.getAttributeAsBoolean("autodetect") && (!hostName.equals("localhost"))) { @@ -757,7 +782,75 @@ * @return whether the server is local */ public boolean isLocalServer( final String serverName ) { - return serverNames.contains(serverName.toLowerCase(Locale.US)); + if (serverNames.contains(serverName.toLowerCase(Locale.US))) { + return true; + } + if (domainTable!=null && !domainTable.equals("")){ + + + String datasourceName = domainTable.substring(5); + int pos = datasourceName.indexOf("/"); + String tableName = datasourceName.substring(pos + 1); + datasourceName = datasourceName.substring(0, pos); + Connection conn = null; + DataSourceComponent datasource; + JDBCUtil theJDBCUtil = new JDBCUtil() { + protected void delegatedLog(String logString) { + log("JDBCVirtualDomains: " + logString); + } + }; + String query = null; + + try { + + log("Check servername " + serverName); + + ComponentManager componentManager = (ComponentManager) compMgr; + // Get the DataSourceSelector service + DataSourceSelector datasources = (DataSourceSelector)componentManager.lookup(DataSourceSelector.ROLE); + // Get the data-source required. + datasource = (DataSourceComponent)datasources.select(datasourceName); + + conn = datasource.getConnection(); + + + // Check if the required table exists. If not, complain. + DatabaseMetaData dbMetaData = conn.getMetaData(); + // Need to ask in the case that identifiers are stored, ask the DatabaseMetaInfo. + // Try UPPER, lower, and MixedCase, to see if the table is there. + if (!(theJDBCUtil.tableExists(dbMetaData, tableName))) { + + log("The table " + tableName + " does not exists"); + + return false; + } + + //Build the query + + query = "select distinct DOMAIN_NAME from " + tableName + " where DOMAIN_NAME=?"; + PreparedStatement domainStatement = conn.prepareStatement(query); + domainStatement.setString(1,serverName); + + ResultSet domainRS = domainStatement.executeQuery(); + + if (domainRS.next()) { + + log("Found the Servername"); + return true; + } + + + } catch (Exception e) { + + log("Exception while getting servernames from sql: " + e.getStackTrace()); + return false; + } finally { + theJDBCUtil.closeJDBCConnection(conn); + } + } + + return false; + } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]