List of usage examples for org.springframework.http HttpHeaders setContentType
public void setContentType(@Nullable MediaType mediaType)
From source file:org.openbaton.marketplace.api.RestVNFPackage.java
@RequestMapping(value = "{id}/download-with-link", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK)//from w w w . j a va 2 s. co m public ResponseEntity downloadWithLink(@PathVariable("id") String id) throws NotFoundException, IOException, ArchiveException { log.trace("Incoming request for getting VNFPackage: " + id); ByteArrayOutputStream tar = vnfPackageManagement.compose(id); log.trace("Incoming request served by returning VNFPackage: " + id); VNFPackageMetadata vnfPackageMetadata = vnfPackageManagement.get(id); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.add("Content-Disposition", "attachment; filename=" + vnfPackageMetadata.getVnfPackageFileName()); ResponseEntity responseEntity = new ResponseEntity(tar.toByteArray(), headers, HttpStatus.OK); return responseEntity; }
From source file:org.zlogic.vogon.web.controller.DataController.java
/** * Returns all data/*from w ww .j a v a2 s. c om*/ * * @param userPrincipal the authenticated user * @return the HTTPEntity for the file download */ @RequestMapping(value = "/export/xml", method = { RequestMethod.GET, RequestMethod.POST }) public HttpEntity<byte[]> exportDataXML(@AuthenticationPrincipal VogonSecurityUser userPrincipal) throws RuntimeException { VogonUser user = userRepository.findByUsernameIgnoreCase(userPrincipal.getUsername()); try { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); XmlExporter exporter = new XmlExporter(outStream); Sort accountSort = new Sort(new Sort.Order(Sort.Direction.ASC, "id"));//NOI18N Sort transactionSort = new Sort(new Sort.Order(Sort.Direction.ASC, "id"));//NOI18N exporter.exportData(user, accountRepository.findByOwner(user, accountSort), transactionRepository.findByOwner(user, transactionSort), null); String date = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()); //NOI18N HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_XML); headers.setContentLength(outStream.size()); headers.setContentDispositionFormData("attachment", "vogon-" + date + ".xml"); //NOI18N //NOI18N return new HttpEntity<>(outStream.toByteArray(), headers); } catch (VogonExportException ex) { throw new RuntimeException(ex); } }
From source file:org.openbaton.marketplace.api.RestVNFPackage.java
/** * Returns an VNFPackage with the given ID from the marketplace * * @param id/*from w w w . ja v a 2 s .com*/ * @return VNFPackage */ @RequestMapping(value = "{id}/download", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public ResponseEntity download(@PathVariable("id") String id) throws NotFoundException, IOException, ArchiveException { log.trace("Incoming request for getting VNFPackage: " + id); ByteArrayOutputStream tar = vnfPackageManagement.download(id); log.trace("Incoming request served by returning VNFPackage: " + id); VNFPackageMetadata vnfPackageMetadata = vnfPackageManagement.get(id); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.add("Content-Disposition", "attachment; filename=" + vnfPackageMetadata.getVnfPackageFileName()); ResponseEntity responseEntity = new ResponseEntity(tar.toByteArray(), headers, HttpStatus.OK); return responseEntity; }
From source file:com.companyname.plat.commons.client.HttpRestfulClient.java
private HttpHeaders getUnsecuredHeaders() { HttpHeaders headers = new HttpHeaders(); if (getContentTypeHeader() != null) { headers.setContentType(getContentTypeHeader()); }/*from w w w .ja v a 2s. c o m*/ if (getAcceptHeader() != null) { headers.setAccept(Arrays.asList(getAcceptHeader())); } return headers; }
From source file:com.orange.ngsi.client.NgsiClient.java
/** * The default HTTP request headers used for the requests. * @return the HTTP request headers. *//*from ww w . j av a 2s.com*/ public HttpHeaders getRequestHeaders() { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.APPLICATION_XML); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); return requestHeaders; }
From source file:fr.itldev.koya.services.impl.KoyaContentServiceImpl.java
private Document upload(User user, NodeRef parent, Object o) throws AlfrescoServiceException { MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>(); parts.add("filedata", o); parts.add("destination", parent.toString()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers); AlfrescoUploadReturn upReturn = fromJSON(new TypeReference<AlfrescoUploadReturn>() { }, user.getRestTemplate().postForObject(getAlfrescoServerUrl() + REST_POST_UPLOAD, request, String.class)); return (Document) getSecuredItem(user, upReturn.getNodeRef()); }
From source file:us.polygon4.izzymongo.controller.AppController.java
/** * Exports database schema as FreeMind map * /* w w w . j a v a 2s . c o m*/ * @param fileName database name * @return fileName + ".mm" * @throws Exception */ @RequestMapping(value = "/export/{fileName}", method = RequestMethod.GET) public HttpEntity<byte[]> createExport(@PathVariable("fileName") String fileName) throws Exception { byte[] documentBody = null; documentBody = service.getDbSchema(fileName); fileName = fileName + ".mm"; HttpHeaders header = new HttpHeaders(); header.setContentType(new MediaType("application", "xml")); header.set("Content-Disposition", "attachment; filename=" + fileName.replace(" ", "_")); header.setContentLength(documentBody.length); return new HttpEntity<byte[]>(documentBody, header); }
From source file:com.facetime.cloud.server.support.UTF8HttpMessageConverter.java
@Override protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException { HttpHeaders headers = outputMessage.getHeaders(); if (!"UTF-8".equalsIgnoreCase(headers.getContentType().getCharSet().displayName())) { headers.setContentType(UTF_8_MEDIA_TYPE); }/* ww w . j a va 2 s .c o m*/ if (writeAcceptCharset) { headers.setAcceptCharset(getAcceptedCharsets()); } MediaType contentType = outputMessage.getHeaders().getContentType(); Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET; FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset)); }
From source file:org.zlogic.vogon.web.controller.DataController.java
/** * Returns all data/*w ww.j a v a 2 s .c om*/ * * @param userPrincipal the authenticated user * @return the HTTPEntity for the file download */ @RequestMapping(value = "/export/json", method = { RequestMethod.GET, RequestMethod.POST }) public HttpEntity<byte[]> exportDataJSON(@AuthenticationPrincipal VogonSecurityUser userPrincipal) throws RuntimeException { VogonUser user = userRepository.findByUsernameIgnoreCase(userPrincipal.getUsername()); try { ClassExporter exporter = new ClassExporter(); Sort accountSort = new Sort(new Sort.Order(Sort.Direction.ASC, "id"));//NOI18N Sort transactionSort = new Sort(new Sort.Order(Sort.Direction.ASC, "id"));//NOI18N exporter.exportData(user, accountRepository.findByOwner(user, accountSort), transactionRepository.findByOwner(user, transactionSort), null); ExportedData exportedData = exporter.getExportedData(); //Process transactions for JSON List<FinanceTransactionJson> processedTransactions = initializationHelper .initializeTransactions(exportedData.getTransactions()); exportedData.getTransactions().clear(); for (FinanceTransactionJson transaction : processedTransactions) exportedData.getTransactions().add(transaction); //Convert to JSON byte[] output = jsonMapper.writer().withDefaultPrettyPrinter().writeValueAsString(exportedData) .getBytes("utf-8"); //NOI18N String date = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()); //NOI18N HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON_UTF8); headers.setContentLength(output.length); headers.setContentDispositionFormData("attachment", "vogon-" + date + ".json"); //NOI18N //NOI18N return new HttpEntity<>(output, headers); } catch (VogonExportException | IOException ex) { throw new RuntimeException(ex); } }
From source file:io.fabric8.che.starter.client.CheRestClient.java
public Workspace createWorkspace(String cheServerURL, String name, String stack, String repo, String branch) throws IOException { // The first step is to create the workspace String url = generateURL(cheServerURL, CheRestEndpoints.CREATE_WORKSPACE); String jsonTemplate = workspaceTemplate.createRequest().setName(name).setStack(stack) .setDescription(workspaceHelper.getDescription(repo, branch)).getJSON(); RestTemplate template = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(jsonTemplate, headers); ResponseEntity<Workspace> workspaceResponse = template.exchange(url, HttpMethod.POST, entity, Workspace.class); Workspace workspace = workspaceResponse.getBody(); LOG.info("Workspace has been created: {}", workspace); workspace.setName(workspace.getConfig().getName()); workspace.setDescription(workspace.getConfig().getDescription()); for (WorkspaceLink link : workspace.getLinks()) { if (WORKSPACE_LINK_IDE_URL.equals(link.getRel())) { workspace.setWorkspaceIdeUrl(link.getHref()); break; }//from w w w .j a v a2 s.c om } return workspace; }