@RequestMapping(value = "/resource/stream/{language}/{name}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void editStreamContent( @PathVariable String language, @PathVariable String name, @RequestParam MultipartFile contentFile) throws ContentNotFoundException, CMSLiteException, IOException { StreamContent streamContent = cmsLiteService.getStreamContent(language, name); streamContent.setChecksum(md5Hex(contentFile.getBytes())); streamContent.setContentType(contentFile.getContentType()); streamContent.setContent(ArrayUtils.toObject(contentFile.getBytes())); cmsLiteService.addContent(streamContent); }
@RequestMapping(value = "/resource/{type}/{language}/{name}", method = RequestMethod.GET) @ResponseBody public Content getContent( @PathVariable String type, @PathVariable String language, @PathVariable String name) throws ContentNotFoundException { Content content = null; switch (type) { case "stream": content = cmsLiteService.getStreamContent(language, name); break; case "string": content = cmsLiteService.getStringContent(language, name); break; default: } return content; }
@RequestMapping(value = "/stream/{language}/{name}", method = RequestMethod.GET) public void getStreamContent( @PathVariable String language, @PathVariable String name, HttpServletResponse response) throws IOException { LOG.info(String.format("Getting resource for : stream:%s:%s", language, name)); try (OutputStream out = response.getOutputStream()) { StreamContent streamContent = cmsLiteService.getStreamContent(language, name); response.setContentLength(streamContent.getContent().length); response.setContentType(streamContent.getContentType()); response.setHeader("Accept-Ranges", "bytes"); response.setStatus(HttpServletResponse.SC_OK); out.write(ArrayUtils.toPrimitive(streamContent.getContent())); } catch (Exception e) { LOG.error( String.format( "Content not found for : stream:%s:%s%n:%s", language, name, Arrays.toString(e.getStackTrace()))); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, NOT_FOUND_RESPONSE); } }