r500498 | eross | 2007-01-27 01:20:49 -0600 (Sat, 27 Jan 2007) | 2 lines

Bug 35259 - Added attribute "sessionJNDI" to the appender
Added negative test, needs positive testing though

Index: src/java/org/apache/log4j/net/SMTPAppender.java
===================================================================
33a34,37
> import javax.naming.Context;
> import javax.naming.InitialContext;
> import javax.naming.NameNotFoundException;
> import javax.naming.NamingException;
76a81,86
> The JavaMail session is obtained through [EMAIL PROTECTED] #setSessionJNDI (String) JNDI} or by > directly calling [EMAIL PROTECTED] Session#getDefaultInstance(Properties) and setting
>    various addressing details on this object.
>    The former method is preferred for application servers,
>    the latter for stand-alone usage.
>    </p>
80a91,96
>
>   /**
>    * JavaMail session.
>    */
>   private Session session;
>
94a111
>   private String sessionJNDI;
125,126c142,152
<     Session session = createSession();
<     msg = new MimeMessage(session);
---
>     if (sessionJNDI != null) {
>       try {
>         session = lookupSession();
>         if (session == null)
>           throw new NameNotFoundException();
>       } catch (NamingException e) {
> throw new IllegalStateException("Failed finding javax.mail.Session: " + sessionJNDI + " Reason: " + e);
>       }
>     } else {
>       session = createSession();
>     }
127a154
>     msg = new MimeMessage(session);
143d169
<       errorCount++;
150d175
<       errorCount++;
160a186,194
>   private Session lookupSession() throws NamingException {
>     Context c = new InitialContext();
>     try {
>       return (Session) c.lookup(sessionJNDI);
>     } finally {
>       c.close();
>     }
>   }
>
189,190c223
<    *  Create mail session.
<    *  @param mail session, may not be null.
---
>    * Returns a new mail session, using properties from the system.
601a635,650
>
>   /**
>    * Returns the session JNDI entry name.
>    * This is useful for application servers.
>    */
>   public String getSessionJNDI() {
>     return sessionJNDI;
>   }
>
>   /**
>    * Sets the session JNDI entry name.
>    */
>   public void setSessionJNDI(String sessionJndiLocation) {
>     this.sessionJNDI = sessionJndiLocation;
>   }
>
Index: tests/src/java/org/apache/log4j/net/SMTPAppenderTest.java
===================================================================
23d22
<
30a30,32
>
>   SMTPAppender ca = new SMTPAppender();
>
32c34
<     return new SMTPAppender();
---
>     return ca;
36,37d37
<     SMTPAppender ca = new SMTPAppender();
<
46,47c46,61
<   public void testPartiallyConfiguredAppender() {
<
---
>   public void testBadSessionJNDI() {
>     ca.setSessionJNDI("/not/here");
>     try {
>       ca.activateOptions();
>       fail("cannot start");
>     } catch (IllegalStateException e) {
>     }
>     ca.setSessionJNDI(null);
>     ca.setLayout(new DummyLayout());
>     ca.activateOptions();
>     /*
>     LoggingEvent le = new LoggingEvent();
>     le.setMessage("hi");
>     le.setLevel(Level.DEBUG);
>     ca.doAppend(le);
>     */
48a63,64
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to