端点:本地开发服务器返回500但App Engine工作正常

时间:2014-06-08 02:32:28

标签: java google-app-engine jetty android-studio google-cloud-endpoints

我已经使用Android Studio设置了一个端点项目。一切都运行得很好,直到我配置本地开发服务器在真正的Android设备而不是模拟器上进行测试。从那以后,本地开发服务器似乎不再公开_ah / api /。

服务器正在运行,我可以从localhost和Android设备访问它。它服务于root的静态网站,它服务于_ah / admin,但它无法提供_ah / api / explorer,而且web服务似乎也无法正常工作。

访问Api Explorer时,服务器出现以下错误:

http://localhost:8080/_ah/api/explorer


HTTP ERROR 500

Problem accessing /_ah/api/explorer. Reason: 
    Error while processing method void in API api VERSION v1


Caused by:
java.lang.IllegalArgumentException: Error while processing method void in API api VERSION v1
    at com.google.api.server.spi.tools.devserver.PathTrie.add(PathTrie.java:61)
    at com.google.api.server.spi.tools.devserver.PathTrie.<init>(PathTrie.java:42)
    at com.google.api.server.spi.tools.devserver.RestApiServlet.loadApiConfigs(RestApiServlet.java:111)
    at com.google.api.server.spi.tools.devserver.ApiServlet.initConfigsIfNecessary(ApiServlet.java:71)
    at com.google.api.server.spi.tools.devserver.RestApiServlet.service(RestApiServlet.java:117)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.tools.appstats.AppstatsFilter.doFilter(AppstatsFilter.java:142)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    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.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
    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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491)
    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 org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.IllegalArgumentException: Path '/post/api/v1/void' is already mapped
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:111)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:126)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:126)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:126)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:126)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.access$100(PathTrie.java:88)
    at com.google.api.server.spi.tools.devserver.PathTrie.add(PathTrie.java:58)
    ... 45 more


Caused by:
java.lang.IllegalArgumentException: Path '/post/api/v1/void' is already mapped
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:111)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:126)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:126)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:126)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.add(PathTrie.java:126)
    at com.google.api.server.spi.tools.devserver.PathTrie$PathTrieNode.access$100(PathTrie.java:88)
    at com.google.api.server.spi.tools.devserver.PathTrie.add(PathTrie.java:58)
    at com.google.api.server.spi.tools.devserver.PathTrie.<init>(PathTrie.java:42)
    at com.google.api.server.spi.tools.devserver.RestApiServlet.loadApiConfigs(RestApiServlet.java:111)
    at com.google.api.server.spi.tools.devserver.ApiServlet.initConfigsIfNecessary(ApiServlet.java:71)
    at com.google.api.server.spi.tools.devserver.RestApiServlet.service(RestApiServlet.java:117)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.tools.appstats.AppstatsFilter.doFilter(AppstatsFilter.java:142)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    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.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
    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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491)
    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 org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)


Powered by Jetty://

“java.lang.IllegalArgumentException:Path'/ post / api / v1 / void'已经映射”对我来说很奇怪。谁能告诉我在哪里看? “/ void”听起来像一种奇怪的方法。

我的gradle.build看起来像这样:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.5'
    }
}

repositories {
    mavenCentral();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.5'
    compile 'com.google.appengine:appengine-endpoints:1.9.5'
    compile 'com.google.appengine:appengine-endpoints-deps:1.9.5'
    compile 'javax.servlet:servlet-api:2.5'
    compile 'com.googlecode.objectify:objectify:5.0.2'
}

appengine {
  downloadSdk = true
  appcfg {
    oauth2 = true
  }
  endpoints {
    getClientLibsOnBuild = true
    getDiscoveryDocsOnBuild = true
  }
}

