簡體   English   中英

從駱駝上下文檢索輸出

[英]Retrieve output from Camel Context

我有一個代碼,可以按照Web服務調用正確執行。 並且還記錄返回的SOAP Header。 現在,我需要在UI上顯示相同的xml,為此,我需要從駱駝上下文中檢索輸出。

代碼:

DefaultCamelContext context = new DefaultCamelContext();

    // append the routes to the context
    String myString = "<route id=\"my_Sample_Camel_Route_with_CXF\" xmlns=\"http://camel.apache.org/schema/spring\">"
            + "      <from uri=\"file:///home/viral/Projects/camel/cxfJavaTest/src/data?noop=true\"/>"
            + "    <log loggingLevel=\"INFO\" message=\"&gt;&gt;&gt; ${body}\"/>"
            + "   <to uri=\"cxf://http://www.webservicex.net/stockquote.asmx?wsdlURL=src/wsdl/stockquote.wsdl&amp;serviceName={http://www.webserviceX.NET/}StockQuote&amp;portName={http://www.webserviceX.NET/}StockQuoteSoap&amp;dataFormat=MESSAGE\"/>"
            + "  <log loggingLevel=\"INFO\" message=\"&gt;&gt;&gt; ${body}\"/>"
            + "    </route>";
    ;

    InputStream is =  new ByteArrayInputStream(myString.getBytes());
    RoutesDefinition routes = context.loadRoutesDefinition(is);
    context.addRouteDefinitions(routes.getRoutes());
    context.setTracing(true);

    context.start();

    Thread.sleep(3000);     

    System.out.println("Done");
    context.stop();

是否有任何方法可以使用上下文變量來獲取Web服務輸出,或者是否有其他方法可以獲取使用log語句打印的Web服務的響應?

如果您提供的代碼比它對我非常有幫助。

提前致謝。

您可以創建一個自定義處理器,以訪問您的路線中的數據。

class MyProcessor extends Processor {

  public void process(Exchange exchange) throws Exception {
    String body = exchange.getIn().getBody(String.class); //Maybe you need some other type.
   //do your logic here
  }

}

然后,您可以將其添加到路由中,例如(您需要將其添加到駱駝上下文注冊表中):

<process id="myProcessor">

另外,為什么要在代碼中使用XML表示法。 使用Java DSL表示法應該更容易。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM