Java 在主类中调用驼峰路由终结点

Java 在主类中调用驼峰路由终结点,java,apache-camel,Java,Apache Camel,我创建了一个带有端点'direct:getRestFromExternalService'的Camel路由,当我尝试在另一个类的main方法中使用该端点时,我得到了一个异常 在exchange上执行期间发生异常:exchange[ID-WMLI118067-61025-1493883025815-0-2] 及 终结点上没有可用的使用者:终结点[direct://getRestFromExternalService]. 交易所[ID-WMLI118067-61025-149383025815-0-

我创建了一个带有端点'direct:getRestFromExternalService'的Camel路由,当我尝试在另一个类的main方法中使用该端点时,我得到了一个异常

在exchange上执行期间发生异常:exchange[ID-WMLI118067-61025-1493883025815-0-2]

终结点上没有可用的使用者:终结点[direct://getRestFromExternalService]. 交易所[ID-WMLI118067-61025-149383025815-0-2]

这是路线等级:

public class MyRoute extends RouteBuilder {

@Override
public void configure() throws Exception {

    // Create the camel context for the REST API routing in Fuse
            CamelContext contextFuseAPI = new DefaultCamelContext();

            // Start the route inside the context to listen to the ActiveMQ
            contextFuseAPI.addRoutes(new RouteBuilder() {

                @Override
                public void configure() {
                    from("direct:getRestFromExternalService")
                        .setHeader(Exchange.HTTP_METHOD, simple("GET"))
                        .to("<external API URI>");
                }
});
}
}

我在没有ProducerTemplate和Object行的情况下测试了main方法,并运行了它。有没有一种方法可以使用另一个类中实现的路由的端点调用requestBody?

我解决了这个问题,问题是在route类和main method类中都创建了上下文

public class FuseApp {

public static void main(String[] args) throws Exception {
    CamelContext contextFuseAPI = new DefaultCamelContext();

    contextFuseAPI.addRoutes(new MyRoute());

    contextFuseAPI.start();

    Thread.sleep(3000);

    ProducerTemplate template = contextFuseAPI.createProducerTemplate();

    Object result = template.requestBody("direct:getRestFromExternalService", null, String.class);


    Exchange exchange = new DefaultExchange(contextFuseAPI);
    String response = ExchangeHelper.convertToType(exchange, String.class, result); 
    System.out.println("Response : "+ response);        

    contextFuseAPI.stop();


}

}