从 Camel 上下文中检索输出
Retrieve output from Camel Context
我有一个代码可以根据 Web 服务调用正确执行。并且它还记录 return SOAP Header。现在我需要在 UI 上显示相同的 xml,为此我需要从 camel 上下文中检索输出。
代码:
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=\">>> ${body}\"/>"
+ " <to uri=\"cxf://http://www.webservicex.net/stockquote.asmx?wsdlURL=src/wsdl/stockquote.wsdl&serviceName={http://www.webserviceX.NET/}StockQuote&portName={http://www.webserviceX.NET/}StockQuoteSoap&dataFormat=MESSAGE\"/>"
+ " <log loggingLevel=\"INFO\" message=\">>> ${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 服务的响应来获取 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
}
}
然后你可以将它添加到你的路由中(你需要将它添加到你的 camel 上下文注册表中):
<process id="myProcessor">
此外,为什么要在代码中使用 XML 符号。使用 Java DSL 表示法应该更容易。
我有一个代码可以根据 Web 服务调用正确执行。并且它还记录 return SOAP Header。现在我需要在 UI 上显示相同的 xml,为此我需要从 camel 上下文中检索输出。
代码:
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=\">>> ${body}\"/>"
+ " <to uri=\"cxf://http://www.webservicex.net/stockquote.asmx?wsdlURL=src/wsdl/stockquote.wsdl&serviceName={http://www.webserviceX.NET/}StockQuote&portName={http://www.webserviceX.NET/}StockQuoteSoap&dataFormat=MESSAGE\"/>"
+ " <log loggingLevel=\"INFO\" message=\">>> ${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 服务的响应来获取 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
}
}
然后你可以将它添加到你的路由中(你需要将它添加到你的 camel 上下文注册表中):
<process id="myProcessor">
此外,为什么要在代码中使用 XML 符号。使用 Java DSL 表示法应该更容易。