[jboss-cvs] JBossAS SVN: r110766 - in branches/JBPAPP_5_1: testsuite/src/resources/ejb3/jbas7883 and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 24 11:43:28 EST 2011
Author: darran.lofthouse at jboss.com
Date: 2011-02-24 11:43:28 -0500 (Thu, 24 Feb 2011)
New Revision: 110766
Modified:
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/ejb3/jbas7883/unit/MailQueryUnitTestCase.java
branches/JBPAPP_5_1/testsuite/src/resources/ejb3/jbas7883/jbas7883-service.xml
branches/JBPAPP_5_1/varia/src/main/org/jboss/mail/MailService.java
branches/JBPAPP_5_1/varia/src/main/org/jboss/mail/SessionObjectFactory.java
Log:
[JBPAPP-5566] Additional fix and testing for mail sessions bound to the java:/ context.
Modified: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/ejb3/jbas7883/unit/MailQueryUnitTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/ejb3/jbas7883/unit/MailQueryUnitTestCase.java 2011-02-24 16:19:03 UTC (rev 110765)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/ejb3/jbas7883/unit/MailQueryUnitTestCase.java 2011-02-24 16:43:28 UTC (rev 110766)
@@ -101,7 +101,23 @@
assertEquals("Expected host name", "2.2.2.2", host);
}
+
+ public void testLookupThree_Java() throws Exception
+ {
+ TestRemote bean = (TestRemote) getInitialContext().lookup("TestBean/remote");
+ String host = bean.testCall(null, "java:/Mail3");
+ assertEquals("Expected host name", "3.3.3.3", host);
+ }
+
+ public void testLookupThree_JavaContext() throws Exception
+ {
+ TestRemote bean = (TestRemote) getInitialContext().lookup("TestBean/remote");
+ String host = bean.testCall("java:/", "Mail3");
+
+ assertEquals("Expected host name", "3.3.3.3", host);
+ }
+
public static Test suite() throws Exception
{
return getDeploySetup(MailQueryUnitTestCase.class, "jbas7883-service.xml, jbas7883.jar");
Modified: branches/JBPAPP_5_1/testsuite/src/resources/ejb3/jbas7883/jbas7883-service.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/resources/ejb3/jbas7883/jbas7883-service.xml 2011-02-24 16:19:03 UTC (rev 110765)
+++ branches/JBPAPP_5_1/testsuite/src/resources/ejb3/jbas7883/jbas7883-service.xml 2011-02-24 16:43:28 UTC (rev 110766)
@@ -26,5 +26,15 @@
</configuration>
</attribute>
</mbean>
+
+ <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail3">
+ <attribute name="JNDIName">java:/Mail3</attribute>
+ <attribute name="Configuration">
+ <configuration>
+ <property name="mail.transport.protocol" value="smtp" />
+ <property name="mail.smtp.host" value="3.3.3.3" />
+ </configuration>
+ </attribute>
+ </mbean>
</server>
\ No newline at end of file
Modified: branches/JBPAPP_5_1/varia/src/main/org/jboss/mail/MailService.java
===================================================================
--- branches/JBPAPP_5_1/varia/src/main/org/jboss/mail/MailService.java 2011-02-24 16:19:03 UTC (rev 110765)
+++ branches/JBPAPP_5_1/varia/src/main/org/jboss/mail/MailService.java 2011-02-24 16:43:28 UTC (rev 110766)
@@ -64,6 +64,9 @@
implements MailServiceMBean
{
public static final String JNDI_NAME = "java:/Mail";
+
+ static final String ADDRESS_TYPE = "nns";
+
/** */
private String user;
/** */
@@ -334,7 +337,7 @@
InitialContext ctx = new InitialContext();
try
{
- StringRefAddr addr = new StringRefAddr("nns", bindName);
+ StringRefAddr addr = new StringRefAddr(ADDRESS_TYPE, bindName);
Reference ref = new Reference(Session.class.getName(),
addr,
SessionObjectFactory.class.getName(),
Modified: branches/JBPAPP_5_1/varia/src/main/org/jboss/mail/SessionObjectFactory.java
===================================================================
--- branches/JBPAPP_5_1/varia/src/main/org/jboss/mail/SessionObjectFactory.java 2011-02-24 16:19:03 UTC (rev 110765)
+++ branches/JBPAPP_5_1/varia/src/main/org/jboss/mail/SessionObjectFactory.java 2011-02-24 16:43:28 UTC (rev 110766)
@@ -30,6 +30,8 @@
import javax.mail.Session;
import javax.naming.Context;
import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
/**
@@ -40,6 +42,7 @@
*
* @author Scott.Stark at jboss.org
* @author <a href="mailto:mlowe at ebilling.it">Mark Lowe</a>
+ * @author <a href="mailto:darran.lofthouse at jboss.com">Darran Lofthouse</a>
* @version $Revision$
*/
public class SessionObjectFactory implements ObjectFactory
@@ -60,18 +63,40 @@
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
throws Exception
{
- if (name == null)
+ String nameStr = null;
+
+ if (obj != null && obj instanceof Reference)
{
- MailSessionConfig defaultConfig = mailSessions.get(MailService.JNDI_NAME);
+ Reference ref = (Reference) obj;
+ RefAddr address = ref.get(MailService.ADDRESS_TYPE);
+ if (address != null)
+ {
+ String addressValue = address.getContent().toString();
+ if (addressValue != null)
+ {
+ nameStr = addressValue;
+ }
+ }
+ }
- if (defaultConfig == null)
+ if (nameStr == null && name != null)
+ {
+ nameStr = name.toString();
+ }
+
+ if (nameStr == null)
+ {
+ if (mailSessions.containsKey(MailService.JNDI_NAME))
{
+ nameStr = MailService.JNDI_NAME;
+ }
+ else
+ {
throw new IllegalStateException("No default mail session found and no alternative jndi name provided.");
}
- return defaultConfig;
}
- MailSessionConfig config = mailSessions.get(name.toString());
+ MailSessionConfig config = mailSessions.get(nameStr);
return config.getSession();
}
More information about the jboss-cvs-commits
mailing list