2017-04-07 58 views
0

我創建了一個簡單的流程,它創建一個名稱列表來轉換它。變換器拋出一個IllegalArgumentException來中斷流程。不幸的是,即使拋出異常,failureExpression也不起作用。它不符合任何例外。我已經包括了流量和變壓器。直到成功失敗表達條件不起作用

這裏是我的配置:

<?xml version="1.0" encoding="UTF-8"?> 
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" 
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://www.mulesoft.org/schema/mule/scripting  
     http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd  
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-current.xsd 
     http://www.mulesoft.org/schema/mule/core 
     http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
     http://www.mulesoft.org/schema/mule/vm 
     http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd 
     http://www.mulesoft.org/schema/mule/http  
     http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> 

    <spring:beans> 
     <spring:bean name="transf" class="com.until.sucessful.tests.StringAppenderTransformer" /> 
     <spring:bean id="objectStore" class="org.mule.util.store.SimpleMemoryObjectStore" /> 
    </spring:beans> 

    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" /> 

    <flow name="untilsuccessfultestsFlow"> 
     <http:listener config-ref="HTTP_Listener_Configuration" path="/mytest" doc:name="HTTP" /> 
     <splitter expression="#[xpath3('//Names')]" doc:name="Splitter" /> 
     <until-successful maxRetries="5" millisBetweenRetries="5000" doc:name="Until Successful" objectStore-ref="objectStore" failureExpression="#[exception is java.lang.IllegalArgumentException)]"> 
      <vm:outbound-endpoint path="process-vm" exchange-pattern="request-response" /> 
     </until-successful> 
     <logger level="INFO" message="After the scoped processor :: #[payload]" doc:name="Logger" /> 
    </flow> 

    <flow name="processorFlow"> 
     <vm:inbound-endpoint path="process-vm" exchange-pattern="request-response" /> 
     <logger level="INFO" message="Before component #[payload]" doc:name="Logger" /> 
     <transformer ref="transf" /> 
    </flow> 
</mule> 

這裏是我的變壓器

public class StringAppenderTransformer extends AbstractTransformer { 

    @Override 
    protected Object doTransform(Object src, String enc) throws TransformerException { 
     String payload = (String) src; 
     List<String> results = new ArrayList<>(); 
     System.out.println("Upon entry in transformer payload is :: " + payload); 
     System.out.println("About to return from transformer payload is :: " + payload.split("\\s+")); 
     int i = 1; 
     for (String args : payload.split("\\s+")) { 
      System.out.println("" + i + " " + args); 
      i++; 
      if (args != null && args.trim().equals("")) { 
       results.add(args); 
      } else { 
       throw new IllegalArgumentException("Break the Flow!!!!!!"); 
      } 

     } 

     return results; 
    } 
} 
+0

你可以檢查你在表達式中使用的表達式嗎?我猜表達式是錯誤的...請檢查使用它正確的方式: - http://stackoverflow.com/questions/20505855/until-successful-failure-expression-that-c​​hecks-for-multiple-types-of-例外 –

+0

表達式是檢查某個對象是否屬於某種類型的正確方法。我在其他流中使用了相同的類型表達式,並且它可以工作,例如,這是相同的測試,它在我的一個流中工作#[payload is java.util.Map]。如果我將表達式更改爲#[exception!= null],例如它可以工作。 – BreenDeen

回答

0

根據文檔: https://docs.mulesoft.com/mule-user-guide/v/3.5/until-successful-scope

failureExpression

指定一個表達式,當它評估爲真時,確定 表示一個路由的處理失敗。如果沒有提供表達式 ,則只有異常將被視爲處理失敗。

所以2個選項,刪除該表達式或確保MEL返回true。 #[exception.causeMatches(「java.lang.IllegalArgumentException」)]

+0

我解決了這個問題。建議我犯了一個錯誤。這是它應該是:#[groovy:異常instanceof java.lang.IllegalArgumentException] – BreenDeen

+0

謝謝大家的建議!非常感謝! – BreenDeen