这是我的web.xml:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">


    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>


    <!-- Endpoints configuration -->
    <servlet>
        <servlet-name>SystemServiceServlet</servlet-name>
        <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
        <init-param>
            <param-name>services</param-name>
            <param-value>
                <!-- Registration endpoints -->
                cc.closeup.backend.endpoints.AccountEndpoint, cc.closeup.backend.endpoints.AccountsEndpoint,
                cc.closeup.backend.endpoints.ProfileEndpoint,
                cc.closeup.backend.endpoints.RegistrationEndpoint,
                cc.closeup.backend.endpoints.SessionEndpoint, cc.closeup.backend.endpoints.SessionsEndpoint,
                cc.closeup.backend.endpoints.UserEndpoint,
                <!-- Graph endpoints -->
                cc.closeup.backend.endpoints.LikeEndpoint, cc.closeup.backend.endpoints.LikesEndpoint,
                cc.closeup.backend.endpoints.MessageEndpoint, cc.closeup.backend.endpoints.MessagesEndpoint,
                cc.closeup.backend.endpoints.RelationEndpoint, cc.closeup.backend.endpoints.RelationsEndpoint,
                <!-- Tile endpoints -->
                cc.closeup.backend.endpoints.TileEndpoint, cc.closeup.backend.endpoints.TilesEndpoint,
                cc.closeup.backend.endpoints.LayerEndpoint, cc.closeup.backend.endpoints.LayersEndpoint
            </param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>SystemServiceServlet</servlet-name>
        <url-pattern>/_ah/spi/*</url-pattern>
    </servlet-mapping>


    <!-- Objectify configuration -->
    <filter>
        <filter-name>ObjectifyFilter</filter-name>
        <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ObjectifyFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <!-- Appstats configuration -->
    <filter>
        <filter-name>appstats</filter-name>
        <filter-class>com.google.appengine.tools.appstats.AppstatsFilter</filter-class>
        <init-param>
            <param-name>calculateRpcCosts</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>appstats</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>appstats</servlet-name>
        <servlet-class>com.google.appengine.tools.appstats.AppstatsServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>appstats</servlet-name>
        <url-pattern>/appstats/*</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>appstats</web-resource-name>
            <url-pattern>/appstats/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>


</web-app>

服务器启动日志如下所示(Windows):

"C:\Program Files\Java\jdk1.8.0_05\bin\java" "-javaagent:C:\Users\Oliver Hausler\.gradle\appengine-sdk\appengine-java-sdk-1.9.1\lib\agent\appengine-agent.jar" "-Xbootclasspath/p:C:\Users\Oliver Hausler\.gradle\appengine-sdk\appengine-java-sdk-1.9.1\lib\override\appengine-dev-jdk-overrides.jar" -Didea.launcher.port=7536 "-Didea.launcher.bin.path=C:\Users\Oliver Hausler\AppData\Local\Android\android-studio\bin" -Dfile.encoding=windows-1252 -classpath "C:\Users\Oliver Hausler\.gradle\appengine-sdk\appengine-java-sdk-1.9.1\lib\appengine-tools-api.jar;C:\Users\Oliver Hausler\AppData\Local\Android\android-studio\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.google.appengine.tools.development.DevAppServerMain --address=0.0.0.0 --port=8080 "C:\Users\Oliver Hausler\AndroidStudioProjects\csnty.android\source\Gangstas\backend\build\exploded-app"


Jun 07, 2014 9:09:46 PM com.google.appengine.tools.development.agent.AppEngineDevAgent premain
SEVERE: Unable to load the App Engine dev agent. Security restrictions will not be completely emulated.
java.lang.RuntimeException: Unexpected exception during cast.
    at com.google.apphosting.utils.clearcast.ClearCast$CasterImpl.cast(ClearCast.java:385)
    at com.google.apphosting.utils.clearcast.ClearCast.staticCast(ClearCast.java:252)
    at com.google.apphosting.utils.clearcast.ClearCast.staticCast(ClearCast.java:263)
    at com.google.appengine.tools.development.agent.AppEngineDevAgent.premain(AppEngineDevAgent.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.IllegalAccessException: Class com.google.apphosting.utils.clearcast.ClearCast$CasterImpl can not access a member of class com.google.appengine.tools.development.agent.$Proxy0 with modifiers "public"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101)
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:295)
    at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:287)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:398)
    at com.google.apphosting.utils.clearcast.ClearCast$CasterImpl.cast(ClearCast.java:383)
    ... 9 more

Jun 07, 2014 9:09:47 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
********************************************************
There is a new version of the SDK available.
-----------
Latest SDK:
Release: 1.9.5
Timestamp: Wed Apr 30 18:55:22 PDT 2014
API versions: [1.0]

-----------
Your SDK:
Release: 1.9.1
Timestamp: Wed Mar 12 16:46:05 PDT 2014
API versions: [1.0]

-----------
Please visit https://developers.google.com/appengine/downloads for the latest SDK.
********************************************************
Jun 07, 2014 9:09:49 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed C:\Users\Oliver Hausler\AndroidStudioProjects\csnty.android\source\Gangstas\backend\build\exploded-app\WEB-INF/appengine-web.xml
Jun 07, 2014 9:09:49 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
INFO: Successfully processed C:\Users\Oliver Hausler\AndroidStudioProjects\csnty.android\source\Gangstas\backend\build\exploded-app\WEB-INF/web.xml
Jun 07, 2014 9:09:49 PM com.google.appengine.tools.development.SystemPropertiesManager setSystemProperties
INFO: Overwriting system property key 'java.util.logging.config.file', value 'C:\Users\Oliver Hausler\.gradle\appengine-sdk\appengine-java-sdk-1.9.1\config\sdk\logging.properties' with value 'WEB-INF/logging.properties' from 'C:\Users\Oliver Hausler\AndroidStudioProjects\csnty.android\source\Gangstas\backend\build\exploded-app\WEB-INF\appengine-web.xml'
Jun 07, 2014 9:09:50 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
Jun 07, 2014 9:09:51 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: jetty-6.1.x
Jun 07, 2014 9:09:53 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Started SelectChannelConnector@0.0.0.0:8080
Jun 07, 2014 9:09:53 PM com.google.appengine.tools.development.AbstractModule startup
INFO: Module instance default is running at http://localhost:8080/
Jun 07, 2014 9:09:53 PM com.google.appengine.tools.development.AbstractModule startup
INFO: The admin console is running at http://localhost:8080/_ah/admin
Jun 07, 2014 9:09:53 PM com.google.appengine.tools.development.DevAppServerImpl doStart
INFO: Dev App Server is now running

2 个答案:

答案 0 :(得分:0)

解决方案非常简单。不像我最初想的那样是服务器错误配置,而是我在端点类中返回void的简单错误,REST似乎不允许这样做。

WRONG:

@ApiMethod(name = "layer.insert")
public void insertLayer(
        final Layer layer
) {
    //... 
}

GOOD:

@ApiMethod(name = "layer.insert")
public Layer insertLayer(
        final Layer layer
) {
    //... 
    return layer;
}

所以,即使你不需要回报,也要给谷歌一些钱并且总是返回结果; - (

答案 1 :(得分:0)

如果您不打算返回任何数据,请尝试将httpMethod设置为POST

像这样:

@ApiMethod(name = "layer.insert", httpMethod = ApiMethod.HttpMethod.POST)