简体   繁体   English

在Web应用程序之间共享消息对象

[英]sharing message object between web applications

I need to share java mail message objects between two web applications(A and B). 我需要在两个Web应用程序(A和B)之间共享Java邮件对象。

WebApplication A obtains the message and write it to the outputStream WebApplication A获取消息并将其写入outputStream

for(int i=0;i<messagesArr.length;i++){
  uid = pop3FolderObj.getUID(messagesArr[i]);
//storing messages with uid names inorder to maintain uniqueness
  File f = new File("F:/PersistedMessagesFolder" + uid);  
  FileOutputStream fos = new FileOutputStream(f);
  messagesArr[i].writeTo(fos);
  fos.flush();
  fos.close();
}

Is FileOutputStream the best output stream for persisting message objects? FileOutputStream是持久存储消息对象的最佳输出流吗? Is it possible to use ObjectOutputStream for message object persistence? 是否可以将ObjectOutputStream用于消息对象持久性?

WebApplication B reads the message object via InputStream WebApplication B通过InputStream读取消息对象

FileInputStream fis = new FileInputStream("F:/MessagesPersistedFolder"+uid);
MimeMessage mm = new MimeMessage(sessionObj,fis);

What if the mail message object which is already written via WebApplication A is not a MimeMessage? 如果已经通过WebApplication A编写的邮件消息对象不是MimeMessage,该怎么办? How can I read non-mime messages using input stream? 如何使用输入流阅读非哑剧消息?

MimeMessage constructor mandates sessionObj as the first parameter? MimeMessage构造函数要求sessionObj作为第一个参数? How can I obtain this sessionObj in WebApplicationB? 如何在WebApplicationB中获取此sessionObj? Do I have to again establish store connection with the same emailid,emailpassword,popserver and port(already used in WebApplication A) with the email server inorder to obtain this session object? 是否需要与电子邮件服务器再次使用相同的emailid,emailpassword,popserver和port(已在WebApplication A中使用)建立存储连接,以便获取此会话对象? Even if obtained, will this session object remains the same as that of the session object which is priorly obtained in WebApplicationA? 即使获得了该会话对象,它也将保持与先前在WebApplicationA中获得的会话对象的相同吗?

Since I am using uids to name Message objects (inorder to maintain uniqueness of file names) how can I share these uids between WebApplication A and WebApplication B? 由于我使用uid来命名消息对象(以保持文件名的唯一性),我如何在WebApplication A和WebApplication B之间共享这些uid? WebApplication B needs the uid inorder to access the specific file which is present in "F:/MessagesPersistedFolder" WebApplication B需要uid才能访问“ F:/ MessagesPersistedFolder”中存在的特定文件

Please help me in resolving the aforeseen issues. 请帮助我解决上述问题。

What are the actual features you are trying to implement here? 您要在此处实现的实际功能是什么? It sounds like you're trying to fit a square peg (the Javamail message classes) in a round hole (the requirement to share message data between two applications). 听起来您正在尝试将方钉(Javamail消息类)安装在圆孔中(在两个应用程序之间共享消息数据的要求)。

My advice would be either: 我的建议是:

1) use a message queue and send the email message content from one application to the other using a javax.jms.TextMessage . 1)使用消息队列,并使用javax.jms.TextMessage将电子邮件内容从一个应用程序发送到另一个应用程序。

2) or save the message content to a clob field in shared database that both applications access. 2)或将消息内容保存到两个应用程序都可以访问的共享数据库的clob字段中。

At the end of the day, use the Javamail API for sending email not as a means to share data. 在一天结束时,请使用Javamail API发送电子邮件,而不是共享数据。

Also using serialization , which is what you'd be doing with an java.io.ObjectOutputStream will produce files that will only work with a specific version of the Javamail API and while I doubt Javamail changes much these days, I wouldn't want to exclude the possiblity. 同样使用序列化 ,这就是您对java.io.ObjectOutputStream它将产生仅适用于特定版本的Javamail API的文件,尽管我怀疑Javamail如今已经发生了很大变化,但我不想排除可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM