List of usage examples for org.springframework.core.io InputStreamResource InputStreamResource
public InputStreamResource(InputStream inputStream)
From source file:eu.serco.dhus.server.http.webapp.wps.controller.WpsAdfSearchController.java
@RequestMapping(value = "/auxiliaries/download", method = { RequestMethod.GET }) public ResponseEntity<?> downloadAuxiliaries(@RequestParam(value = "uuid", defaultValue = "") String uuid, @RequestParam(value = "filename", defaultValue = "file") String filename) { try {//ww w . j av a2 s .c o m String hashedString = ConfigurationManager.getHashedConnectionString(); //SD-1928 add download filename archive extension String downloadFilename = (filename.endsWith(DOWNLOAD_EXT)) ? (filename) : filename + DOWNLOAD_EXT; String urlString = ConfigurationManager.getExternalDHuSHost() + "odata/v1/Products('" + uuid + "')/$value"; logger.info("urlString:::: " + urlString); URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "Basic " + hashedString); InputStream is = conn.getInputStream(); InputStreamResource isr = new InputStreamResource(is); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Authorization", "Basic " + hashedString); httpHeaders.add("Content-disposition", "attachment; filename=" + downloadFilename); httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM); return new ResponseEntity<>(isr, httpHeaders, HttpStatus.OK); } catch (Exception e) { logger.error(" Failed to download Auxiliary File."); e.printStackTrace(); return new ResponseEntity<>("{\"code\":\"unauthorized\"}", HttpStatus.UNAUTHORIZED); } }
From source file:com.greglturnquist.springagram.fileservice.mongodb.ApplicationController.java
@RequestMapping(method = RequestMethod.GET, value = "/files/{filename}") public ResponseEntity<?> getFile(@PathVariable String filename) { GridFsResource file = this.fileService.findOne(filename); if (file == null) { return ResponseEntity.notFound().build(); }//from www . j a v a 2 s.c o m try { return ResponseEntity.ok().contentLength(file.contentLength()) .contentType(MediaType.parseMediaType(file.getContentType())) .body(new InputStreamResource(file.getInputStream())); } catch (IOException e) { return ResponseEntity.badRequest().body("Couldn't process the request"); } }
From source file:th.co.geniustree.intenship.advisor.controller.InformationController.java
@RequestMapping(value = "/getfileinformation/{id}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getFile(@PathVariable("id") FileUpload fileUpload) { ResponseEntity<InputStreamResource> body = ResponseEntity.ok().contentLength(fileUpload.getContent().length) .contentType(MediaType.parseMediaType(fileUpload.getMimeType())) .header("Content-Disposition", "attachment; filename=\"" + fileUpload.getName() + "\"") .body(new InputStreamResource(new ByteArrayInputStream(fileUpload.getContent()))); return body;/*from ww w. j a v a 2 s. c o m*/ }
From source file:business.services.PaNumberService.java
public HttpEntity<InputStreamResource> writeAllPaNumbers(List<LabRequestRepresentation> labRequests) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(out, PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING); CSVWriter csvwriter = new CSVWriter(writer, ',', '"'); csvwriter.writeNext(PA_NUMBERS_HEADER); for (LabRequestRepresentation labRequest : labRequests) { String labRequestCode = labRequest.getLabRequestCode(); String status = labRequest.getStatus().toString(); String labName = labRequest.getLab().getName(); String requesterName = labRequest.getRequesterName(); String requesterEmail = labRequest.getRequesterEmail(); String requesterTelephone = labRequest.getRequesterTelephone(); String labRequestSentDate = labRequest.getSendDate() == null ? "" : labRequest.getSendDate().toString(); for (PathologyRepresentation item : labRequest.getPathologyList()) { csvwriter.writeNext(new String[] { labRequestCode, status, item.getPaNumber(), labName, requesterName, requesterEmail, requesterTelephone, labRequestSentDate }); }/*from w ww. ja v a 2s . c o m*/ } csvwriter.flush(); writer.flush(); out.flush(); InputStream in = new ByteArrayInputStream(out.toByteArray()); csvwriter.close(); writer.close(); out.close(); InputStreamResource resource = new InputStreamResource(in); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("text/csv;charset=" + PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING)); String filename = "pa_numbers.csv"; headers.set("Content-Disposition", "attachment; filename=" + filename); HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers); return response; }
From source file:com.spartasystems.holdmail.rest.MessageController.java
@RequestMapping(value = "/{messageId}/content/{contentId}") public ResponseEntity getMessageContentByPartId(@PathVariable("messageId") long messageId, @PathVariable("contentId") String contentId) { Message message = messageService.getMessage(messageId); MessageContentPart content = message.getContent().findByContentId(contentId); return ResponseEntity.ok().header("Content-Type", content.getContentType()) .body(new InputStreamResource(content.getContentStream())); }
From source file:com.github.lynxdb.server.api.http.handlers.EpQuery.java
@RequestMapping(path = "", method = { RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE }, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity rootJson(@RequestBody @Valid QueryRequest _request, Authentication _authentication, HttpServletResponse _response) { User user = (User) _authentication.getPrincipal(); List<Query> queries; try {//from w w w. j av a 2s . c om queries = parseQuery(vhosts.byId(user.getVhost()), _request); } catch (ParsingQueryException ex) { return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, ex.getMessage(), ex).response(); } File f; FileOutputStream fos; try { f = File.createTempFile("lynx.", ".tmp"); fos = new FileOutputStream(f); } catch (IOException ex) { return new ErrorResponse(mapper, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), ex).response(); } try { saveResponse(fos, queries); } catch (IOException ex) { return new ErrorResponse(mapper, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), ex).response(); } try { return ResponseEntity.ok(new InputStreamResource(new FileInputStream(f))); } catch (FileNotFoundException ex) { return new ErrorResponse(mapper, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), ex).response(); } finally { f.delete(); } }
From source file:com.sitewhere.configuration.ExternalConfigurationResolver.java
@Override public ApplicationContext resolveTenantContext(ITenant tenant, IVersion version, ApplicationContext parent) throws SiteWhereException { URL remoteTenantUrl = getRemoteTenantUrl(tenant, version); GenericApplicationContext context = new GenericApplicationContext(parent); // Plug in custom property source. Map<String, Object> properties = new HashMap<String, Object>(); properties.put("sitewhere.edition", version.getEditionIdentifier().toLowerCase()); properties.put("tenant.id", tenant.getId()); MapPropertySource source = new MapPropertySource("sitewhere", properties); context.getEnvironment().getPropertySources().addLast(source); try {// ww w . j a va 2s . co m // Read context from XML configuration file. XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(remoteTenantUrl.openStream())); context.refresh(); return context; } catch (BeanDefinitionStoreException e) { throw new SiteWhereException(e); } catch (IOException e) { throw new SiteWhereException(e); } }
From source file:net.jakubholy.jeeutils.jsfelcheck.beanfinder.SpringContextBeanFinder.java
private Resource[] toResources(Collection<InputResource> resourceFiles) { Resource[] locations = new Resource[resourceFiles.size()]; int index = 0; for (InputResource configFile : resourceFiles) { if (configFile.getFileIfAvailable() != null) { locations[index++] = new FileSystemResource(configFile.getFileIfAvailable()); } else {// www . ja v a2 s .c om locations[index++] = new InputStreamResource(configFile.getStream()); } } return locations; }
From source file:br.edu.ifpb.controllers.TopicController.java
@RequestMapping(value = "/image/{id}", method = RequestMethod.GET) @ResponseBody/* w w w .ja v a 2s .c o m*/ public ResponseEntity<InputStreamResource> getImage(@PathVariable String id) { byte[] file = ImageTopicRepository.getTopicImage2(id); return ResponseEntity.ok().contentLength(file.length) // .contentType(MediaType.parseMediaType(file.getGridFSFile().getMetadata().getString("content-type"))) .body(new InputStreamResource(new ByteArrayInputStream(file))); }
From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java
/** * Method to get the spring application context for a spring service * * @param axisService - spring service//w w w. j a v a2 s.c o m * @param contextLocation - location of the application context file * @return - GenericApplicationContext for the given spring service * @throws AxisFault */ public static GenericApplicationContext getSpringApplicationContext(AxisService axisService, String contextLocation) throws AxisFault { Parameter appContextParameter = axisService.getParameter(SPRING_APPLICATION_CONTEXT); if (appContextParameter != null) { return (GenericApplicationContext) appContextParameter.getValue(); } else { GenericApplicationContext appContext = new GenericApplicationContext(); ClassLoader classLoader = axisService.getClassLoader(); appContext.setClassLoader(classLoader); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false); InputStream in = classLoader.getResourceAsStream(contextLocation); if (in == null) { throw new AxisFault("Spring context cannot be located for AxisService"); } xbdr.loadBeanDefinitions(new InputStreamResource(in)); appContext.refresh(); axisService.addParameter(new Parameter(SPRING_APPLICATION_CONTEXT, appContext)); } catch (Exception e) { throw AxisFault.makeFault(e); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } return appContext; } }