这是基于弹簧的api:
@RequestMapping(value = ControllerConstants.FILE_UPLOAD_URI, method = RequestMethod.POST)
public @ResponseBody
boolean processUpload(@RequestParam("file") MultipartFile file, @RequestParam("accessionId") String accessionId, @RequestParam("protocol") String protocol, HttpServletRequest request) throws IOException {
logger.info("upload file: {} with accessionId: {} and protocol:{}",file.getOriginalFilename(),accessionId,protocol);
return dataManagerService.writeFile(file, protocol, accessionId);
}
这是我的最大努力:
FormDataMultiPart part = new FormDataMultiPart()
.field("accessionId", returnedAccessionId)
.field("protocol", protocol)
.field("name", file.getName())
.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("file", file.getAbsolutePath());
params.add("accessionId", returnedAccessionId);
params.add("protocol", protocol);
WebResource resource2 = client.resource(agent.getServerEndpointUri() + "/novax/service/dataManager/upload");
ClientResponse response4 = resource2
.queryParams(params)
.type(MediaType.MULTIPART_FORM_DATA_TYPE)
.post(ClientResponse.class, part);
响应为 404。
2 个问题: - 是否正确定义了 spring API?- 如何使用 Jersey 客户端正确调用 api?