我有一个可以上传文件的休息资源。
@Path("/rest/input")
public class InputResourceBean {
@POST
@Path("{directory: .*}")
@Consumes("multipart/form-data")
public void post(final String directory, final MultipartFormDataInput input) {
}
我已经使用SOAPUI,curl和HTML表单来测试这段代码,但是对于所有这些代码我得到了同样的错误:在部分内找不到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
我正在使用JBoss AS 6和resteasy。我不明白为什么我会收到这个错误或如何解决它。
答案 0 :(得分:2)
我在尝试使用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,我也会开始查看您正在使用的框架并找出您的请求首先处理的位置。
答案 1 :(得分:2)
使用Resteasy和Spring Boot我遇到了同样的错误。
Spring MVC默认情况下不配置MultipartResolver
,但Spring Boot MultipartAutoConfiguration
确实。
只需将以下内容添加到application.yml
即可禁用Spring Boot要配置的多部分解析程序:
spring.http.multipart.enabled: false
如果您使用的Spring版本低于1.4:
multipart.enabled: false