List of usage examples for org.springframework.http HttpHeaders CONTENT_TYPE
String CONTENT_TYPE
To view the source code for org.springframework.http HttpHeaders CONTENT_TYPE.
Click Source Link
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java
private void checkJobOutput(final int documentationId, final String id) throws Exception { // Check getting a directory as json final RestDocumentationResultHandler jsonResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/json/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the directory to get").optional()), // Path parameters HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT) .description(MediaType.APPLICATION_JSON_VALUE).optional()), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.APPLICATION_JSON_VALUE)), // Response Headers Snippets.OUTPUT_DIRECTORY_FIELDS); this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/output/{filePath}", id, "")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("parent", Matchers.isEmptyOrNullString())) .andExpect(MockMvcResultMatchers.jsonPath("$.directories[0].name", Matchers.is("genie/"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[0].name", Matchers.is("dep1"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[1].name", Matchers.is("jobsetupfile"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[2].name", Matchers.is("run"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[3].name", Matchers.is("stderr"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[4].name", Matchers.is("stdout"))) .andDo(jsonResultHandler);/*w w w. ja v a 2 s. c o m*/ // Check getting a directory as HTML final RestDocumentationResultHandler htmlResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/html/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the directory to get").optional()), // Path parameters HeaderDocumentation.requestHeaders( HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT).description(MediaType.TEXT_HTML)), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.TEXT_HTML)) // Response Headers ); this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/output/{filePath}", id, "") .accept(MediaType.TEXT_HTML)).andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.TEXT_HTML)) .andDo(htmlResultHandler); // Check getting a file // Check getting a directory as HTML final RestDocumentationResultHandler fileResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/file/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the file to get").optional()), // Path parameters HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT) .description(MediaType.ALL_VALUE).optional()), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description("The content type of the file being returned").optional()) // Response Headers ); // check that the generated run file is correct final String runShFileName = SystemUtils.IS_OS_LINUX ? "linux-runsh.txt" : "non-linux-runsh.txt"; final String runShFile = this.resourceLoader.getResource(BASE_DIR + runShFileName).getFile() .getAbsolutePath(); final String runFileContents = new String(Files.readAllBytes(Paths.get(runShFile)), "UTF-8"); final String jobWorkingDir = this.jobDirResource.getFile().getCanonicalPath() + FILE_DELIMITER + id; final String expectedRunScriptContent = this.getExpectedRunContents(runFileContents, jobWorkingDir, id); this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/output/{filePath}", id, "run")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string(expectedRunScriptContent)) .andDo(fileResultHandler); }
From source file:eu.europa.ec.grow.espd.ted.TedService.java
private HttpHeaders createHeaders(final String username, final String password) { String plainCreds = username + ":" + password; String base64Creds = BaseEncoding.base64().encode(plainCreds.getBytes()); HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.AUTHORIZATION, "Basic " + base64Creds); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return headers; }
From source file:io.syndesis.runtime.BaseITCase.java
private void prepareHeaders(Object body, HttpHeaders headers, String token) { if (body != null) { headers.set(HttpHeaders.CONTENT_TYPE, "application/json"); }/*from w w w.j a v a2 s .co m*/ if (token != null) { headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + token); } }
From source file:org.ambraproject.wombat.controller.ArticleController.java
/** * Returns a list of figures and tables of a given article; main usage is the figshare tile on the Metrics * tab//from ww w .ja va 2 s . c om * * @param site current site * @param articleId DOI identifying the article * @return a list of figures and tables of a given article * @throws IOException */ @RequestMapping(name = "articleFigsAndTables", value = "/article/assets/figsAndTables") public ResponseEntity<List> listArticleFiguresAndTables(@SiteParam Site site, RequestedDoiVersion articleId) throws IOException { List<Map<String, ?>> figureView = articleMetadataFactory.get(site, articleId) .validateVisibility("articleFigsAndTables").getFigureView(); HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity<>(figureView, headers, HttpStatus.OK); }
From source file:org.apache.geode.management.internal.web.controllers.ShellCommandsController.java
private ResponseEntity<InputStreamResource> getJsonResponse(String result) { HttpHeaders respHeaders = new HttpHeaders(); try {//from w w w. java 2 s . c o m InputStreamResource isr = new InputStreamResource(toInputStream(result, "UTF-8")); respHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK); } catch (Exception e) { throw new RuntimeException("IO Error writing file to output stream", e); } }
From source file:org.apache.geode.management.internal.web.controllers.ShellCommandsController.java
private ResponseEntity<InputStreamResource> getFileDownloadResponse(CommandResult commandResult) { HttpHeaders respHeaders = new HttpHeaders(); Path filePath = commandResult.getFileToDownload(); try {/*from w w w . java2s . c o m*/ InputStreamResource isr = new InputStreamResource(new FileInputStream(filePath.toFile())); respHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE); return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK); } catch (Exception e) { throw new RuntimeException("IO Error writing file to output stream", e); } finally { FileUtils.deleteQuietly(filePath.toFile()); } }
From source file:org.apache.geode.management.internal.web.controllers.ShellCommandsControllerProcessCommandTest.java
private void assertThatContentTypeEquals(ResponseEntity<InputStreamResource> response, MediaType mediaType) { assertThat(response.getHeaders().get(HttpHeaders.CONTENT_TYPE)).containsExactly(mediaType.toString()); }
From source file:org.apache.geode.management.internal.web.http.support.HttpRequesterTest.java
@Test public void extractResponseOfJsonString() throws Exception { String responseString = "my response"; requester = new HttpRequester(); response = new MockClientHttpResponse(IOUtils.toInputStream(responseString, "UTF-8"), HttpStatus.OK); response.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); Object result = requester.extractResponse(response); assertThat(result).isEqualTo(responseString); }
From source file:org.apache.geode.management.internal.web.http.support.HttpRequesterTest.java
@Test public void extractResponseOfFileDownload() throws Exception { File responseFile = temporaryFolder.newFile(); FileUtils.writeStringToFile(responseFile, "some file contents", "UTF-8"); requester = new HttpRequester(); response = new MockClientHttpResponse(new FileInputStream(responseFile), HttpStatus.OK); response.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE); Object result = requester.extractResponse(response); Path fileResult = (Path) result; assertThat(fileResult).hasSameContentAs(responseFile.toPath()); }
From source file:org.apache.servicecomb.demo.edge.business.Impl.java
@GetMapping(path = "/download") @ApiResponses({ @ApiResponse(code = 200, response = File.class, message = ""), }) public ResponseEntity<InputStream> download() throws IOException { return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=download.txt") .body(new ByteArrayInputStream("download".getBytes(StandardCharsets.UTF_8))); }