Resteasy 和文件上传:没有出现内容处置错误

发布于 2024-11-09 20:13:40 字数 5607 浏览 3 评论 0原文

我有一个可以上传文件的休息资源。

   @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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所有深爱都是秘密 2024-11-16 20:13:40

当我尝试使用resteasy 时,在我的例子中,Seam 框架出现了同样的错误。
错误的原因是Seam MultipartFilter捕获了请求。我什么
所要做的就是告诉 Seam MultipartFilter 仅处理以以下结尾的多部分请求
*。接缝。

这样 Resteasy 就得到了预期的请求,而不是接缝过滤器。

我的休息方法:

@POST
@Path("admin/uploadImage")
public String uploadImage(@MultipartForm UploadForm form);

上传表单:

public class UploadForm {

    private byte[] filedata;

    public UploadForm() {
    }

    public byte[] getFileData() {
        return filedata;
    }

    @FormParam("filedata")
    @PartType("application/octet-stream")
    public void setFileData(final byte[] filedata) {
        this.filedata = filedata;
    }


}

components.xml:

    <component class="org.jboss.seam.web.MultipartFilter">
        <property name="createTempFiles">true</property>
        <property name="maxRequestSize">8000000</property>
        <property name="urlPattern">*.seam</property>
    </component>

即使您可能不使用 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:

@POST
@Path("admin/uploadImage")
public String uploadImage(@MultipartForm UploadForm form);

Upload form:

public class UploadForm {

    private byte[] filedata;

    public UploadForm() {
    }

    public byte[] getFileData() {
        return filedata;
    }

    @FormParam("filedata")
    @PartType("application/octet-stream")
    public void setFileData(final byte[] filedata) {
        this.filedata = filedata;
    }


}

components.xml:

    <component class="org.jboss.seam.web.MultipartFilter">
        <property name="createTempFiles">true</property>
        <property name="maxRequestSize">8000000</property>
        <property name="urlPattern">*.seam</property>
    </component>

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.

饮惑 2024-11-16 20:13:40

我使用 Resteasy 和 Spring Boot 遇到了同样的错误。

Spring MVC 不配置 MultipartResolver 默认情况下,但是 Spring Boot MultipartAutoConfiguration确实

只需将以下内容添加到您的 application.yml 即可禁用 Spring Boot 要配置的多部分解析器:

spring.http.multipart.enabled: false

如果您使用的 Spring Boot 版本低于 1.4:

multipart.enabled: false

I got the same error using Resteasy and Spring Boot.

Spring MVC does not configure a MultipartResolver by default, but the Spring Boot MultipartAutoConfiguration does.

Simply add the following to your application.yml to disable the multipart resolver that Spring Boot wants to configure:

spring.http.multipart.enabled: false

If you're using a version of Spring Boot lower than 1.4:

multipart.enabled: false
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文