我正在开发一项REST服务,允许IOS用户上传照片(通常为100-300KB)。我使用Jersey,jersey-media-multipart 2.11,部署在Tomcat7上,AFNetworking 1.3.4,云托管 - digitalocean
//==================
// server.xml (tomcat7), using APR native library
//==================
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
connectionUploadTimeout="40000"
disableUploadTimeout="false"
URIEncoding="UTF-8"
redirectPort="8443" />
//==================
// SERVER
//==================
public class PostForm {
@FormDataParam("photo_data")
private InputStream photoStream;
@FormDataParam("audio_data")
private InputStream audioStream;
@FormDataParam("video_data")
private InputStream videoStream;
// Some other form data
}
public class PostResource {
@POST
@Consumes("multipart/form-data")
@Produces("application/json")
public Response createPost(@BeanParam PostForm form) {
// ...
}
}
//==================
// CLIENT
//==================
AFHTTPClient *httpClient = [[AFHttpClient alloc] init];
NSMutableURLRequest *request =
[httpClient multipartFormRequestWithMethod:@"POST"
path:some_path
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
if (sending_photo) {
[formData appendPartWithFileData:photoData
name:@"photo_data"
fileName:@"photo_data"
mimeType:[photoData imageContentType]];
}
// else sending audio or video...
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[httpClient enqueueHTTPRequestOperation:operation];
照片被压缩,大多数在100-200KB之下。问题是,泽西服务器经常抛出异常
org.glassfish.hk2.api.MultiException: A MultiException has 18 exceptions. They are:
1. org.glassfish.jersey.server.internal.process.MappableException: java.net.SocketTimeoutException
2. java.lang.IllegalStateException: Entity input stream has already been closed.
3. java.lang.IllegalStateException: Entity input stream has already been closed.
4. java.lang.IllegalStateException: Entity input stream has already been closed.
5. java.lang.IllegalStateException: Entity input stream has already been closed.
6. java.lang.IllegalStateException: Entity input stream has already been closed.
7. java.lang.IllegalStateException: Entity input stream has already been closed.
8. java.lang.IllegalStateException: Entity input stream has already been closed.
9. java.lang.IllegalStateException: Entity input stream has already been closed.
10. java.lang.IllegalStateException: Entity input stream has already been closed.
11. java.lang.IllegalStateException: Entity input stream has already been closed.
12. java.lang.IllegalStateException: Entity input stream has already been closed.
13. java.lang.IllegalStateException: Entity input stream has already been closed.
14. java.lang.IllegalStateException: Entity input stream has already been closed.
15. java.lang.IllegalStateException: Entity input stream has already been closed.
16. java.lang.IllegalStateException: Entity input stream has already been closed.
17. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of gd.api.v1.post.PostForm errors were found
18. java.lang.IllegalStateException: Unable to perform operation: resolve on gd.api.v1.post.PostForm
at org.jvnet.hk2.internal.Collector.throwIfErrors(Collector.java:88) ~[hk2-locator-2.3.0-b05.jar:na]
at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:252) ~[hk2-locator-2.3.0-b05.jar:na]
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:360) ~[hk2-locator-2.3.0-b05.jar:na]
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456) ~[hk2-locator-2.3.0-b05.jar:na]
at org.glassfish.jersey.server.internal.inject.BeanParamValueFactoryProvider$BeanParamValueFactory.provide(BeanParamValueFactoryProvider.java:103) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:81) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:121) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:387) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:331) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:103) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [jersey-common-2.11.jar:na]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [jersey-common-2.11.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [jersey-common-2.11.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [jersey-common-2.11.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [jersey-common-2.11.jar:na]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297) [jersey-common-2.11.jar:na]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254) [jersey-server-2.11.jar:na]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028) [jersey-server-2.11.jar:na]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372) [jersey-container-servlet-core-2.11.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381) [jersey-container-servlet-core-2.11.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344) [jersey-container-servlet-core-2.11.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221) [jersey-container-servlet-core-2.11.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [tomcat-catalina-7.0.52.jar:7.0.52]
at gd.support.jersey.ThreadNameServletFilter.doFilter(ThreadNameServletFilter.java:52) [ThreadNameServletFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) [tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) [tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2378) [tomcat-coyote-7.0.52.jar:7.0.52]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_75]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_75]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_75]
Caused by: org.glassfish.jersey.server.internal.process.MappableException: java.net.SocketTimeoutException
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:77) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:154) ~[jersey-common-2.11.jar:na]
at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1124) ~[jersey-common-2.11.jar:na]
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:851) ~[jersey-common-2.11.jar:na]
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:783) ~[jersey-common-2.11.jar:na]
at org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:233) ~[jersey-server-2.11.jar:na]
at org.glassfish.jersey.media.multipart.internal.FormDataParamValueFactoryProvider.getEntity(FormDataParamValueFactoryProvider.java:375) ~[jersey-media-multipart-2.11.jar:na]
at org.glassfish.jersey.media.multipart.internal.FormDataParamValueFactoryProvider.access$000(FormDataParamValueFactoryProvider.java:86) ~[jersey-media-multipart-2.11.jar:na]
at org.glassfish.jersey.media.multipart.internal.FormDataParamValueFactoryProvider$FormDataParamValueFactory.provide(FormDataParamValueFactoryProvider.java:202) ~[jersey-media-multipart-2.11.jar:na]
at org.glassfish.jersey.server.internal.inject.ParamInjectionResolver.resolve(ParamInjectionResolver.java:134) ~[jersey-server-2.11.jar:na]
at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:214) ~[hk2-locator-2.3.0-b05.jar:na]
at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:237) ~[hk2-locator-2.3.0-b05.jar:na]
... 42 common frames omitted
Caused by: java.net.SocketTimeoutException: null
at org.apache.coyote.http11.InternalAprInputBuffer.fill(InternalAprInputBuffer.java:607) ~[tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.coyote.http11.InternalAprInputBuffer$SocketInputBuffer.doRead(InternalAprInputBuffer.java:642) ~[tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:124) ~[tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.coyote.http11.InternalAprInputBuffer.doRead(InternalAprInputBuffer.java:534) ~[tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.coyote.Request.doRead(Request.java:422) ~[tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:290) ~[tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:449) ~[tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:315) ~[tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200) ~[tomcat-catalina-7.0.52.jar:7.0.52]
at org.glassfish.jersey.message.internal.EntityInputStream.read(EntityInputStream.java:101) ~[jersey-common-2.11.jar:na]
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream.read(ReaderInterceptorExecutor.java:300) ~[jersey-common-2.11.jar:na]
at org.jvnet.mimepull.MIMEParser.fillBuf(MIMEParser.java:440) ~[mimepull-1.9.3.jar:1.9.3]
at org.jvnet.mimepull.MIMEParser.skipPreamble(MIMEParser.java:307) ~[mimepull-1.9.3.jar:1.9.3]
at org.jvnet.mimepull.MIMEParser.access$300(MIMEParser.java:68) ~[mimepull-1.9.3.jar:1.9.3]
at org.jvnet.mimepull.MIMEParser$MIMEEventIterator.next(MIMEParser.java:149) ~[mimepull-1.9.3.jar:1.9.3]
at org.jvnet.mimepull.MIMEParser$MIMEEventIterator.next(MIMEParser.java:132) ~[mimepull-1.9.3.jar:1.9.3]
at org.jvnet.mimepull.MIMEMessage.makeProgress(MIMEMessage.java:198) ~[mimepull-1.9.3.jar:1.9.3]
at org.jvnet.mimepull.MIMEMessage.parseAll(MIMEMessage.java:181) ~[mimepull-1.9.3.jar:1.9.3]
at org.jvnet.mimepull.MIMEMessage.getAttachments(MIMEMessage.java:106) ~[mimepull-1.9.3.jar:1.9.3]
at org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide.readMultiPart(MultiPartReaderClientSide.java:225) ~[jersey-media-multipart-2.11.jar:na]
at org.glassfish.jersey.media.multipart.internal.MultiPartReaderServerSide.readMultiPart(MultiPartReaderServerSide.java:90) ~[jersey-media-multipart-2.11.jar:na]
at org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:179) ~[jersey-media-multipart-2.11.jar:na]
at org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:91) ~[jersey-media-multipart-2.11.jar:na]
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:258) ~[jersey-common-2.11.jar:na]
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:234) ~[jersey-common-2.11.jar:na]
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:154) ~[jersey-common-2.11.jar:na]
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:73) ~[jersey-server-2.11.jar:na]
... 53 common frames omitted
我不确定这是由我的ios用户的网络连接不良造成的。但压缩后文件太小,异常频繁发生,我怀疑可能还有其他罪魁祸首。谁能让我对它有所了解呢?