【问题标题】:Is this Google Endpoints error on the server or client?这是服务器或客户端上的 Google Endpoints 错误吗?
【发布时间】:2014-06-20 04:25:57
【问题描述】:

我一直在通过https://developers.google.com/appengine/docs/java/endpoints/ 的教程学习 Google Endpoints。我将 Endpoint 成功部署到 Google App Engine,并设法构建了一个调用 Endpoint 的简单 iPhone 应用程序。但是,我的 iPhone 应用程序在尝试调用 Endpoint 时出现以下错误:

错误信息

错误 NSError * 域:@"com.google.GTLJSONRPCErrorDomain" - 代码:-32099 0x00000001094518a0

_userInfo __NSDictionaryI * 3 个键/值对 0x00000001094452b0

[0] (null) @"error" : @"java.lang.IndexOutOfBoundsException: Index: 0, Size: 0"
[1] (null) @"NSLocalizedFailureReason" : @"(java.lang.IndexOutOfBoundsException: Index: 0, Size: 0)"
[2] (null) @"GTLStructuredError" : (没有总结)

iPhone API 调用程序(在 Xcode 调试器中运行的 Objective-C 中)

- (IBAction)myButton:(id)sender {
    NSInteger myId;
    if (self.mySwitch.isOn) {
        myId = 0;
    }
    else {
        myId = 1;
    }
    GTLQueryHelloworld *query = [GTLQueryHelloworld queryForGreetingsGetGreetingWithIdentifier:myId];
    [self.helloWorldService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
        if (!error) {
            [self.myLabel setText:object];
        }
        else {
            [self.myLabel setText:[error description]];  // This line gets called 
        }
    }];
}

我在Youtube video upload fails after 100 % progress for some users with Backend Error code:-32099 中发现了相同的错误消息,但它与调用 YouTube 有关,并且最终作为一个已修复的错误而关闭。所以我认为这没有关系。

我相信错误出在客户端,因为我在服务器 (Java) 上放置了一些日志记录,但它似乎没有被调用:

public class Greetings {
    private static final Logger log = Logger.getLogger(Greetings.class.getName());

    public static ArrayList<HelloGreeting> greetings = new ArrayList<HelloGreeting>();

    static {
            log.setLevel(Level.INFO);
            greetings.add(new HelloGreeting("hello world!"));
            greetings.add(new HelloGreeting("goodbye world!"));
    }

        public HelloGreeting getGreeting(@Named("id") Integer id) {
            log.info("HelloGreeting called with getGreeting");
            log.info("getGreeting id " + id);
            return greetings.get(id);
    }

我在 Google 服务器日志中没有看到“使用 getGreeting 调用 HelloGreeting”,我看到的只是指示我的 Endpoint 项目已成功部署的日志消息:

21:56:45.639 端点:https://1-war-dot-firstendpointproject.appspot.com/_ah/api/helloworld@v1 已保存

我还确认我可以从已部署的 API 资源管理器中为我的项目成功测试 helloworld.greetings.getGreeting API:

https://1-war-dot-firstendpointproject.appspot.com/_ah/api/explorer

当我从 Explorer 调用 API 时,它会生成一条日志消息:

24.130.150.54 - - [19/Jun/2014:21:17:45 -0700] "POST /_ah/spi/com.google.appengine.samples.helloendpoints.Greetings.getGreeting HTTP/1.1" 200 93 " https://1-war-dot-firstendpointproject.appspot.com/ah/api/static/proxy.html?jsh=m%3B%2F%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.htta44JhPmg.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Fz%3Dzcms%2Frs%3DAItRSTPk1CJ1YqUCyb-H-zhkQTjKPZwvbQ" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) 版本/7.0.3 Safari/537.75.14" "1-war-dot-firstendpointproject.appspot。 com" ms=17 cpu_ms=87 cpm_usd=0.000010 instance=00c61b117ce13f56d6eb483511c2c1bcd24241 app_engine_release=1.9.6

它不会生成“使用 getGreeting 调用的 HelloGreeting”,但我怀疑这是因为我没有配置记录器。无论如何,当我的客户调用端点时,我根本没有收到任何日志消息。由于 API 资源管理器调用至少生成 1 条日志消息,我怀疑问题出在客户端上。

