Ok, I find it.
If I'm right, in order to convert a mailet from 2.2 to 3.0

At least, we have to change :

  /* ok with James 2.2.0
  ComponentManager componentManager = (ComponentManager)
                        getMailetContext().getAttribute(
                                Constants.AVALON_COMPONENT_MANAGER);
  DataSourceSelector datasources (DataSourceSelector)
                componentManager.lookup(DataSourceSelector.ROLE);
  */

  ServiceManager serviceManager = (ServiceManager)      
                        getMailetContext().getAttribute(
                                Constants.AVALON_COMPONENT_MANAGER);

  DataSourceSelector datasources = (DataSourceSelector)
                        serviceManager.lookup(DataSourceSelector.ROLE);


Does someone already list the Mailet API change? I noticed that all the mailet into the v3 have been changed...


Laurent Rouvet



Laurent Rouvet wrote:
Hi,

I'm trying to move my mailet to james-3.0-dev (mainly because I've a connection pool bug to fix and that I'm currently using james 2.2.1RC1 but I don't have the source for that version).

First of all, I would to said that each time (it's the second time) that I'm moving my code to a new James version, I spend several hours in order to be able to compile and deploy.
I think that it's not a James issue but that problem come from phoenix and avalon which are complicated, not soo stable, and not well finished.
However I think that framework is technicaly quite nice, I had probably choiced it too.


So, regarding previus discussions, I'd encourage to choice a more stable and well know framework. I'd like a J2EE framework like Jboss or Geronimo (if that one be come enought usable).


Back to my problem:

I'm use james-3.0-dev 170743   which compile and work ok  :-D
but I've several problems with my own mailet:

- I've notice that cornerstone.jar is not used anymore but replaced by a list of small jar: cornerstone-XXXX-api/impl-1.0.jar

 -> is it right ?
    because my mailet don't compile because the package
org.apache.avalon.service.datasource(s) use NOW a (s)


That small problem fixed, I'm able to compile it, but I got the following error at start:



20/05/05 11:44:08 ERROR spoolmanager: Unable to init mailet EmailSupportStore: javax.mail.MessagingException: Error initializing EmailSupportStore;
nested exception is:
java.lang.ClassCastException
javax.mail.MessagingException: Error initializing EmailSupportStore;
nested exception is:
java.lang.ClassCastException
at email.james.mailets.EmailSupportStore.init(EmailSupportStore.java:56)
at org.apache.mailet.GenericMailet.init(GenericMailet.java:129)
at org.apache.james.transport.MailetLoader.getMailet(MailetLoader.java:60)
at org.apache.james.transport.JamesSpoolManager.initialize(JamesSpoolManager.java:250)


at org.apache.avalon.framework.container.ContainerUtil.initialize(ContainerUtil.java:282)

at org.apache.excalibur.containerkit.lifecycle.LifecycleHelper.startup(LifecycleHelper.java:144)

at org.apache.avalon.phoenix.components.application.DefaultApplication.startup(DefaultApplication.java:480)

...


My code (full code attached):

 try {
   ComponentManager componentManager =
      (ComponentManager)getMailetContext().getAttribute(
                Constants.AVALON_COMPONENT_MANAGER);
   DataSourceSelector datasources =
    (DataSourceSelector)componentManager.lookup(
                    DataSourceSelector.ROLE);
   datasource = new DataSourceWrapper(
    (DataSourceComponent)datasources.select(datasourceName));
   if (crmDatasourceName != null)
    crmDatasource = new DataSourceWrapper(
      (DataSourceComponent)datasources.select(crmDatasourceName));
 }
 catch (Exception e) {
    // line 56
    throw new
    MessagingException("Error initializing EmailSupportStore", e);
 }



Does there is some compatibility issue between james 2.2 and james 3?
Does I'm using the right version? or does I mixing wrong APIs?
Any idea of my ClassCastException error?

Thanks

Laurent Rouvet



------------------------------------------------------------------------



package email.james.mailets;


import javax.mail.MessagingException; import javax.mail.internet.MimeMessage;

import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
import org.apache.avalon.excalibur.datasource.DataSourceComponent;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.james.Constants;
import org.apache.james.util.JDBCUtil;
import org.apache.log4j.Logger;
import org.apache.mailet.GenericMailet;
import org.apache.mailet.Mail;
import org.apache.mailet.MailetException;

import email.james.util.DataSourceWrapper;
import email.model.EMail;

public class EmailSupportStore extends GenericMailet {
    static Logger logger = Logger.getLogger(EmailSupportStore.class);

     protected DataSourceWrapper datasource;
     protected DataSourceWrapper crmDatasource;
         protected String datasourceName;
         protected String crmDatasourceName;

     private final JDBCUtil theJDBCUtil =  new JDBCUtil() {
                 protected void delegatedLog(String logString) {
                        log("EmailSupportStore: " + logString);
                 }
     };

     // code from JDBCListserv
     public void init() throws MessagingException {
                 datasourceName = getInitParameter("datasource");
                 crmDatasourceName = getInitParameter("CRMdatasource");
         logger.info("Initialisation datasource="+ datasourceName +" 
CRMdatasource="+crmDatasourceName);
                 if (datasourceName == null) {
                        throw new MailetException("datasource not specified for 
EmailSupportStore");
                 }
                 if (crmDatasourceName == null) {
                        logger.info("CRMdatasource not specified for 
EmailSupportStore");
                 }

                 try {
                         ComponentManager componentManager = 
(ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
                         DataSourceSelector datasources = 
(DataSourceSelector)componentManager.lookup(DataSourceSelector.ROLE);
                         datasource = new 
DataSourceWrapper((DataSourceComponent)datasources.select(datasourceName));
                         if (crmDatasourceName != null)
                                 crmDatasource = new 
DataSourceWrapper((DataSourceComponent)datasources.select(crmDatasourceName));
                 }
                 catch (Exception e) {
                        throw new MessagingException("Error initializing 
EmailSupportStore", e);
                 }
    }

    public void service(Mail mail) throws MessagingException {
        MimeMessage message = mail.getMessage();

        try {
            EMail.received(datasource, datasourceName, crmDatasource, 
crmDatasourceName, message);
        } catch (Exception ex) {
            getMailetContext().log("Error while storing mail to Email Support: 
",
                    ex);
            getMailetContext().sendMail(mail.getSender(), mail.getRecipients(),
                    message, Mail.ERROR);
        }
        // We always consume this message
        mail.setState(Mail.GHOST);
    }
}



------------------------------------------------------------------------

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


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



Reply via email to