I'm trying to make a file upload work inside a REST project running on GlassFish Server 4.0.
The GlassFish server (although I find it confusing) has its own version of the Jersey library inside javax.ws.rs library which so far has worked fine, now however I need to use MediaType.MULTIPART_FORM_DATA and FormDataContentDisposition on the REST server service and can't find them inside GlassFish.
I therefore downloaded Jersey libraries and added
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
to the libraries, the server side code is
@ApplicationPath("webresources")
@Path("/file")
@Stateless
public class FileResource
{
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadWeb(@FormDataParam("file") InputStream inputStream,
@FormDataParam("file") FormDataContentDisposition disposition)
{
int read = 0;
byte[] bytes = new byte[1024];
try
{
while ((read = inputStream.read(bytes)) != -1)
{
System.out.write(bytes, 0, read);
}
}
catch (IOException ex)
{
Logger.getLogger(FileResource.class.getName()).log(Level.SEVERE, null, ex);
}
return Response.status(403).entity(inputStream).build();
}
}
Now however whenever a REST resource is called (even the ones that previously were working fine) I get the error:
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
How do I fix the above error? How do I add jersey.multipart support to the GlassFish server?