2012-06-12 187 views
0

我想僅顯示我的消息以供露天工作流異常使用。但在露天異常消息格式是 1. exception.class.name 2. ErrorLogNumber 3.消息Alfresco異常消息格式

例如, org.alfresco.service.cmr.workflow.WorkflowException:05130007 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

我只想顯示3.Message不是1.exception.class.name和2.ErrorLogNumber。我可以通過添加自定義異常類來從消息中刪除ErrorLogNumber。但是我不能從錯誤信息中刪除1.exception.class.name。 讓我知道如何實現這一點。

+0

您是否嘗試使用'getMessage()'獲取消息,而不是在異常處調用'toString()'? – Gagravarr

回答

0

您是否嘗試在您的異常類中重寫toString?或者也許改變記錄器的實現,如果輸出以這種方式打印。

0

我和你有類似的問題,並且無法跟蹤甚至使用調試器創建此消息的位置,這相當複雜。此外,Alfresco論壇上的任何人都不能幫助我。 我開發了一個解決方法,而不是直接在java工作流任務中拋出異常,我在表單中使用了一個JS驗證(我在另一篇文章中告訴過你的方式),在那裏我調用了一個使用ajax的java webscript,在出現錯誤時顯示JS警報框。

1

該解決方案非常簡單。只需將AlfrescoRuntimeException與您的消息。

throw new AlfrescoRuntimeException("your.message"); 

在這種情況下,您會收到一條消息,但是會發生異常分類。

這是真的很難用言語來解釋露天JavaScript代碼看到異常處理時,我是如何驚訝:

 onFormSubmitFailure: function FormManager_onFormSubmitFailure(response) 
     { 
      var failureMsg = null; 
      if (response.json && response.json.message && response.json.message.indexOf("Failed to persist field 'prop_cm_name'") !== -1) 
      { 
       failureMsg = this.msg("message.details.failure.name"); 
      } 
      else if (response.json && response.json.message && response.json.message.indexOf("PropertyValueSizeIsMoreMaxLengthException") !== -1) 
      { 
       failureMsg = this.msg("message.details.failure.more.max.length"); 
      } 
      else if (response.json && response.json.message && response.json.message.indexOf("org.alfresco.error.AlfrescoRuntimeException") == 0) 
      { 
       var split = response.json.message.split(/(?:org.alfresco.error.AlfrescoRuntimeException:\s*\d*\s*)/ig); 
       if (split && split[1]) 
       { 
        failureMsg = split[1]; 
       } 
      } 
      Alfresco.util.PopupManager.displayPrompt(
      { 
       title: this.msg(this.options.failureMessageKey), 
       text: failureMsg ? failureMsg : (response.json && response.json.message ? response.json.message : this.msg("message.details.failure")) 
      }); 
     }, 

正如你可以從Java看他們「抓」類名稱和消息替換它。我希望他們提供更可擴展的方式來處理客戶的例外情況。

P.S.當然,另一種方法是擴展alfresco.js文件併爲您例外添加一個if else條件。