File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Persistent queue email mimemessages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Persistent queue email mimemessages" Watch "Persistent queue email mimemessages" New topic

Persistent queue email mimemessages

Jeroen Bs

Joined: Sep 25, 2009
Posts: 9

Im working on a school project with java EE and hibernate. In my project i use a couple of EJB with have the option to send and recieve emails. There is a seperation between the beans who create the mail and the one actually using transport to send it. There are a couple of reasons why I choose to use that idea. One of which is to throttle the outgoing mail. The idea is as following:

1. Session Bean creates creates custom object. (The custom object has a couple of variables like date and status and criteria. One important part of the custom object is the email to send. This is a mimemessage)
2. Session Bean sends the custom object using JMS to a message bean.
3. The message is processed by the message bean which persists the custom object using hibernate (The table in the database with the persisted custom objects will be used as a queue)
4. Once ever x minutes a timer triggers a bean which will read the custom objects from the database (Using hibernate) and depending on the critera will read the mimemessage from the custom object and send it using transport.

My problem is that I cant find a way to store the actual mimemessage. My custom object has Message as a transient variable.I know that the mimemessage isnt serializeable. My custom object has Message as a transient variable and a Byte [] serialMessage. So I tried to use the writeTo() methode and store it as a byte [] in the "private void writeObject(ObjectOutputStream out) throws IOException" method. But somehow it doesnt work.

The problem i'm running into is that the message doesnt seem to have have any content because of the runtime exception: No Content. Even though I create the mimemessage and do: message.setContent("This is a test", "text/plain");

I feel i'm building something way to complex for what I want. I just want to create a mimemesaage and store it with some extra fields in a persistent queue (For buffering/throttling and save it in case of a crash). Any here got some tips how to achieve this ?

Jeroen Bs

Joined: Sep 25, 2009
Posts: 9
Well I fixed it and i am able to serialize mail messages (For use in jms/ejb class) and persist them using hibernate. My code had some small bugs and I forgot to rebuilt my transient fields when I retrieve the custom object using hibernate. Hibernate doesnt use serialize and therefore does not run my deserialize methode (doh! how could I miss that) and leaving my transient fields empty ;)

Though I still think it would be nice if sun provided a serializeable alternative for the mimemessage so I dont have to build a custom serialize function
I agree. Here's the link:
subject: Persistent queue email mimemessages
It's not a secret anymore!