[問題] 關於IBM lotus Notes的Exception補抓

看板java作者 (緣投農夫)時間9年前 (2016/02/12 15:17), 編輯推噓4(407)
留言11則, 1人參與, 最新討論串1/1
各位前輩好: 小弟目前的專案有一個需求,那就是使用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

02/13 11:53, , 1F
是否為多執行緒的問題呢? 發生錯誤的時候程式已經離開
02/13 11:53, 1F

02/13 11:54, , 2F
try-catch區塊
02/13 11:54, 2F

02/13 11:55, , 3F
以前也在notes寫過JAVA,好久了,你看看原廠文件
02/13 11:55, 3F

02/13 11:55, , 4F
他有一些範例可以參考
02/13 11:55, 4F

02/13 12:44, , 5F
剛剛找了一下以前寫的筆記,發信不需要繼承notesthread
02/13 12:44, 5F

02/13 12:45, , 6F
如果你需要等做完之後得到結果,可以用ExecutorService
02/13 12:45, 6F

02/13 12:46, , 7F
不太確定你為什麼開了一個執行緒之後就丟回應成功
02/13 12:46, 7F

02/13 13:00, , 8F
如果你有一定要繼承NotesThread的理由
02/13 13:00, 8F

02/13 13:02, , 9F
http://0rz.tw/siSrJ 幫你找到一篇這個,我也沒用過
02/13 13:02, 9F

02/13 13:07, , 10F

02/13 13:07, , 11F
上面這個連結你再參考一下
02/13 13:07, 11F
文章代碼(AID): #1MlOS3ud (java)
文章代碼(AID): #1MlOS3ud (java)