问题:

1] 我看到的错误是在客户端还是服务器端生成的?

2] 你知道这个错误指的是什么数组吗?

3] 有哪些技术可用于调试此类连接问题?

感谢您对 StackOverflowers 的帮助!

迈克尔

【问题讨论】:

  • +1 因为我遇到了同样的问题(Error Domain=com.google.GTLJSONRPCErrorDomain Code=-32099,当我从 Objective C 调用我的 Google Cloud Endpoints 服务时)并且希望看到答案......
  • 我已经通过 Google Cloud 支持打开了支持票证。到目前为止,他们通过指出问题必须在端点的 Java 代码中提供帮助,因为详细的错误是 Java 异常 (java.lang.IndexOutOfBoundsException)。感谢您发布 Drux,我会让他们知道我不是唯一一个。

标签: java xcode google-app-engine google-cloud-endpoints google-cloud-platform


【解决方案1】:

我认为发生了以下情况:服务器遇到了意外情况(特别是:它抛出了一个无人处理的IndexOutOfBoundsException),因此它无法返回生成的客户端存根在其 HTTP 响应中期望的那种 JSON (特别是:它返回 HTTP 状态 500 而不是 2xx)。客户端存根将此报告为NSError,域为com.google.GTLJSONRPCErrorDomain,代码为32099。JSON-RPC 2.0 规范将此错误代码定义为“为实现定义的服务器错误保留”。

似乎处理此问题的最佳方法是在服务器端或客户端添加适当的异常处理,具体取决于究竟是什么导致了服务器上的意外情况。 IndexOutOfBoundsException 最有可能由服务器处理,因为它可能源于应用程序级错误。

所以回答逐字的问题:(原始)错误在服务器上。顺便说一句,与 OP 不同,我确实在 Google Developers Console 中看到了相关的 JUL 日志输出。

【讨论】:

  • 恭喜@Drux 走到这一步。据我所知,我的日志不仅没有在 Google Developers Console 中输出,而且代码甚至似乎都没有运行。我简化了它,所以它所做的只是new HelloGreeting("holamundo")。这也返回java.lang.IndexOutOfBoundsException。所以我想知道它是否在调用我的 getGreeting 方法之前调用的端点代码上抛出异常。
  • @MichaelOsofsky 您是否尝试过添加try/catch 并在您的servlet 的@ApiMethod 代码中的调试器中设置断点以进行仔细检查?会不会是您更新了@ApiMethods 而没有再次运行ServiceGenerator 等?顺便说一句,我的是JsonMappingException,不是IndexOutOfBoundsException,所以情况略有不同。
  • 感谢@Drux,我现在在我的端点上添加了一个 try/catch(Exception e) 块。不会调用 catch 块。该错误似乎发生在我的 Endpoint 应用程序代码实际到达之前。
  • 我有更多证据表明该错误是由服务器生成的。我关闭了无线,然后在 Xcode 调试器中运行 iPhone 应用程序。当我单击启动端点调用的按钮时,我得到了一个不同的错误:[0] (null) @"NSUnderlyingError" : (no summary) [1] (null) @"NSErrorFailingURLStringKey" : @"helloendpoints.appspot.com/_ah/api/rpc?prettyPrint=false" [2 ] (null) @"NSErrorFailingURLKey" : @"helloendpoints.appspot.com/_ah/api/rpc?prettyPrint=false" [3] (null) @"NSLocalizedDescription" : @"Internet 连接似乎处于脱机状态。"
  • @MichaelOsofsky 是的,它必须是服务器。我猜有些东西会阻止它解析或生成 API 方法签名所描述的 JSON。这就是为什么我认为客户端和服务器使用的描述可能不同步。顺便说一句,通过修复我的应用程序/服务代码中的根本原因,我已经能够摆脱错误 32099。
【解决方案2】:

我查看了您的端点,并在资源管理器中使用 curl 成功调用了它。我很确定问题出在客户端,而服务器不理解请求。

如果您确定正确调用客户端,我会尝试重新生成它。自从您上次生成以来,也许有一个错误修复。

【讨论】:

  • 大侦探@LouFranco,重新生成iOS客户端代码解决了问题!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多