gpt4 book ai didi

ios - RestKit/RestEASY——排队请求操作时出现ClientAbortException

转载 作者:行者123 更新时间:2023-11-29 13:21:58 25 4
gpt4 key购买 nike

我正在开发一个 iOS 应用程序,它将使用 RestKit 0.20 对在 JBoss AS 7.1.1 上运行的服务进行基于 REST 的调用,并使用 restEASY 作为其基于 REST 的 Web 服务框架。

客户端应用程序将调用的 REST 服务用于根据对象的唯一标识符检索对象。由于这些对象可大可小(大小 > 1MB)并且数量众多(一次 20?50?100 或更多)我不想进行一次大调用以一次检索所有对象。相反,我计划使用 RestKit 的排队操作支持来基于对象标识符为每个对象创建 GET 请求,并异步执行调用。 GET 完成后,将通过使用 Objective-C block 来处理每个对象,以避免任何不必要的阻塞。

我的 RestKit 客户端代码如下所示......

    NSArray *identifiers = ...
RKObjectManager *objectManager = [RKObjectManager sharedManager];

RKResponseDescriptor *getObjResp = [RKResponseDescriptor responseDescriptorWithMapping:[MyObject mapping] pathPattern:[WebServiceHelper pathForServiceOperation:@"/objects/:uniqueIdentifier"] keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
for (int i=0; i < identifiers.count; i++) {
NSString *identifier = [identifiers objectAtIndex:i];
NSURL *serviceURL = [WebServiceHelper urlForServiceOperation:[NSString stringWithFormat:@"/objects/%@", identifier]];
NSURLRequest *request = [NSURLRequest requestWithURL:serviceURL];
RKObjectRequestOperation *requestOp = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[getObjResp]];

[requestOp setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
MyObject *obj = [mappingResult firstObject];
if (self.delegate != nil) {
[self.delegate didLoadObjectWithIdentifier:identifier myObj:obj];
}
} failure:^(RKObjectRequestOperation *operation, NSError *error){
if (self.delegate != nil) {
[self.delegate didFinishWithError:error];
}
}];

[objectManager enqueueObjectRequestOperation:requestOp];
}

从那里,检索对象时调用的委托(delegate)方法如下所示:

-(void)didLoadObjectWithIdentifier:(NSString *)identifier myObj:(MyObject *)myObj {
if(secureMessage != nil) {
NSLog(@"Message %@ retrieved successfully : %@:%@", identifier, myObj);
} else {
NSLog(@"NO OBJ");
}
}

调用似乎按预期运行,因为我能够打印出有关检索对象的信息。但是,我在服务端看到了一些奇怪/意外的行为。

首先,我看到 restEASY 抛出了一些异常:

13:22:02,903 WARN  [org.jboss.resteasy.core.SynchronousDispatcher] (http--0.0.0.0-8080-10) Failed executing GET /objects/BBFE39EA126F610C: org.jboss.resteasy.spi.WriterException: ClientAbortException:  java.net.SocketException: Broken pipe
at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:262) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:585) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:506) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:145) [jboss-seam-resteasy.jar:2.3.0.Final]
at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:120) [jboss-seam-resteasy.jar:2.3.0.Final]
...

看起来好像 RestKit 正在以某种方式关闭套接字(或者一些其他错误阻止从服务器读取对象)。我无法在文档中找到任何可以解释这里发生的事情的内容。

不过,其次,当请求失败并出现此错误时,我还看到另一个调用了完全相同的对象。为什么 GET 被调用不止一次? RestKit 是否重做失败的 GET 请求?

我最关心的是为什么异常会在 restEASY 中发生,因为这会使诊断真正失败的调用变得困难。有没有人见过这种行为?关于如何纠正这些问题的任何提示?感谢您提供的任何帮助!!

最佳答案

这些异常是由客户端断开连接导致的,即一些用户可能在等待过程完成时退出应用程序或出现网络故障(在客户端)。因此,破管。

关于ios - RestKit/RestEASY——排队请求操作时出现ClientAbortException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14162905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com