@RequestMapping(value = "/network.xml", method = RequestMethod.GET) public void exportToXml(HttpServletRequest request, HttpServletResponse response) throws Exception { DistributionNetwork network = distributionNetworkRepository.read(); response.setContentType("application/xml"); SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy"); String file = "risk-analyzer-network-export-" + dateFormat.format(new Date()) + ".xml"; response.setHeader("Content-Disposition", "attachment;filename=" + file); networkMarshaller.marshall(network, response.getOutputStream()); }
@RequestMapping(value = "/network", method = RequestMethod.POST) public void importFromXml( @RequestParam("networkXml") MultipartFile networkXml, HttpServletResponse resp) throws Exception { Boolean result = true; if (!networkXml.isEmpty()) { DistributionNetwork network = networkMarshaller.unmarshall(networkXml.getInputStream()); distributionNetworkRepository.save(network); } else { result = false; } // FIXME This text/html content type is probably a bug in ExtJS 4 resp.setContentType("text/html"); resp.getWriter().printf("{success: %s}", result); }
@RequestMapping(value = "/network", method = RequestMethod.GET) public @ResponseBody DistributionNetwork getNetwork() throws Exception { return distributionNetworkRepository.read(); }