Java Apache Camel Rest DSL DirectConsumerNotAvailableException
我已经使用servlet和SpringXML通过Springboot建立了一个ApacheCalmelRESTAPI。我使用JBoss EAP通过war文件部署API。以下是我参考的网站: 代码成功构建和部署。但是,当我尝试访问端点URL时(http://localhost:8080/camel-rest cxfrs jaxrs/api/customers?country=abc),我得到以下例外情况: 对/camel-rest-cxfrs-jaxrs/api/客户的异常处理请求: org.apache.camel.cameleExecutionException:在 在exchange上执行:exchange[ID localhost- 在 org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1846) 在 org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:713) 在 org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:515) 在 org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:511) 在 org.apache.camel.impl.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:338) 位于org.test.MyServlet.doGet(MyServlet.java:50) 原因:org.apache.camel.component.DirectConsumerNotAvailableException:端点上没有可用的使用者:direct://start. Exchange[ID]本地主机- 我是否错过了什么,或者配置设置错误 下面是我的文件结构和源代码: 文件结构:Java Apache Camel Rest DSL DirectConsumerNotAvailableException,java,spring-boot,rest,servlets,apache-camel,Java,Spring Boot,Rest,Servlets,Apache Camel,我已经使用servlet和SpringXML通过Springboot建立了一个ApacheCalmelRESTAPI。我使用JBoss EAP通过war文件部署API。以下是我参考的网站: 代码成功构建和部署。但是,当我尝试访问端点URL时(http://localhost:8080/camel-rest cxfrs jaxrs/api/customers?country=abc),我得到以下例外情况: 对/camel-rest-cxfrs-jaxrs/api/客户的异常处理请求: org.a
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring https://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="org.test.MyBean" id="helloBean"/>
<camelContext id="camelContext-0476f574-9dab-47b1-89dd-e87e0c6ba735" xmlns="http://camel.apache.org/schema/spring">
<restConfiguration component="servlet" bindingMode="auto"/>
<rest path="/api/customers">
<get>
<route>
<from uri="direct:start"/>
<to uri="direct:start"/>
</route>
</get>
<post>
<route>
<to uri="file:output/customers"/>
</route>
</post>
</rest>
<rest path="/customers">
<delete uri="{id}">
<to uri="bean:helloBean?method=delete(${header.id})"/>
</delete>
</rest>
<rest path="/getapi">
<get uri="/search?country={country}">
<to uri="bean:helloBean?method=byCountry(${header.country})"/>
</get>
</rest>
</camelContext>
</beans>
jboss camel context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring https://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="org.test.MyBean" id="helloBean"/>
<camelContext id="camelContext-0476f574-9dab-47b1-89dd-e87e0c6ba735" xmlns="http://camel.apache.org/schema/spring">
<restConfiguration component="servlet" bindingMode="auto"/>
<rest path="/api/customers">
<get>
<route>
<from uri="direct:start"/>
<to uri="direct:start"/>
</route>
</get>
<post>
<route>
<to uri="file:output/customers"/>
</route>
</post>
</rest>
<rest path="/customers">
<delete uri="{id}">
<to uri="bean:helloBean?method=delete(${header.id})"/>
</delete>
</rest>
<rest path="/getapi">
<get uri="/search?country={country}">
<to uri="bean:helloBean?method=byCountry(${header.country})"/>
</get>
</rest>
</camelContext>
</beans>
MyBean.java
@WebServlet(name = "HttpServiceServlet", urlPatterns = { "/*" }, loadOnStartup = 1)
public class MyServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
@Resource(name = "java:jboss/camel/context/spring-context")
private CamelContext camelContext = new DefaultCamelContext();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
try {
camelContext.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String name = req.getParameter("country");
ServletOutputStream out = res.getOutputStream();
ProducerTemplate producer = camelContext.createProducerTemplate();
String result = producer.requestBody("direct:start", name, String.class);
out.print(result);
//camelContext.stop();
}
}
public class MyBean {
public String sayHello(String message) {
return "Hello " + message;
}
public String delete(String id) {
return "Deleted Customer = " + id;
}
public String byCountry(String countryName) {
System.out.println("Hello World " + countryName);
return "Hello World";
}
}
谢谢。我认为,眼前的问题是,您有一条“到”和“从”的路线端点是
direct:start
。我不确定这应该做什么。在同一个应用程序中,您似乎将camel-cxf内容与camel-rest内容混合在一起。使用servlet作为输入来实现camel-cxf的示例如下:我想离开camel-cxf,使用camel-rest DSL组件来代替。我主要使用下面的教程:但是,我不确定restConfiguration()块将放在哪里;在MyServlet.java类中?