Follow up for the archives. I got this working.
There are a few ways of specifying the Session to use to send messages using the
SMTPTargetFactory.
#1)
The original question was how to specify a Session in the Context when using Fortress.
The answer is to use code like the following when initializing Fortress:
---
FortressConfig config = new FortressConfig();
config.setContainerClass( getContainerClassName() );
config.setCommandFailureHandlerClass( ServerCommandFailureHandler.class );
config.setContextDirectory( "./" );
config.setWorkDirectory( "./" );
config.setContainerConfiguration( ConfigurationUtil.loadConfiguration( new File( configResourceBase + ".xconf" ) ) );
config.setLoggerManagerConfiguration( ConfigurationUtil.loadConfiguration( new File( configResourceBase + ".xlog" ) ) );
config.setInstrumentManagerConfiguration( ConfigurationUtil.loadConfiguration( new File( configResourceBase + ".instruments" ) ) );
DefaultContext newContext = new DefaultContext( config.getContext() ); newContext.put( "smtp-session", createSMTPSession() ); newContext.makeReadOnly();
m_containerManager = new DefaultContainerManager( newContext ); ContainerUtil.initialize( m_containerManager );
m_container = (DefaultContainer)m_containerManager.getContainer(); ---
You would then define the target in your xlog file as follows:
---
<smtp id="smtp" context-key="smtp-session">
<to>[EMAIL PROTECTED]</to>
<from>[EMAIL PROTECTED]</from>
<subject>Subject</subject>
<maximum-size>1</maximum-size>
<format type="extended">
%7.7{priority} %23.23{time:yyyy-MM-dd HH:mm:ss.SSS} [%32.32{category}] (%{context}): %{message}\n%{throwable}
</format>
</smtp>
---
#2
The second option lets you do everything from within the .xlog file and is actually what I
had been looking for originally:
---
<smtp id="smtp">
<session>
<parameter name="mail.host" value="smtp.host.com"/>
</session>
<to>[EMAIL PROTECTED]</to>
<from>[EMAIL PROTECTED]</from>
<subject>Subject</subject>
<maximum-size>1</maximum-size>
<format type="extended">
%7.7{priority} %23.23{time:yyyy-MM-dd HH:mm:ss.SSS} [%32.32{category}] (%{context}): %{message}\n%{throwable}
</format>
</smtp>
---
Simply define a session element which specifies any parameters that you would like to set
when creating the Session.
Cheers, Leif
Leif Mortenson wrote:
Niclas Hedhman wrote:
Thanks, The problem is that the SMTPTargetFactory is looking for a javax.mail.SessionOn Monday 26 July 2004 13:01, Leif Mortenson wrote:
I was also wondering why the SMTPTargetFactory simply does not allow you
to specify the SMTP host in its configuration. If that was possible,
then it would
be easy to completely self contain the configuration information for
sending the
log events.
I am shooting in the dark, but perhaps it can give you some ideas;
JavaMail looks for a "mail.properties" resource, in which most stuff can be configured. Perhaps it is enough to make it available in the classloader.
instance on the Context. When normally working with JavaMail, I understand how this
Session object is normally created. In this case however, I am just getting stuck trying
to figure out how that Session object is supposed to find its way into the Context.
To create the Session instance, you just do this:
// Setup the session properties for the message.
Properties sessionProperties = new Properties();
sessionProperties.put( "mail.smtp.host", m_smtpHost );
sessionProperties.put( "mail.smtp.port", Integer.toString( m_smtpPort ) );
// Get session
Session session = Session.getDefaultInstance( sessionProperties, null );
The mail.properties file could be a good way to specify the host/port of the SMTP
server as well. But the current implementation is still looking for its own Session.
Once option is to enhance this Factory, but I want to make sure I understand why it
is written the way it is and how it was designed to be used before playing around
with it.
Cheers, Leif
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Apache Excalibur Project -- URL: http://excalibur.apache.org/
