I have a REST web service realized through Spring, it returns an object Response with 4 field, so the constructor is :
Response(boolean status, boolean success, Object result, ErrorResponse error)
Below there is the web service:
@Override
@RequestMapping(value = "/", method = RequestMethod.GET)
public @ResponseBody Response getAcquisition(@RequestParam(value="path", defaultValue="/home") String path){
File file;
try {
file = matlabClientServices.getFile(path);
if (file.exists())
return new Response(true, true, file, null);
else
return new Response(false, false, "File doesn't exist!", null);
} catch (Exception e) {
ErrorResponse errorResponse= ErrorResponseBuilder.buildErrorResponse(e);
LOG.error("Threw exception in MatlabClientControllerImpl::getAcquisition :" + errorResponse.getStacktrace());
return new Response(false, false, "Error during file retrieving!", errorResponse);
}
}
In Object field of Response I would like tu fill File, so when I call this web service I can retrieve the file from the server. But in my client application the Response result field is a String and not a File.
@Override
@RequestMapping(value = "/test/", method = RequestMethod.GET)
public Response getFileTest(@RequestParam(value="path", defaultValue="/home") String path){
RestTemplate restTemplate = new RestTemplate();
Response response = restTemplate.getForObject("http://localhost:8086/ATS/client/file/?path={path}", Response.class, path);
if (response.isStatus() && response.isSuccess()){
@SuppressWarnings("unused")
File fileLoaded= (File)response.getResult();
}
return response;
}
Do you know where is the error? My aim is to send file from server and receive and store it in another pc. Thanks, regards Otherwise, if I use
@RequestMapping(value = "/{path}", method = RequestMethod.GET)
public @ResponseBody FileSystemResource getFile(@PathVariable("path") String path) {
return new FileSystemResource(matlabClientServices.getFile(path));
}
how can retrieve the file and write it in specific path and how can I check for exception or other error?