RESTEasy – Could not find message body reader for type: multipart/form-data

Note
Tested with Eclipse 3.6, Maven 3 and RESTEasy 2.2.1.GA

Question

Developing file upload feature with RESTEasy, see following RESTEasy multipart file upload example :


public class FileUploadForm {
	
	private byte[] data;

	@FormParam("file")
	public void setData(byte[] data) {
		this.data = data;
	}

	//...code omitted
}

@Path("/file")
public class UploadFileService {
	
	@POST
	@Path("/upload")
	@Consumes("multipart/form-data")
	public Response uploadFile(@MultipartForm FileUploadForm form) {
		//...code omitted
	}

}

Above file upload example is able to compile without any error. However, it prompts following scary error message during when upload file to the deployed service.

resteasy error message

HTTP Status 500 - Bad arguments passed to public javax.ws.rs.core.Response 
com.mkyong.rest.UploadFileService.uploadFile(com.mkyong.rest.FileUploadForm) 
( org.jboss.resteasy.spi.BadRequestException org.jboss.resteasy.spi.BadRequestException: 
Could not find message body reader for type: 
class com.mkyong.rest.FileUploadForm of content type: multipart/form-data;
boundary="---------------------------98942870323811" )

Solution

RESTEasy is unable to find message body reader for “multipart/form-data“, it should be included in “resteasy-multipart-provider.jar“.

To fix it, make sure follow 2 steps are checked.

1. Declared resteasy-multipart-provider

Make sure “resteasy-multipart-provider.jar” is declared. See Maven example :

File : pom.xml


	<dependency>
		<groupId>org.jboss.resteasy</groupId>
		<artifactId>resteasy-multipart-provider</artifactId>
		<version>2.2.0.GA</version>
	</dependency>

2. mvn eclipse:eclipse -Dwtpversion=2.0

For web application project in Eclipse, you need to use following command to make sure all dependencies are deployed correctly.


mvn eclipse:eclipse -Dwtpversion=2.0

After that, check your Eclipse “Web Deployment Assembly“, make sure all required dependencies are included.

Remember -Dwtpversion=2.0
In Eclipse (web project), the classic “mvn eclipse:eclipse” is unable to get all dependencies deployed, instead, you should use “mvn eclipse:eclipse -Dwtpversion=2.0“.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
5 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
Joseph Appeahandy_liuhaijunAnjaliPhaniGuruji_89 Recent comment authors
newest oldest most voted
Guruji_89
Guest
Guruji_89

Hi similar to the error you have shown, I’m getting this one -“Could not find message body reader for type: Application/json”. I’m unable to figure out which jar I’ve missed. Could you throw some light on this?

Phani
Guest
Phani

Try with this..

org.codehaus.jackson
jackson-xc
1.7.0
.. As I was going through the site.. stumbled upon here and thought of help if still looking for it.

trackback
JAX-RS TUTORIALS | BUYWORKSELL

[…] RESTEasy – Could not find message body reader for type: multipart/form-data […]

Joseph Appeah
Guest
Joseph Appeah

I added the the dependency to my pom and still had the same error. I expanded the my jar file and the resteasy-multipart-provider classes are in there. Is there a work around for this?

andy_liuhaijun
Guest
andy_liuhaijun

Hi

Anjali
Guest
Anjali

Hai