Resteasy 和文件上传:没有出现内容处置错误
我有一个可以上传文件的休息资源。
@Path("/rest/input")
public class InputResourceBean {
@POST
@Path("{directory: .*}")
@Consumes("multipart/form-data")
public void post(final String directory, final MultipartFormDataInput input) {
}
部分中找不到 Content-Disposition 标头
12:55:19,739 WARN [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing POST /rest/input/myDir: org.jboss.resteasy.spi.ReaderException: java.lang.RuntimeException: Could find no Content-Disposition header within part
at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:123) [:6.0.0.Final]
at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:93) [:6.0.0.Final]
at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:146) [:6.0.0.Final]
at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:114) [:6.0.0.Final]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) [:6.0.0.Final]
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:252) [:6.0.0.Final]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:217) [:6.0.0.Final]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:206) [:6.0.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:503) [:6.0.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:480) [:6.0.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:139) [:6.0.0.Final]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:211) [:6.0.0.Final]
at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:59) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191) [:6.0.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [:6.0.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]
Caused by: java.lang.RuntimeException: Could find no Content-Disposition header within part
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInputImpl.extractPart(MultipartFormDataInputImpl.java:69) [:6.0.0.Final]
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.extractParts(MultipartInputImpl.java:108) [:6.0.0.Final]
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.parse(MultipartInputImpl.java:77) [:6.0.0.Final]
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataReader.readFrom(MultipartFormDataReader.java:52) [:6.0.0.Final]
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataReader.readFrom(MultipartFormDataReader.java:20) [:6.0.0.Final]
at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105) [:6.0.0.Final]
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:46) [:6.0.0.Final]
at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108) [:6.0.0.Final]
at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:111) [:6.0.0.Final]
... 35 more
我使用 SOAPUI、curl 和 HTML 表单来测试此代码,对于所有这些代码,我都得到相同的错误:在我使用 JBoss AS 6 和 Resteasy 的 。我不明白为什么会出现此错误或如何解决它。
I have a rest resource to which files can be uploaded.
@Path("/rest/input")
public class InputResourceBean {
@POST
@Path("{directory: .*}")
@Consumes("multipart/form-data")
public void post(final String directory, final MultipartFormDataInput input) {
}
I've used SOAPUI, curl and a HTML form to test this code and for all of them I get the same error: Could find no Content-Disposition header within part
12:55:19,739 WARN [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing POST /rest/input/myDir: org.jboss.resteasy.spi.ReaderException: java.lang.RuntimeException: Could find no Content-Disposition header within part
at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:123) [:6.0.0.Final]
at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:93) [:6.0.0.Final]
at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:146) [:6.0.0.Final]
at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:114) [:6.0.0.Final]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) [:6.0.0.Final]
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:252) [:6.0.0.Final]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:217) [:6.0.0.Final]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:206) [:6.0.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:503) [:6.0.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:480) [:6.0.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:139) [:6.0.0.Final]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:211) [:6.0.0.Final]
at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:59) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191) [:6.0.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [:6.0.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]
Caused by: java.lang.RuntimeException: Could find no Content-Disposition header within part
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInputImpl.extractPart(MultipartFormDataInputImpl.java:69) [:6.0.0.Final]
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.extractParts(MultipartInputImpl.java:108) [:6.0.0.Final]
at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.parse(MultipartInputImpl.java:77) [:6.0.0.Final]
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataReader.readFrom(MultipartFormDataReader.java:52) [:6.0.0.Final]
at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataReader.readFrom(MultipartFormDataReader.java:20) [:6.0.0.Final]
at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105) [:6.0.0.Final]
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:46) [:6.0.0.Final]
at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108) [:6.0.0.Final]
at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:111) [:6.0.0.Final]
... 35 more
I'm using JBoss AS 6 and resteasy. I do not understand why I'm getting this error or how to solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我尝试使用resteasy 时,在我的例子中,Seam 框架出现了同样的错误。
错误的原因是Seam MultipartFilter捕获了请求。我什么
所要做的就是告诉 Seam MultipartFilter 仅处理以以下结尾的多部分请求
*。接缝。
这样 Resteasy 就得到了预期的请求,而不是接缝过滤器。
我的休息方法:
上传表单:
components.xml:
即使您可能不使用 Seam,我也会开始查看您正在使用的框架,并且找出您的请求首先在哪里得到处理。
I got the same error when trying to using resteasy and in my case Seam framework.
The reason for the error was that Seam MultipartFilter captured the request. What I
had to do was to tell the Seam MultipartFilter to only handle multipart requests ending with
*.seam.
This way resteasy got the intended request, not the seam filter.
My Rest method:
Upload form:
components.xml:
Even though you might not use Seam I would start looking at the framework you are using and finding out where your request is being handled first.
我使用 Resteasy 和 Spring Boot 遇到了同样的错误。
Spring MVC 不配置
MultipartResolver
默认情况下,但是 Spring BootMultipartAutoConfiguration
确实。
只需将以下内容添加到您的
application.yml
即可禁用 Spring Boot 要配置的多部分解析器:如果您使用的 Spring Boot 版本低于 1.4:
I got the same error using Resteasy and Spring Boot.
Spring MVC does not configure a
MultipartResolver
by default, but the Spring BootMultipartAutoConfiguration
does.Simply add the following to your
application.yml
to disable the multipart resolver that Spring Boot wants to configure:If you're using a version of Spring Boot lower than 1.4: