2013-12-10 29 views
0

我已經爲wso2創建並部署了一個java服務。我需要在WSO2中創建一個序列,以便在Java服務發出某個錯誤響應的情況下將故障轉移到另一個端點。我想爲某些錯誤代碼使用端點功能「suspendOnFailure」和「markForSuspension」,但是我沒有找到從Java服務中拋出某個錯誤代碼的方法。WSO2生成並使用自定義錯誤代碼

有沒有什麼辦法可以在java中拋出一個錯誤代碼,這個錯誤代碼會被端點解釋,以便在一段時間內將其標記爲「暫停失敗」?

我試着使用一個makefault中介,但我不知道如何拋出一個錯誤代碼從這個(或其他)中介,可以在稍後解釋「suspendOnFailure」。

下面我試圖使用PGWFAULT服務來總是發送一個錯誤代碼,該錯誤代碼將被「suspendOnFailure」解釋。它不工作的方式......引用到暫停端點定義

<proxy name="CommandClientService" transports="https http" startOnLoad="true" 
      trace="enable"> 
     <description/> 
     <target> 
     <endpoint name="FaultyOne"> 
      <address uri="http://localhost:8282/services/PGWFAULT"> 
       <suspendOnFailure> 
        <errorCodes>101500</errorCodes> 
        <initialDuration>1</initialDuration> 
        <progressionFactor>1.0</progressionFactor> 
        <maximumDuration>1</maximumDuration> 
       </suspendOnFailure> 
       <markForSuspension> 
        <errorCodes>101500</errorCodes> 
        <retriesBeforeSuspension>20</retriesBeforeSuspension> 
        <retryDelay>1</retryDelay> 
       </markForSuspension> 
      </address> 
     </endpoint> 
     <faultSequence> 
      <log level="full"> 
       <property name="text" value="Fault sequence activatesNOW"/> 
       <property name="message" expression="get-property('ERROR_MESSAGE')"/> 
      </log> 
      <send> 
       <endpoint key="errorProvider"/> 
      </send> 
     </faultSequence> 
     </target> 
    </proxy> 


<proxy name="PGWFAULT" transports="https http" startOnLoad="true" trace="enable"> 
     <description/> 
     <target> 
     <endpoint key="Local"/> 
     <outSequence> 
      <makefault version="soap12"> 
       <code xmlns:soap12Env="http://www.w3.org/2003/05/soap-envelope" 
        value="soap12Env:Receiver"/> 
       <reason value="101500"/> 
       <node/> 
       <role>asdcasdf</role> 
       <detail>a fault to be taken into account</detail> 
      </makefault> 
      <send/> 
     </outSequence> 
     </target> 
    </proxy> 

回答

0

錯誤代碼是基於HTTP錯誤代碼

您可以在調解類似的設置這樣的錯誤代碼:

<property name="HTTP_SC" value="500" scope="axis2"/> 

對於端點錯誤處理錯誤代碼的列表,請參閱http://docs.wso2.org/display/ESB480/Endpoint+Error+Handling

我想你會很容易找到如何設置它在Java。 ..

對於HttpServletResponse對象上爲例:

response.sendError(response.SC_NOT_FOUND, "No XXX specified."); 
+0

謝謝你,讓 - 米歇爾! – user2493522