我应该先说明我使用的是Camel 2.10.3和GAE SDK 1.7.1。
我刚将以下代码打包到我的CamelServlet
中,并将WAR部署到GAE的本地开发者应用服务器实例:
public class CamelServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
RouteBuilder routeBuilder = new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").process(new Processor() {
@Override
public void process(Exchange arg0) throws Exception {
logger.warning("I am inside a Camel route!");
}
}).to("direct:end");
}
};
CamelContext camelContext = new DefaultCamelContext();
try {
camelContext.addRoutes(routeBuilder);
camelContext.start();
Thread.sleep(10000);
camelContext.stop();
}
catch(Exception e) {
logger.warning("Error: " + e.getMessage());
}
}
}
当我转到http://localhost:8888/camel
(这是我映射CamelServlet
的地方)时,我得到了一个堆栈跟踪:
java.lang.NoClassDefFoundError: java.lang.management.ManagementFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.apache.camel.management.DefaultManagementAgent.findOrCreateMBeanServer(DefaultManagementAgent.java:364)
at org.apache.camel.management.DefaultManagementAgent.createMBeanServer(DefaultManagementAgent.java:348)
at org.apache.camel.management.DefaultManagementAgent.doStart(DefaultManagementAgent.java:253)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.management.DefaultManagementStrategy.start(DefaultManagementStrategy.java:209)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.management.ManagementStrategyFactory.create(ManagementStrategyFactory.java:40)
at org.apache.camel.impl.DefaultCamelContext.createManagementStrategy(DefaultCamelContext.java:2490)
at org.apache.camel.impl.DefaultCamelContext.getManagementStrategy(DefaultCamelContext.java:2310)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1499)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1444)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1412)
at com.myapp.server.servlets.CamelServlet.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
受限的?!?!骆驼路线/公共汽车不应该在GAE上运行吗?!? Camel有一个GAE组件(Camel-GAE),我认为是一种验证形式,你实际上可以在GAE上运行Camel。但是现在我担心这只是为了从GAE端点消费,而实际上并不意味着在GAE上运行......
因此要么无法在GAE上运行/启动Camel路由,要么我需要一种特殊的方式来配置路由对象(DefaultCamelContext
等)以避免违反GAE限制类。或者,正在发生一些完全不同的事情。有什么想法吗?提前谢谢!
更新
通过camelContext.disableJMX();
对JMX进行诽谤后,我得到一个新的(非常相似的)异常:
java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.apache.camel.impl.JndiRegistry.createContext(JndiRegistry.java:103)
at org.apache.camel.impl.JndiRegistry.getContext(JndiRegistry.java:92)
at org.apache.camel.impl.JndiRegistry.lookup(JndiRegistry.java:65)
at org.apache.camel.impl.JndiRegistry.lookup(JndiRegistry.java:47)
at org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookup(PropertyPlaceholderDelegateRegistry.java:62)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1557)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1444)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1412)
at com.myapp.server.servlets.CamelServlet.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
答案 0 :(得分:3)
关闭JMX,你应该没问题。
// spring xml
<camel:camelContext id="camelContext">
<!-- JMX is not supported in GAE -->
<camel:jmxAgent id="agent" disabled="true"/>
...
// or in your case, java DSL
CamelContext camelContext = new DefaultCamelContext(new SimpleRegistry());
camelContext.disableJMX();
<强>更新强> 如果您使用的是DefaultCamelContext,则可能希望避免使用默认的JNDI注册表。而是在创建上下文时创建SimpleRegistry(请参阅上面的代码)。 spring config camel context没有默认值,因为它使用spring注册表。