修改端点以接收XML文件

时间:2014-10-20 16:40:43

标签: java xml rest servlets endpoint

我使用Postman将xml文件作为附件发送到" form-data"选项。 我正在为" Content-Type"添加请求标头。 as" multipart / form-data"

enter image description here

但我的端点没有获取xml文件。我的端点如何接收xml文件?

@PUT
@Path("/{param1}/{param2}")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_JSON)
public Response receiveXmlFile(List<Identifier> identifierList,
                                        @PathParam("param1") String param1,
                                        @PathParam("param2") String param2,

                                        @FormParam("xmlFile") File xmlFile)
)
{
    try {
        return Response.status(Response.Status.OK).entity(readXmlFile(xmlFile)).build();
    } catch (Exception e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).header("error", e.getMessage()).build();
    }
}

1 个答案:

答案 0 :(得分:1)

解决方案是不发送邮递员的multipart/form-data标题。

当发送相同的请求但没有任何标题时,我的端点成功收到了该文件。

相关问题