List of usage examples for org.springframework.http MediaType APPLICATION_ATOM_XML_VALUE
String APPLICATION_ATOM_XML_VALUE
To view the source code for org.springframework.http MediaType APPLICATION_ATOM_XML_VALUE.
Click Source Link
From source file:org.energyos.espi.datacustodian.web.api.AuthorizationRESTController.java
@RequestMapping(value = Routes.ROOT_AUTHORIZATION_COLLECTION, method = RequestMethod.POST, consumes = "application/atom+xml", produces = "application/atom+xml") @ResponseBody//from w w w . j a v a 2 s .c o m public void create(HttpServletResponse response, @RequestParam Map<String, String> params, InputStream stream) throws IOException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { Authorization authorization = this.authorizationService.importResource(stream); exportService.exportAuthorization(authorization.getId(), response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.energyos.espi.datacustodian.web.api.ElectricPowerUsageSummaryRESTController.java
@RequestMapping(value = Routes.ROOT_ELECTRIC_POWER_USAGE_SUMMARY_COLLECTION, method = RequestMethod.POST, consumes = "application/atom+xml", produces = "application/atom+xml") @ResponseBody/*from w w w . j a v a 2s . com*/ public void create(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, String> params, InputStream stream) throws IOException { Long subscriptionId = getSubscriptionId(request); response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { ElectricPowerUsageSummary electricPowerUsageSummary = this.electricPowerUsageSummaryService .importResource(stream); exportService.exportElectricPowerUsageSummary_Root(subscriptionId, electricPowerUsageSummary.getId(), response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.energyos.espi.datacustodian.web.api.IntervalBlockRESTController.java
@RequestMapping(value = Routes.ROOT_INTERVAL_BLOCK_COLLECTION, method = RequestMethod.POST, consumes = "application/atom+xml", produces = "application/atom+xml") @ResponseBody/* w w w . j a v a 2 s . c om*/ public void create(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, String> params, InputStream stream) throws IOException { Long subscriptionId = getSubscriptionId(request); response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { IntervalBlock intervalBlock = this.intervalBlockService.importResource(stream); exportService.exportIntervalBlock_Root(subscriptionId, intervalBlock.getId(), response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.energyos.espi.datacustodian.web.api.ElectricPowerQualitySummaryRESTController.java
@RequestMapping(value = Routes.ROOT_ELECTRIC_POWER_QUALITY_SUMMARY_COLLECTION, method = RequestMethod.POST, consumes = "application/atom+xml", produces = "application/atom+xml") @ResponseBody// w w w .j a v a2s . c o m public void create(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, String> params, InputStream stream) throws IOException { Long subscriptionId = getSubscriptionId(request); response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { ElectricPowerQualitySummary electricPowerQualitySummary = this.electricPowerQualitySummaryService .importResource(stream); exportService.exportElectricPowerQualitySummary_Root(subscriptionId, electricPowerQualitySummary.getId(), response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.energyos.espi.datacustodian.web.api.UsagePointRESTController.java
@RequestMapping(value = Routes.ROOT_USAGE_POINT_COLLECTION, method = RequestMethod.POST, consumes = "application/atom+xml", produces = "application/atom+xml") @ResponseBody/*from w w w . ja v a2s . c o m*/ public void create(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, String> params, InputStream stream) throws IOException { Long subscriptionId = getSubscriptionId(request); response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { UsagePoint usagePoint = this.usagePointService.importResource(stream); exportService.exportUsagePoint_Root(subscriptionId, usagePoint.getId(), response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:edu.mayo.trilliumbridge.webapp.TransformerController.java
protected void doTransform(HttpServletRequest request, HttpServletResponse response, String acceptHeader, String formatOverride, Transformer transformer) throws IOException { // default to XML if no Accept Header (it should at least be */*, but just in case). if (StringUtils.isBlank(acceptHeader)) { acceptHeader = MediaType.APPLICATION_ATOM_XML_VALUE; }// w w w. j ava2s . co m TrilliumBridgeTransformer.Format responseFormat = null; if (StringUtils.isNotBlank(formatOverride)) { responseFormat = TrilliumBridgeTransformer.Format.valueOf(formatOverride); } else { String[] accepts = StringUtils.split(acceptHeader, ','); for (String accept : accepts) { MediaType askedForType = MediaType.parseMediaType(accept); if (askedForType.isCompatibleWith(MediaType.TEXT_XML) || askedForType.isCompatibleWith(MediaType.APPLICATION_XML)) { responseFormat = TrilliumBridgeTransformer.Format.XML; } else if (askedForType.isCompatibleWith(MediaType.TEXT_HTML) || askedForType.isCompatibleWith(MediaType.APPLICATION_XHTML_XML)) { responseFormat = TrilliumBridgeTransformer.Format.HTML; } else if (askedForType.getType().equals("application") && askedForType.getSubtype().equals("pdf")) { responseFormat = TrilliumBridgeTransformer.Format.PDF; } if (responseFormat != null) { break; } } } if (responseFormat == null) { throw new UserInputException("Cannot return type: " + acceptHeader, HttpStatus.NOT_ACCEPTABLE); } String contentType; switch (responseFormat) { case XML: contentType = MediaType.APPLICATION_XML_VALUE; break; case HTML: contentType = MediaType.TEXT_HTML_VALUE.toString(); break; case PDF: contentType = "application/pdf"; break; default: throw new IllegalStateException("Illegal Response Format"); } InputStream inputStream; if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile(INPUT_FILE_NAME); inputStream = multipartFile.getInputStream(); } else { inputStream = request.getInputStream(); } inputStream = this.checkForUtf8BOMAndDiscardIfAny(this.checkStreamIsNotEmpty(inputStream)); // create a buffer so we don't use the servlet's output stream unless // we get a successful transform, because if we do use it, // we can't use the error view anymore. ByteArrayOutputStream baos = new ByteArrayOutputStream(); transformer.transform(inputStream, baos, responseFormat); try { response.setContentType(contentType); response.getOutputStream().write(baos.toByteArray()); } finally { IOUtils.closeQuietly(baos); } }
From source file:org.energyos.espi.datacustodian.web.api.BatchRESTController.java
/** * Supports Green Button Download My Data - A DMD file will be produced that * contains all Usage Points for the requested Retail Customer. * /*from w w w .j a v a 2s.co m*/ * Requires Authorization: Bearer [{data_custodian_access_token} | * {upload_access_token}] * * @param response * HTTP Servlet Response * @param retailCustomerId * The locally unique identifier of a Retail Customer - NOTE PII * @param HTTP * Query Parameters * @throws IOException * @throws FeedException * * @usage GET * /espi/1_1/resource/Batch/RetailCustomer/{retailCustomerId}/UsagePoint */ @RequestMapping(value = Routes.BATCH_DOWNLOAD_MY_DATA_COLLECTION, method = RequestMethod.GET, produces = "application/atom+xml") @ResponseBody public void download_collection(HttpServletResponse response, @PathVariable Long retailCustomerId, @RequestParam Map<String, String> params) throws IOException, FeedException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); response.addHeader("Content-Disposition", "attachment; filename=GreenButtonDownload.xml"); try { // TODO -- need authorization hook exportService.exportUsagePointsFull(0L, retailCustomerId, response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.energyos.espi.datacustodian.web.api.MeterReadingRESTController.java
@RequestMapping(value = Routes.METER_READING_COLLECTION, method = RequestMethod.GET, produces = "application/atom+xml") @ResponseBody//from www .j av a 2s . co m public void index(HttpServletResponse response, @PathVariable Long subscriptionId, @PathVariable Long usagePointId, @RequestParam Map<String, String> params) throws IOException, FeedException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); Long retailCustomerId = subscriptionService.findRetailCustomerId(subscriptionId, usagePointId); exportService.exportMeterReadings(subscriptionId, retailCustomerId, usagePointId, response.getOutputStream(), new ExportFilter(params)); }
From source file:org.energyos.espi.datacustodian.web.api.UsagePointRESTController.java
@RequestMapping(value = Routes.USAGE_POINT_COLLECTION, method = RequestMethod.GET, produces = "application/atom+xml") @ResponseBody/*from ww w .ja va2 s . c om*/ public void index(HttpServletResponse response, @PathVariable Long subscriptionId, @RequestParam Map<String, String> params) throws IOException, FeedException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { Subscription subscription = subscriptionService.findById(subscriptionId); Authorization authorization = subscription.getAuthorization(); RetailCustomer retailCustomer = authorization.getRetailCustomer(); Long retailCustomerId = retailCustomer.getId(); System.out.println("Exporting xpath usage points for subscription: " + subscriptionId); exportService.exportUsagePoints(subscriptionId, retailCustomerId, response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.energyos.espi.datacustodian.web.api.BatchRESTController.java
/** * Supports Green Button Download My Data A DMD file for a particular Usage * Point will be produced and returned to the Retail Customer * /*w w w . j a v a 2 s . c o m*/ * Requires Authorization: Bearer [{data_custodian_access_token} | * {upload_access_token}] * * @param response * HTTP Servlet Response * @param retailCustomerId * The locally unique identifier of a Retail Customer - NOTE PII * @param usagePointId * The locally unique identifier of a UsagePoint.id * @param params * params HTTP Query Parameters * @throws IOException * @throws FeedException * * @usage GET * /espi/1_1/resource/Batch/RetailCustomer/{retailCustomerId}/UsagePoint * /{usagePointId} */ @RequestMapping(value = Routes.BATCH_DOWNLOAD_MY_DATA_MEMBER, method = RequestMethod.GET, produces = "application/atom+xml") @ResponseBody public void download_member(HttpServletResponse response, @PathVariable Long retailCustomerId, @PathVariable Long usagePointId, @RequestParam Map<String, String> params) throws IOException, FeedException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); response.addHeader("Content-Disposition", "attachment; filename=GreenButtonDownload.xml"); try { exportService.exportUsagePointFull(0L, retailCustomerId, usagePointId, response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }