因此,我对使用解析PDF的方法进行单元测试时遇到了一些麻烦
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response parsingPdfOrange(@FormDataParam("fichier") InputStream uploadedInputStream,
@FormDataParam("fichier") FormDataContentDisposition fileDetail) {
try {
String uploadedFileLocation = "D:/tmp/doc.pdf";
String info = "facture Orange:"
+ OrangeService.ParseFacture(uploadedFileLocation, uploadedInputStream).toString();
return Response.status(201).entity(info).build();
哪个工作正常我的网址给我的好结果等但是
@Override
protected Application configure() {
return new ResourceConfig(OrangeWebService.class).register(MultiPartFeature.class);
}
@Override
protected void configureClient(ClientConfig config) {
config.register(MultiPartFeature.class);
}
@Test
public void parsePDF_NullPointerExcpetion() throws Exception {
try {
FileDataBodyPart filePart = new FileDataBodyPart("file", new File(pathtoRessources));
FormDataMultiPart formDataMultipart = new FormDataMultiPart();
FormDataMultiPart multipart = (FormDataMultiPart) formDataMultipart.bodyPart(filePart);
Response response = (target("pdf").request().post(Entity.entity(multipart, multipart.getMediaType())));
System.out.println(response);
response.close();
} catch (Exception e) {
e.printStackTrace();
}
这是我的测试代码,pb在这里:似乎我的FormDataMultiPart很好,但是当我执行Entity.entity(multipart,multipart.getMediaType()时,它返回一个空值,因为我得到一个nullPointerException。 / p>
我需要帮助,非常感谢。
答案 0 :(得分:0)
文件部件名称为"fichier"
@FormDataParam("fichier") InputStream uploadedInputStream
但是您将其发送为"file"
FileDataBodyPart filePart = new FileDataBodyPart("file", new File(pathtoRessources));
修复此问题。