2017-06-06 23 views
0

這是.xml.ftl文件:如何使用jdbc:outbound-gateway捕獲org.springframework.messaging.MessageHandlingException?

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:jdbc="http://www.springframework.org/schema/integration/jdbc" 
     xmlns:integration="http://www.springframework.org/schema/integration" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans.xsd 
          http://www.springframework.org/schema/integration 
          http://www.springframework.org/schema/integration/spring-integration.xsd 
          http://www.springframework.org/schema/integration/jdbc 
          http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd"> 

    <!-- remove initial + from number --> 
    <integration:channel id="${provider_name}Channel"/> 
    <integration:header-enricher input-channel="${provider_name}Channel" 
           output-channel="catchException"> 
     <integration:header name="reformedNumber" 
          expression="T(com.tosan.chapar.core.helper.PhoneNumberHelper).removeInitialPlus(headers[recipient])"/> 
     <integration:header name="body" expression="payload"/> 
    </integration:header-enricher> 
    <!--to catch exception--> 
     <integration:channel id="catchException"/> 
     <integration:service-activator input-channel="catchException" 
             output-channel="${provider_name}reformedNumberChannel" 
             ref="providerExceptionHandller" method="catchProviderException"/> 

     <jdbc:outbound-gateway request-channel="${provider_name}reformedNumberChannel" 
           data-source="${provider_name}DataSource" 
           update="insert into `outgoing_message` (`from_mobile_number`, `dest_mobile_number`, `message_body`, `due_date`, `creation_date`, `udh`, `source_port`, `dest_port`, `dcs`, `priority`, `status`) 
               values ('${sms_number}', :headers[reformedNumber], :payload, now(), now(), '', :headers[port], :headers[port], :headers[dcs], :headers[priority], null);" 
           reply-channel="${provider_name}OutputChannel"/> 

JDBC的信道拋出 「org.springframework.messaging.MessageHandlingException」。我想將它作爲一個消息來處理它。我決定使用「ProviderExceptionHandller.class」並處理「catchProviderException()」方法中的異常。有可能的? 它是類代碼:

public class ProviderExceptionHandller { 
    public void catchProviderException() { 

     //// want to catch Exception here, How?????? 
    } 
} 

我如何能趕上Spring集成異常??? 我不想使用方面? 我的方法是可能的?

+0

**所有**異常的類型爲'Throwable'。你不能以這種方式使用服務激活器;您需要一個帶有錯誤通道的網關,但您應該顯示其餘配置,包括流程的開始,以便我們可以爲錯誤處理提供更好的建議。 –

+0

@Gray Russell ...謝謝你...(:更新我的問題,你能幫我嗎? –

回答

0

理解StackTrace存在問題。只需打開JdbcOutboundGateway即可看到它不是Exception。你可以考慮使用ExpressionEvaluatingRequestHandlerAdvicehttp://docs.spring.io/spring-integration/reference/html/messaging-endpoints-chapter.html#expression-advice。它的failureChannel選項可以幫助您發送一些分析錯誤。

另請參閱Error Handling一章。

UPDATE

好吧,如果你在你的服務方法要try...catch和處理來自集成信息流異常,你必須選擇從該服務的@MessagingGateway電話。這樣你就可以通過網關的代理方法調用try...catch。在這種情況下,您應該重組您的下游流程,並將網關方法的requestChannel作爲${provider_name}reformedNumberChannel

有關更多信息,請參閱Messaging Gateway

+0

thankyou ...我編輯了我的問題,你能再讀一遍嗎? –

+0

呃!對不起,我錯過了通知你在我的答案更新。 –