[logback-user] SMTPAppender OSGi-Problem within Glassfish v3.1.1 (Apache Felix)

Thorbjørn Ravn Andersen thunderaxiom at hotmail.com
Wed Jan 4 12:58:45 CET 2012


I did a google search for the exception text and found that this problem has
been reported by others.  You might find 

 

 
<http://stackoverflow.com/questions/1969667/send-a-mail-from-java5-and-java6
>
http://stackoverflow.com/questions/1969667/send-a-mail-from-java5-and-java6

 

relevant.

 

/Thorbjørn

 

From: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch] On
Behalf Of cinhtau
Sent: 4. januar 2012 11:14
To: logback-user at qos.ch
Subject: [logback-user] SMTPAppender OSGi-Problem within Glassfish v3.1.1
(Apache Felix)

 

Hi @all, I try to use SMTPAppender for logging errors to respective users
via E-Mail in OSGi. My configuration is: 

*	OS: Ubuntu Linux 10.04.03 LTS
*	Application Environment: Glassfish 3.1.1 using Apache Felix
*	Logback: tried logback classic Version 0.29 and current Version 1.0
leading to same results

Glassfish has following bundles 

 
g! lb mail
START LEVEL 10
   ID|State      |Level|Name
  227|Resolved   |    1|JavaMail API (1.4.4)

I write following BundleActivator (I switch the real addresses with stubs),
sending an email via SMTPAppender and Java Mail from scratch. 

 
package de.sgbs.log;
 
import java.util.logging.Level;
 
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
 
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
 
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
 
public class Activator implements BundleActivator {
 
    private final static Logger logger =
LoggerFactory.getLogger(Activator.class); 
 
        @Override
        public void start(BundleContext context) throws Exception {
            try {
                LoggerContext lc = (LoggerContext)
LoggerFactory.getILoggerFactory();
                JoranConfigurator configurator = new JoranConfigurator();
                configurator.setContext(lc);
                lc.reset();
                lc.putProperty("application-name",
Activator.class.getSimpleName());
                configurator.doConfigure("logback.xml");

                Marker notifyAdmin =
MarkerFactory.getMarker("NOTIFY_ADMIN");
                logger.error(notifyAdmin,
                  "This is a serious an error requiring the admin's
attention",
                   new Exception("Just testing"));
                
              } catch (JoranException ex) {
 
java.util.logging.Logger.getLogger(Activator.class.getName()).log(Level.SEVE
RE, null, ex);
              }
            
            sendEMail();
        }
 
        private void sendEMail() throws MessagingException {
            java.util.Properties props = new java.util.Properties();
        props.put("mail.smtp.host", "smtp");
        props.put("mail.smtp.port", "25");
        Session session = Session.getDefaultInstance(props, null);
 
        // Construct the message
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress("me at gmail.com"));
        msg.setRecipient(Message.RecipientType.TO, new
InternetAddress("foo at bar.com"));
        msg.setSubject("Test");
        msg.setText("Hello user, you got an error:");
 
        // Send the message
        Transport.send(msg);        
    }
 
    @Override
        public void stop(BundleContext context) {
            logger.info("Goodbye Community!");
        }
}

My logback.xml 

 
 
    
      NOTIFY_ADMIN
      TRANSACTION_FAILURE
    
    smtp
    foo at bar.com
    
    me at gmail.com
    TESTING: %logger{20} - %m
    
      %date %-5level %logger{35} - %message%n
           
  

Sending from scratch works. SMTPAppender raises an error. This error is
given on the osgi console: 

 
10:14:46,850 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction -
Attaching appender named [EMAIL] to Logger[ROOT]
10:14:47,048 |-ERROR in ch.qos.logback.classic.net.SMTPAppender[EMAIL] -
Error occured while sending e-mail notification.
javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: no object DCH for
MIME type multipart/mixed; 
        boundary="----=_Part_5_17758761.1325668486851"
        at javax.mail.MessagingException: IOException while sending message
        at      at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1141)
        at      at javax.mail.Transport.send0(Transport.java:195)
        at      at javax.mail.Transport.send(Transport.java:124)
        at      at
ch.qos.logback.core.net.SMTPAppenderBase.sendBuffer(SMTPAppenderBase.java:34
3)
        at      at
ch.qos.logback.core.net.SMTPAppenderBase.append(SMTPAppenderBase.java:179)
        at      at
ch.qos.logback.core.AppenderBase.doAppend(AppenderBase.java:85)
        at      at
ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(Appende
rAttachableImpl.java:64)
        at      at
ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:285)
        at      at
ch.qos.logback.classic.Logger.callAppenders(Logger.java:272)
        at      at
ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:473)
        at      at
ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:427)
        at      at ch.qos.logback.classic.Logger.error(Logger.java:610)
        at      at de.sgbs.log.Activator.start(Activator.java:37)
        at      at
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.jav
a:629)
...
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for
MIME type multipart/mixed; 
        boundary="----=_Part_5_17758761.1325668486851"
        at      at
javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
        at      at
javax.activation.DataHandler.writeTo(DataHandler.java:302)
        at      at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)
        at      at
javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772)
        at      at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1099)
        at      ... 47 common frames omitted
10:14:47,049 |-INFO in ch.qos.logback.classic.net.SMTPAppender[EMAIL] -
SMTPAppender [EMAIL] is tracking [1] buffers

First I thought MIME type multipart/mixed is the cause. I checked my SMTP
Server Settings, sending email is ok. I tried googlemail. It's working too.
I found another resource
<https://bugs.eclipse.org/bugs/show_bug.cgi?id=322398>  with the same error
message. Could it be an classloader problem? Could someone help me to
pinpoint the problem? Thanks in advance. 

  _____  

View this message in context: SMTPAppender OSGi-Problem within Glassfish
v3.1.1 (Apache Felix)
<http://old.nabble.com/SMTPAppender-OSGi-Problem-within-Glassfish-v3.1.1-%28
Apache-Felix%29-tp33078034p33078034.html> 
Sent from the Logback User mailing list archive
<http://old.nabble.com/Logback-User-f16252.html>  at Nabble.com.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120104/adcd0b7c/attachment-0001.html>


More information about the Logback-user mailing list