Source:
public ResponseEntity uploadFiles( @PathVariable("conversationId") String conversationId, MultipartHttpServletRequest request) { OutgoingConversationResource conversationResource = repo.findOne(conversationId); if (conversationResource == null) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No conversation with supplied id found"); } ArrayList<String> files = Lists.newArrayList(request.getFileNames()); for (String f : files) { MultipartFile file = request.getFile(f); log.info("Key: "+file.getName()); log.info("Name: "+file.getOriginalFilename()); log.info("Content-Type: "+file.getContentType()); log.info("Size (bytes): "+file.getSize()); String filedir = props.getNextbest().getFiledir(); if (!filedir.endsWith("/")) { filedir = filedir+"/"; } filedir = filedir+conversationId+"/"; File localFile = new File(filedir+file.getOriginalFilename()); localFile.getParentFile().mkdirs(); try { FileOutputStream os = new FileOutputStream(localFile); BufferedOutputStream bos = new BufferedOutputStream(os); bos.write(file.getBytes()); bos.close(); if (!conversationResource.getFileRefs().values().contains(file.getOriginalFilename())) { conversationResource.addFileRef(file.getOriginalFilename()); } repo.delete(conversationResource); } catch (java.io.IOException e) { log.error("Could not write file {f}", localFile, e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not write file"); } } try { messageSender.sendMessage(conversationResource); } catch (MessageContextException | IOException e) { log.error("Send message failed.", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error during sending. Check logs"); } return ResponseEntity.ok().build(); }

Target:
public ResponseEntity uploadFiles( @PathVariable("conversationId") String conversationId, MultipartHttpServletRequest request) { OutgoingConversationResource conversationResource = repo.findOne(conversationId); if (conversationResource == null) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No conversation with supplied id found"); } ArrayList<String> files = Lists.newArrayList(request.getFileNames()); for (String f : files) { MultipartFile file = request.getFile(f); log.info("Key: "+file.getName()); log.info("Name: "+file.getOriginalFilename()); log.info("Content-Type: "+file.getContentType()); log.info("Size (bytes): "+file.getSize()); String filedir = props.getNextbest().getFiledir(); if (!filedir.endsWith("/")) { filedir = filedir+"/"; } filedir = filedir+conversationId+"/"; File localFile = new File(filedir+file.getOriginalFilename()); localFile.getParentFile().mkdirs(); try { FileOutputStream os = new FileOutputStream(localFile); BufferedOutputStream bos = new BufferedOutputStream(os); bos.write(file.getBytes()); bos.close(); os.close(); if (!conversationResource.getFileRefs().values().contains(file.getOriginalFilename())) { conversationResource.addFileRef(file.getOriginalFilename()); } repo.delete(conversationResource); } catch (java.io.IOException e) { log.error("Could not write file {f}", localFile, e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not write file"); } } try { messageSender.sendMessage(conversationResource); } catch (MessageContextException e) { log.error("Send message failed.", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error during sending. Check logs"); } return ResponseEntity.ok().build(); }