Google API Explorer不允许访问Cloud Endpoints V2方法

时间:2017-02-22 18:57:28

标签: google-app-engine google-cloud-endpoints

我正在尝试将Java AppEngine从Cloud Endpoints迁移到Cloud Endpoints Framework。即v1到v2。

迁移很顺利,端点都可以在新实例上访问。 并且发现显示了所有方法https://myapp.appspot.com/_ah/api/discovery/v1/apis

但是当我使用https://apis-explorer.appspot.com/apis-explorer作为我的appengine域时,虽然我仍然可以看到API方法,但当我深入研究它们时,我再也无法提供参数并执行它们。

查看AppEngine日志我看到以下ClassCastException

Uncaught exception from servlet
javax.servlet.UnavailableException: java.lang.ClassCastException: com.google.api.server.spi.config.AnnotationBoolean cannot be cast to com.google.api.server.spi.config.AnnotationBoolean
    at org.mortbay.jetty.servlet.ServletHolder.makeUnavailable(ServletHolder.java:415)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:458)
    at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:58)
    at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:37)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:257)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:145)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:559)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:519)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:489)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:453)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:460)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:293)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:319)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:311)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:457)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:238)
    at java.lang.Thread.run(Thread.java:745)

这似乎与尝试在API Explorer中深入研究方法相匹配。云端点v1不会发生这些错误。

ClassCast暗示AnnotationBoolen已加载到2个不同的类加载器中。我自己不玩类加载器,所以我认为这对于Endpoints v2来说是新的。我应该做些什么来避免ClassCast?

API Explorer是否不完全支持Cloud Endpoints Framework?

我需要采取一些额外步骤来通过API Explorer for Cloud Endpoints Framework启用方法执行吗?

2 个答案:

答案 0 :(得分:3)

根据Cloud EndPoints框架迁移指南,不再支持这些maven目标。

                      <goal>endpoints_get_discovery_doc</goal>
                      <goal>endpoints_get_client_lib</goal>

请参阅https://cloud.google.com/appengine/docs/standard/java/endpoints/migrating

看起来像你需要

  1. 将Cloud Endpoints API管理添加到您的应用。 请参阅https://cloud.google.com/endpoints/docs/frameworks/java/adding-api-management
  2. 生成API配置文件并在部署应用程序之前部署它。 请参阅https://cloud.google.com/endpoints/docs/frameworks/java/test-deploy

  3. 使用...

  4. 生成客户端库

    请参阅https://cloud.google.com/endpoints/docs/frameworks/java/quickstart-frameworks-java

    步骤1意味着在web.xml中添加以下内容:

    <!--
        EndPoints management API. See https://cloud.google.com/endpoints/docs/frameworks/java/adding-api-management
    -->
    <filter>
        <filter-name>endpoints-api-configuration</filter-name>
        <filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
    </filter>
    
    <!--
        EndPoints management API. See https://cloud.google.com/endpoints/docs/frameworks/java/adding-api-management
    -->
    <filter>
        <filter-name>endpoints-api-controller</filter-name>
        <filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
        <init-param>
            <param-name>endpoints.projectId</param-name>
            <param-value>your-appengine-projectid</param-value>
        </init-param>
        <init-param>
            <param-name>endpoints.serviceName</param-name>
            <param-value>your-appengine-project-url.appspot.com</param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>endpoints-api-configuration</filter-name>
        <servlet-name>EndpointsServlet</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>endpoints-api-controller</filter-name>
        <servlet-name>EndpointsServlet</servlet-name>
    </filter-mapping>
    

答案 1 :(得分:0)

您遇到的ClassCastException是由于加载了旧的SystemServiceServlet而不是新的EndpointsServlet。配置web.xml以替换

<servlet>
    <servlet-name>SystemServiceServlet</servlet-name>
    <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
    ...
</servlet>
<servlet-mapping>
    <servlet-name>SystemServiceServlet</servlet-name>
    <url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>EndpointsServlet</servlet-name>
    <servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
    ...
</servlet>
<servlet-mapping>
    <servlet-name>EndpointsServlet</servlet-name>
    <url-pattern>/_ah/api/*</url-pattern>
</servlet-mapping>