1

我在 Google App Engine 上部署了 REST 服务,每次尝试查询服务时都会收到以下错误:

com.sun.jersey.core.spi.component.ProviderFactory __getComponentProvider: The provider class, class com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider, could not be instantiated. Processing will continue but the class will not be utilized
java.lang.SecurityException: Unable to get members for class com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
    at com.google.appengine.runtime.Request.process-7d6711107bb7eaaa(Request.java)
    at java.lang.Class.getDeclaredMethods(Class.java:253)
    at com.sun.jersey.core.reflection.MethodList.getAllDeclaredMethods(MethodList.java:70)
    at com.sun.jersey.core.reflection.MethodList.<init>(MethodList.java:64)
    at com.sun.jersey.core.spi.component.ComponentConstructor.getPostConstructMethods(ComponentConstructor.java:131)
    at com.sun.jersey.core.spi.component.ComponentConstructor.<init>(ComponentConstructor.java:123)
    at com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java:165)
    at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:137)
    at com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:256)
    at com.sun.jersey.core.spi.component.ProviderServices.getServices(ProviderServices.java:160)
    at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:176)
    at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1310)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:168)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:774)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:770)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:703)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    ... 41 more
Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2444)
    ... 41 more
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
    at com.google.appengine.runtime.Request.process-7d6711107bb7eaaa(Request.java)
    ... 41 more

此服务不使用或发送任何邮件消息。它只做一件事就是从一些 POJO 写入 JSON 响应。它当然可以在本地工作(在本地 GAE 和本地 Tomcat 上)。

4

2 回答 2

1

这可能是版本的兼容性问题。据此,与 Google App Engine 兼容Jersey 版本是 1.5 和 1.1.5。

我有类似的问题,我不喜欢这个版本的兼容性问题,所以我选择了:

  • 要从 GAE 提供 REST Web 服务,请使用Google Cloud Endpoints,这仍然是一项实验性技术,但据我尝试,它运行良好。此外,它还与 GAE 和Google Plugin for Eclipse很好地集成在一起。

  • 为了使用 GAE 的 REST 服务,我选择仅使用 Java 内置 HTTP 客户端库,如此所述。我不知道这是否是最好的方法,但它非常简单,您可以避免 GAE 和外部 API(如 Jersey)之间可能出现的兼容性问题。

于 2013-03-13T19:06:52.320 回答
0

我在 GitHub 上创建了一个 GAE REST 框架应用程序。它位于https://github.com/deege/gae-rest-skeleton

该应用程序只定义了两个 REST 调用,但它会为您提供一个起点。它使用 GAE 1.9.4 和 Jersey 1.17.1。

您可以从https://github.com/deege/gae-rest-skeleton.git分叉代码

于 2014-05-24T20:09:44.623 回答