簡體   English   中英

jersey rest web 服務返回對象列表,其中對象包含文件的字節數組

[英]jersey rest web service to return list of objects where objects contain byte array for file

問題是返回包含一些文件相關信息的文件列表。

這是我的網絡服務類:

@Path("/pdfsigning")
public class PdfSigningResource{    

    @EJB
    private PdfSigningFacadeInt pdfSigningFacadeInt;

    @POST
    @Path("/unsignedfilelist")
    @Produces({ MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON })
    public Response getUnsignedFileList() {

        List<FileInfoDto> unsignedFileInfoDtoList = pdfSigningFacadeInt
                .getUnsignedFileList();

        GenericEntity<List<FileInfoDto>> genericUnsignedFileInfoDtoList = new GenericEntity<List<FileInfoDto>>(
                unsignedFileInfoDtoList) {
        };
        return Response.ok(Status.OK).entity(genericUnsignedFileInfoDtoList)
                .build();

    }
}

省略了 getter/setter 的 FileInfoDto 類:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class FileInfoDto implements Serializable {

    private static final long serialVersionUID = 303766558349361898L;

    @XmlElement(name = "fileName")
    private String fileName;

    @XmlElement(name = "fileType")
    private String fileType;

    // other fields ...

    @XmlElement(name = "fileByteArray")
    private byte[] fileByteArray;

這是 jersey-1 客戶端:

public class FileService implements FileServiceInt {

   public List<FileInfoDto> getUnsignedFileList() {            

       //code to build url  

        WebResource unsignedFileListResource = unsignedFileListClient.resource(url);


        ClientResponse response = unsignedFileListResource.type(MediaType.APPLICATION_JSON)                                        .post(ClientResponse.class);

        if (Constants.CLIENT_RESPONSE_STATUS != response.getStatus()) {
            LOGGER.debug(">>>>>>>>>> Response Not OK <<<<<<<<<<<<<");
            //TODO throw proper exception
        } else {
            LOGGER.debug(">>>>>>>>>> Response OK <<<<<<<<<<<<<");
        }

        // This line throw exception
        List<FileInfoDto> entityList = response.getEntity(new GenericType<List<FileInfoDto>>() {
        });    

        return entityList;
    }

}

從服務器獲得的響應是​​“OK”。 但是線

List<FileInfoDto> entityList = response.getEntity(new GenericType<List<FileInfoDto>>() {
            });

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/mail/internet/MimeMultipart拋出Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/mail/internet/MimeMultipart

在 POM 中,我的依賴為

<dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-multipart</artifactId>
            <version>1.18.1</version>
        </dependency>

我錯過了什么? 我們不能以這種方式獲取文件列表嗎?

對於此版本的 jersey,使用javax.mail.internet.MimeMultipart需要 Java Mail(請參閱Jersey 1.x 文檔/Mail 和 MIME multipart )。

將此依賴項添加到您的 pom.xml:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.7</version>
</dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM