You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Rene Lacasse <rl...@globalatn.com> on 2003/10/17 23:09:01 UTC

MySQL connection within a mailet

Are there restrictions to accessing a MySQL database from within a Mailet?

James is currently on a Linux box and is configured to use MySQL.  I've created a Mailet that checks to see if the recipients are listed in a non-James MySQL table.

Tailing the mailet log file, I can see the mailet in question outputting log messages but I'm not getting the expected results.  Furthermore, the MySQL log file isn't showing any activity.

Any ideas?


I've attached the code in question.  The last message I see in the mailet log is "Retrieving subscription...".

	public void service (org.apache.mailet.Mail oMail) throws javax.mail.MessagingException
	{
		this.log("Received message on server with "+ oMail.getRecipients ().size () +" recipients");
		
		// get receipients
		java.util.Collection oCollection = oMail.getRecipients();
		
		log("Collection: " + oCollection.toString ());
		java.util.Iterator oMailIterator = oCollection.iterator ();
	
		while(oMailIterator.hasNext())
		{
			org.apache.mailet.MailAddress oMailAddress = (org.apache.mailet.MailAddress) oMailIterator.next();
			
			// check database
			this.log("Checking if user \"" + oMailAddress.getUser () +"\" is registered");
			try
			{
				this.log("Retrieving subscription...");
				String oHostString = oJDBCSubscription.checkSubscription (oMailAddress.getUser ());
				this.log("... retrieved: " + oHostString);
				
				if(oHostString != null)
				{
					this.log("Found Registration, sending notification");
					// if user subscribed, send notification
					com.globalatn.sl.ai.Notify oNotify = new com.globalatn.sl.ai.Notify ();
					oNotify.setDate(new java.util.Date());
					oNotify.setServer (java.net.InetAddress.getLocalHost ().getHostAddress ());
					java.net.InetAddress oInetAddress = java.net.InetAddress.getByName (oHostString);
					this.oPacketServer.sendObject (oNotify, oInetAddress);
				}
				else
				{
					this.log("No registration found");
				}
			}
			catch (com.globalatn.dd.ps.PersistentStorageException oPersistentStorageException)
			{
				this.log("DOH!: "+ oPersistentStorageException.toString () );
			}
			catch (java.net.UnknownHostException oUnknownHostException)
			{
				this.log("DOH!!: "+ oUnknownHostException.toString ());
			}
			catch (java.io.IOException oIOException)
			{
				this.log("DOH!!!: "+ oIOException.toString ());
			}
		}
	}

---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


RE: MySQL connection within a mailet

Posted by "Noel J. Bergman" <no...@devtech.com>.
The exception might not be one that you are catching, and thus going back to
the spool manager.

	--- Noel


---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


RE: MySQL connection within a mailet

Posted by Lindsay Smith <li...@wapdat.com>.
There are no restrictions accessing mysql or any DB.  My suspicion is  there
is a ClassNotFoundException for com.globalatn.* or a class this depends on,
being logged in some other James log.

best of luck

Lindsay

-----Original Message-----
From: Rene Lacasse [mailto:rlacasse@globalatn.com]
Sent: 17 October 2003 22:09
To: server-user@james.apache.org
Subject: MySQL connection within a mailet


Are there restrictions to accessing a MySQL database from within a Mailet?

James is currently on a Linux box and is configured to use MySQL.  I've
created a Mailet that checks to see if the recipients are listed in a
non-James MySQL table.

Tailing the mailet log file, I can see the mailet in question outputting log
messages but I'm not getting the expected results.  Furthermore, the MySQL
log file isn't showing any activity.

Any ideas?


I've attached the code in question.  The last message I see in the mailet
log is "Retrieving subscription...".

	public void service (org.apache.mailet.Mail oMail) throws
javax.mail.MessagingException
	{
		this.log("Received message on server with "+ oMail.getRecipients ().size
() +" recipients");

		// get receipients
		java.util.Collection oCollection = oMail.getRecipients();

		log("Collection: " + oCollection.toString ());
		java.util.Iterator oMailIterator = oCollection.iterator ();

		while(oMailIterator.hasNext())
		{
			org.apache.mailet.MailAddress oMailAddress =
(org.apache.mailet.MailAddress) oMailIterator.next();

			// check database
			this.log("Checking if user \"" + oMailAddress.getUser () +"\" is
registered");
			try
			{
				this.log("Retrieving subscription...");
				String oHostString = oJDBCSubscription.checkSubscription
(oMailAddress.getUser ());
				this.log("... retrieved: " + oHostString);

				if(oHostString != null)
				{
					this.log("Found Registration, sending notification");
					// if user subscribed, send notification
					com.globalatn.sl.ai.Notify oNotify = new com.globalatn.sl.ai.Notify ();
					oNotify.setDate(new java.util.Date());
					oNotify.setServer (java.net.InetAddress.getLocalHost ().getHostAddress
());
					java.net.InetAddress oInetAddress = java.net.InetAddress.getByName
(oHostString);
					this.oPacketServer.sendObject (oNotify, oInetAddress);
				}
				else
				{
					this.log("No registration found");
				}
			}
			catch (com.globalatn.dd.ps.PersistentStorageException
oPersistentStorageException)
			{
				this.log("DOH!: "+ oPersistentStorageException.toString () );
			}
			catch (java.net.UnknownHostException oUnknownHostException)
			{
				this.log("DOH!!: "+ oUnknownHostException.toString ());
			}
			catch (java.io.IOException oIOException)
			{
				this.log("DOH!!!: "+ oIOException.toString ());
			}
		}
	}

---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org