1
這裏REST API是基於彈簧的API:調用基於彈簧的使用Jersey客戶端
@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?