我创建了驼峰路由并存储在数据库中,我需要加载并运行。
直到现在我创建的代码是动态创建的路由,但结果不符合预期。
我已经下载了CXF的示例并使用mvn camel运行:运行它运行,结果它正在调用Web服务,但现在我需要一个create java项目并调用,我有一个String in String变量。所以加载路由,存储为String,并调用Web服务。
代码相同:
public static void main(String[] args) throws Exception {
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: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);
// at the end start the camel context
context.start();
Thread.sleep(3000);
context.stop();
System.out.println("Done");
/***
* Jars are
*
aopalliance-1.0.jar
asm-3.3.jar
camel-core-2.6.0-fuse-00-00.jar
camel-cxf-2.6.0-fuse-00-00.jar
camel-http-2.6.0-fuse-00-00.jar
camel-spring-2.6.0-fuse-00-00.jar
commons-codec-1.2.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
commons-management-1.0.jar
cxf-api-2.3.2-fuse-00-00.jar
cxf-common-schemas-2.3.2-fuse-00-00.jar
cxf-common-utilities-2.3.2-fuse-00-00.jar
cxf-rt-bindings-soap-2.3.2-fuse-00-00.jar
cxf-rt-bindings-xml-2.3.2-fuse-00-00.jar
cxf-rt-core-2.3.2-fuse-00-00.jar
cxf-rt-databinding-jaxb-2.3.2-fuse-00-00.jar
cxf-rt-frontend-jaxrs-2.3.2-fuse-00-00.jar
cxf-rt-frontend-jaxws-2.3.2-fuse-00-00.jar
cxf-rt-frontend-simple-2.3.2-fuse-00-00.jar
cxf-rt-transports-common-2.3.2-fuse-00-00.jar
cxf-rt-transports-http-2.3.2-fuse-00-00.jar
cxf-rt-ws-addr-2.3.2-fuse-00-00.jar
cxf-tools-common-2.3.2-fuse-00-00.jar
geronimo-javamail_1.4_spec-1.7.1.jar
geronimo-servlet_2.4_spec-1.1.1.jar
jaxb-impl-2.1.13.jar
jettison-1.2.jar
jsr311-api-1.1.1.jar
log4j-1.2.16.jar
neethi-2.0.4.jar
spring-aop-3.0.5.RELEASE.jar
spring-asm-3.0.5.RELEASE.jar
spring-beans-3.0.5.RELEASE.jar
spring-context-3.0.5.RELEASE.jar
spring-core-3.0.5.RELEASE.jar
spring-expression-3.0.5.RELEASE.jar
spring-tx-3.0.5.RELEASE.jar
spring-web-3.0.5.RELEASE.jar
stax2-api-3.0.2.jar
woodstox-core-asl-4.0.8.jar
wsdl4j-1.6.2.jar
xml-resolver-1.2.jar
XmlSchema-1.4.7.jar
*/
}
运行相同的程序后我就像
一样Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
log4j:WARN No appenders could be found for logger (org.apache.camel.impl.DefaultCamelContext).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Jun 11, 2015 12:36:19 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://www.webserviceX.NET/}StockQuote from WSDL: src/wsdl/stockquote.wsdl
Done