1

我应该先说我正在使用 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 限制类。或者,正在发生完全不同的事情。有什么想法吗?提前致谢!

更新

通过禁用 JMX 后,camelContext.disableJMX();我得到一个新的(非常相似的)异常:

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)
4

1 回答 1

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 注册表。

有效的证明: http ://camelcloud.appspot.com/

于 2013-02-01T11:23:45.163 回答