2016-08-02 54 views
1

我的要求是要通過計算如JDBC,Web服務等外部資源所消耗的總時間,端點信息

我在添加請求處理程序,建議鏈所需的端點並計算時間。它完美的作品。 我也必須添加端點組件的標識符。有什麼辦法通過建議類獲得端點ID。

例:

<int-jdbc:stored-proc-outbound-gateway id="myProcID" request-channel="myChannel" data-source="dataSource" 
.... 
     <int-jdbc:request-handler-advice-chain> 
      <ref bean="statsAdvice" /> 
     </int-jdbc:request-handler-advice-chain> 
    </int-jdbc:stored-proc-outbound-gateway> 

我能在諮詢類的JDBC端點ID?請建議。 在此先感謝。

建議類擴展了AbstractRequestHandlerAdvice,當我嘗試轉換時 NamedComponent component =(NamedComponent)target;

我得到下面的異常 - org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.jdbc.StoredProcOutboundGateway#0]; nested exception is java.lang.ClassCastException: org.springframework.integration.handler.AbstractReplyProducingMessageHandler$AdvisedRequestHandler

修復工作正常使用4.3.2版本:

((AbstractReplyProducingMessageHandler.RequestHandler) target).getAdvisedHandler().getComponentName(); 

回答

0

如果你的建議延長AbstractRequestHandlerAdvice目標對象是可作爲doInvoke參數 - 見the javadocs

將其轉換爲NamedComponent並致電getComponentName()

如果您直接實施了MethodInterceptor,請使用invocation.getThis()獲取對處理程序的引用。

+0

請參閱編輯的問題.. –

+0

您的幫助是高度讚賞。 –

+0

哦,是的;抱歉;我忘記了這個包裝 - 我們應該提供訪問它的代表;請打開一個改進[JIRA問題](https://jira.spring.io/browse/INT)。 –