【发布时间】:2014-01-04 03:44:54
【问题描述】:
我正在尝试在 GlassFish Server 4.0 上运行的 REST 项目中进行文件上传。
GlassFish 服务器(虽然我觉得它令人困惑)在 javax.ws.rs 库中拥有自己的 Jersey 库版本,到目前为止运行良好,但是现在我需要在 REST 服务器上使用 MediaType.MULTIPART_FORM_DATA 和 FormDataContentDisposition服务,但在 GlassFish 中找不到它们。
因此我下载了 Jersey 库并添加了
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
到库,服务器端代码是
@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();
}
}
然而,现在每当调用 REST 资源时(即使是以前工作正常的资源),我都会收到错误消息:
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
如何解决上述错误?如何向 GlassFish 服务器添加 jersey.multipart 支持?
【问题讨论】:
-
这个答案可能会有所帮助:stackoverflow.com/questions/18252990/…
标签: rest jakarta-ee netbeans glassfish glassfish-4