我有一个正在寻找多部分数据的Web服务端点
@POST
@Path("/import/file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response importData(MultipartFormDataInput multipartData) {
if(multipartData == null) {
return Response.status(400).entity("Invalid Data").build();
}
InputStream is = multipartData.getFormDataPart("file", Inputstream.class, null);
try {
someService.someMethod(is);
} catch(Exception ex) {
return Response.serverError().build();
}
return Response.ok().build();
}
当我调用此Web服务(使用Postman)时,我不断收到此错误
15:29:52.664 WARN - Failed executing POST /import/file
org.jboss.resteasy.spi.ReaderException: java.lang.RuntimeException: java.io.IOException: No such file or directory
at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:183) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:217) [resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:224) [resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:62) [resteasy-jaxrs-3.0.10.Final.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.35]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.35]
at org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter$MarmottaFilterChain.doFilter(MarmottaResourceFilter.java:185) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.filters.ModuleResourceFilter.doFilter(ModuleResourceFilter.java:157) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.filters.ModuleResourceFilter$Proxy$_$$_WeldClientProxy.doFilter(Unknown Source) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter$MarmottaFilterChain.doFilter(MarmottaResourceFilter.java:180) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.filters.MarmottaServerNameFilter.doFilter(MarmottaServerNameFilter.java:104) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter$MarmottaFilterChain.doFilter(MarmottaResourceFilter.java:180) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.filters.TemplatingFilter.doFilter(TemplatingFilter.java:176) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.filters.TemplatingFilter$Proxy$_$$_WeldClientProxy.doFilter(Unknown Source) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter$MarmottaFilterChain.doFilter(MarmottaResourceFilter.java:180) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter$MarmottaFilterChain.doFilter(MarmottaResourceFilter.java:182) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.security.filters.MarmottaAccessControlFilter.doFilter(MarmottaAccessControlFilter.java:151) [marmotta-security-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.security.filters.MarmottaAccessControlFilter$Proxy$_$$_WeldClientProxy.doFilter(Unknown Source) [marmotta-security-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter$MarmottaFilterChain.doFilter(MarmottaResourceFilter.java:180) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.user.filters.MarmottaAuthenticationFilter.doFilter(MarmottaAuthenticationFilter.java:191) [marmotta-user-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.user.filters.MarmottaAuthenticationFilter$Proxy$_$$_WeldClientProxy.doFilter(Unknown Source) [marmotta-user-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter$MarmottaFilterChain.doFilter(MarmottaResourceFilter.java:180) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter.doFilter(MarmottaResourceFilter.java:133) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.35]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.35]
at org.apache.marmotta.platform.core.servlet.MarmottaPreStartupFilter.doFilter(MarmottaPreStartupFilter.java:106) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.35]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.35]
at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:208) [cors-filter-2.2.1.jar:2.2.1]
at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:271) [cors-filter-2.2.1.jar:2.2.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.35]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.35]
at org.apache.marmotta.platform.core.servlet.MarmottaOptionsFilter.doFilter(MarmottaOptionsFilter.java:81) [marmotta-core-3.3.0.jar:3.3.0]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.35]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.35]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [catalina.jar:8.0.35]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.35]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:8.0.35]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [catalina.jar:8.0.35]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.35]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) [catalina.jar:8.0.35]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.35]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) [catalina.jar:8.0.35]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) [tomcat-coyote.jar:8.0.35]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) [tomcat-coyote.jar:8.0.35]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) [tomcat-coyote.jar:8.0.35]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) [tomcat-coyote.jar:8.0.35]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.35]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]
Caused by: java.lang.RuntimeException: java.io.IOException: No such file or directory
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$BinaryOnlyMessageBuilder.body(MultipartInputImpl.java:140) ~[resteasy-multipart-provider-3.0.10.Final.jar:na]
at org.apache.james.mime4j.parser.MimeStreamParser.parse(MimeStreamParser.java:101) ~[apache-mime4j-0.6.jar:0.6]
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$BinaryMessage.<init>(MultipartInputImpl.java:153) ~[resteasy-multipart-provider-3.0.10.Final.jar:na]
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$BinaryMessage.<init>(MultipartInputImpl.java:146) ~[resteasy-multipart-provider-3.0.10.Final.jar:na]
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.parse(MultipartInputImpl.java:197) ~[resteasy-multipart-provider-3.0.10.Final.jar:na]
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataReader.readFrom(MultipartFormDataReader.java:52) ~[resteasy-multipart-provider-3.0.10.Final.jar:na]
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataReader.readFrom(MultipartFormDataReader.java:20) ~[resteasy-multipart-provider-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:59) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.readFrom(ServerReaderInterceptorContext.java:62) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:51) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:150) ~[resteasy-jaxrs-3.0.10.Final.jar:na]
... 56 common frames omitted
Caused by: java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method) ~[na:1.8.0_77]
at java.io.File.createTempFile(File.java:2024) ~[na:1.8.0_77]
at org.apache.james.mime4j.storage.TempFileStorageProvider.createStorageOutputStream(TempFileStorageProvider.java:104) ~[apache-mime4j-0.6.jar:0.6]
at org.apache.james.mime4j.storage.ThresholdStorageProvider$ThresholdStorageOutputStream.write0(ThresholdStorageProvider.java:113) ~[apache-mime4j-0.6.jar:0.6]
at org.apache.james.mime4j.storage.StorageOutputStream.write(StorageOutputStream.java:119) ~[apache-mime4j-0.6.jar:0.6]
at org.apache.james.mime4j.codec.CodecUtil.copy(CodecUtil.java:43) ~[apache-mime4j-0.6.jar:0.6]
at org.apache.james.mime4j.storage.AbstractStorageProvider.store(AbstractStorageProvider.java:57) ~[apache-mime4j-0.6.jar:0.6]
at org.apache.james.mime4j.message.BodyFactory.binaryBody(BodyFactory.java:92) ~[apache-mime4j-0.6.jar:0.6]
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$BinaryOnlyMessageBuilder.body(MultipartInputImpl.java:132) ~[resteasy-multipart-provider-3.0.10.Final.jar:na]
... 68 common frames omitted
从我看到的情况来看,请求正在点击过滤器并清除它们但由于某种原因,它不会进入importData
方法。
有人能告诉我为什么会收到此错误?在我看来,服务器无法在某处创建一些临时文件,但我无法理解这个临时文件需要在哪里以及为什么?
答案 0 :(得分:0)
我能够找出问题所在。系统属性java.io.tmpdir
的值在系统中不存在。一旦我手动创建了位置,我就没有收到错误。
File.createTempFile(String prefix, String suffix, File dir)
方法尝试在指定的目录中创建临时文件。如果是null
,则它使用系统属性java.io.tmpdir
提供的路径。该属性应该是系统中的有效目录。如果未设置此属性或系统中不存在此属性,则会出现我收到的异常。