2 Replies Latest reply on Mar 28, 2004 5:55 PM by john redden

    whether javamail activation frame work ?

    john redden Newbie

      I have a nice set of session and entity beans running under JBoss 3.X that distribute content as long as it is html or text. In addition want to send gifs and jpegs. Plowing thtough posts and documentation it looks like I need to add a JavaMail DataSource to process jpegs and gifs. Has anyone done this with javamail? Did you have to add a mailcap file to a war file? Anybody had experience with this? Any alternatives to javamail? I looked at James and it was of little help.


      JohnRedden@aol.com

        • 1. Re: whether javamail activation frame work ?
          Andrew Oliver Master

          It doesn't sound like you need Mail Services just to send some files. It might help you to use mail services (for queueing and so forth, so that you don't need a separate mail server). The JBoss Admin + Development guide shows you how to set up a J2EE JavaMail conifg.

          • 2. Re: whether javamail activation frame work ?
            john redden Newbie

            Problem solved. It took something like this:

            (though a more elegant solution is out there in refactor land ...)


            ------------------- source start ------------------------------

            package com.zenred.advert;

            import java.io.InputStream;
            import java.io.OutputStream;
            import java.io.ByteArrayOutputStream;
            import java.io.ByteArrayInputStream;

            import java.io.IOException;
            import javax.activation.DataSource;
            import javax.ejb.FinderException;

            import com.zenred.advert.interfaces.DocumentFilterIF;

            /**
            *
            */
            public class ByteStreamDataSource implements DataSource {

            private String key;
            private Short stream_size;
            private DocumentFilterIF delegated_o;
            public ByteStreamDataSource (String key,
            Short stream_size,
            DocumentFilterIF delegated_o
            ){
            this.key = key;
            this.stream_size = stream_size;
            this.delegated_o = delegated_o;
            }


            public InputStream getInputStream()
            throws IOException{
            try{
            return new ByteArrayInputStream(DocumentSizeMap.getDocument(stream_size,
            key,
            delegated_o));
            }
            catch(FinderException fe){
            throw new IOException(fe.getMessage());
            }
            }

            public OutputStream getOutputStream()
            throws IOException{
            return new ByteArrayOutputStream();
            }

            private String content_type;
            public String getContentType(){
            return content_type;
            }

            public void setContentType(String content_type){
            this.content_type = content_type;
            }

            public String getName(){
            return key;
            }



            }





            package com.zenred.advert;

            import javax.ejb.RemoveException;
            import javax.ejb.FinderException;
            import java.rmi.RemoteException;

            import javax.mail.Message;
            import javax.mail.MessagingException;
            import javax.mail.Multipart;
            import javax.mail.internet.MimeBodyPart;
            import javax.mail.internet.MimeMultipart;



            import javax.activation.DataSource;
            import javax.activation.DataHandler;

            import com.zenred.advert.interfaces.ContentFactoryIF;
            import com.zenred.advert.interfaces.DocumentFilterIF;
            import com.zenred.advert.interfaces.AdvertMailException;

            /**
            * ContentComplex.java
            *
            *
            * Created: Sun Mar 21 14:33:43 2004
            *
            * @author
            * @version
            */

            public class ContentComplex implements ContentFactoryIF{
            public ContentComplex () {
            }

            public Message getContent(Message message, String key, DocumentFilterIF delegated_object)throws AdvertMailException{

            String _content_type =
            MimeMapAvecExtensions.getContentTypeFor(key);
            String msgText = key;

            try{
            Short stream_size = delegated_object.prepareDocument(key);

            MimeBodyPart mbp1 = new MimeBodyPart();
            mbp1.setContent(msgText, "text/plain");

            MimeBodyPart mbp2 = new MimeBodyPart();
            ByteStreamDataSource bytestreamdatasource = new ByteStreamDataSource(key, stream_size, delegated_object);
            bytestreamdatasource.setContentType(_content_type);
            // mbp2.setContent(_content_type);
            mbp2.setDataHandler(new DataHandler(bytestreamdatasource));

            Multipart mp = new MimeMultipart();
            mp.addBodyPart(mbp1);
            mp.addBodyPart(mbp2);

            message.setContent(mp);
            }
            catch(FinderException fe){
            fe.printStackTrace();
            throw new AdvertMailException(fe.getMessage());
            }
            catch(RemoteException re){
            re.printStackTrace();
            throw new AdvertMailException(re.getMessage());
            }
            catch(MessagingException me){
            me.printStackTrace();
            throw new AdvertMailException(me.getMessage());
            }
            return message;
            }


            }// ContentComplex




            package com.zenred.advert;

            import com.zenred.advert.interfaces.ContentFactoryIF;

            /**
            * ContentFactory.java
            *
            *
            * Created: Sun Mar 21 14:48:54 2004
            *
            * @author
            * @version
            */

            public class ContentFactory {

            private static String text_plain = "text/plain";
            private static String text_html = "text/html";

            public static ContentFactoryIF getInstance(String type){
            if(type.equals(text_plain) ||
            type.equals(text_html)) {
            return new ContentSimple();
            }
            else{
            return new ContentComplex();
            }
            }

            }// ContentFactory