作者u9423504 (緣投農夫)
看板java
標題[問題] 關於IBM lotus Notes的Exception補抓
時間Fri Feb 12 15:17:18 2016
各位前輩好:
小弟目前的專案有一個需求,那就是使用Notes來寄公司的內部信。
小弟的實做方式是使用Notes Client的API調用Notes Client來達到寄信功能。
目前這支的程式已經實做出來了,而且能正常運作。
然而,在 RESTful Web Service 的程式中,調用那一支寄信的程式,使用try/catch
卻補抓不到 NotesException的異常訊息。
程式碼節錄如下:
(1)MailSent程式碼節錄:
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.EmbeddedObject;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;
import lotus.domino.RichTextItem;
import lotus.domino.RichTextStyle;
import lotus.domino.Session;
import lotus.domino.NotesException;
public class MailSent extends NotesThread{
String pwd;
String attche;
String NameNsf;
String Subject;
String SentTo;
String Name;
Document MailContent =null;
Session session= null;
public MailSent(String pwd,String attche,String NameNsf,String subject,String
sent){
this.pwd= pwd;
this.attche= attche;
this.NameNsf = NameNsf;
this.Subject=subject;
this.SentTo=sent;
}
public void runNotes()throws NotesException {
session = NotesFactory.createSessionWithFullAccess(pwd);
.
.
.
(省略)
MailContent.sent(false,SentTo);
}
}
------------------------------------------------------------------
(2)RESTful Web API程式節錄:
@GET
@Path("/SendMail/{SendTo}")
public Response MailSend(@PathParam("SendTo") String SendTo){
String pwd = config.GetValue("MailPwd");
String NameNsf = config.GetValue("MailNameNsf");
String Subject="xxxxx";
String attch="c:\\xx.doc";
try{
MailSent mailSend = new
MailSent(pwd,attch,NameNsf,Subject,SendTo);
mailSend.start();
return Response.ok("MailSend_Ok").build();
}catch(NotesException e){
log.error("Mail Send Failed!"+e.text);
return Response.status(500).entity(e.text).build();
}
}
----------------------------------------------------------------------
問題就是出在上述的 RESTful Web API中調用寫好的MailSent的程式,卻補抓不到
NotesException的異常訊息(若異常發生時。)小弟認為應該是出在該支MailSent
是一支執行緒,因此若發生異常時在web api中才會補抓不到異常訊息。若要在上述
RESTful的程式中補抓NotesException的訊息,是否有方法可行呢?!
--
陰律無情!是的,犯邪淫者,小如手淫、婚前性行為
均會遭折福減壽之惡報。國考者更不能犯淫邪,
否則文昌帝君會除去功名,不信請看此懺悔文:
http://lustwarn.blogspot.tw/
陰律無情!是的,犯邪淫者,若不懺悔發心改過永不再犯,
死後必入邪淫地獄,不信請看;
http://goo.gl/tchBZY
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 14.188.239.227
※ 文章網址: https://www.ptt.cc/bbs/java/M.1455261443.A.E27.html
推 asship: 是否為多執行緒的問題呢? 發生錯誤的時候程式已經離開 02/13 11:53
→ asship: try-catch區塊 02/13 11:54
→ asship: 以前也在notes寫過JAVA,好久了,你看看原廠文件 02/13 11:55
→ asship: 他有一些範例可以參考 02/13 11:55
推 asship: 剛剛找了一下以前寫的筆記,發信不需要繼承notesthread 02/13 12:44
→ asship: 如果你需要等做完之後得到結果,可以用ExecutorService 02/13 12:45
→ asship: 不太確定你為什麼開了一個執行緒之後就丟回應成功 02/13 12:46
推 asship: 如果你有一定要繼承NotesThread的理由 02/13 13:00
→ asship: 上面這個連結你再參考一下 02/13 13:07