List of usage examples for org.springframework.http MediaType TEXT_PLAIN_VALUE
String TEXT_PLAIN_VALUE
To view the source code for org.springframework.http MediaType TEXT_PLAIN_VALUE.
Click Source Link
From source file:com.orange.ngsi2.server.Ngsi2BaseController.java
@ExceptionHandler({ IllegalArgumentException.class }) public ResponseEntity<Object> illegalArgument(IllegalArgumentException exception, HttpServletRequest request) { logger.error("Illegal Argument: {}", exception.getMessage()); HttpStatus httpStatus = HttpStatus.BAD_REQUEST; if (request.getHeader("Accept").contains(MediaType.TEXT_PLAIN_VALUE)) { return new ResponseEntity<>(exception.getMessage(), httpStatus); }// ww w. j a va 2 s. c om return new ResponseEntity<>(exception.getMessage(), httpStatus); }
From source file:com.rr.wabshs.ui.surveys.surveyController.java
/** * The 'checkForDuplicateSurveys' GET request will query the system to make sure their is not a same contract number * in the system./* w w w. j a va 2s.c om*/ * * @param i * @param v * @param enteredDate * @return * @throws Exception */ @RequestMapping(value = "/checkForDuplicateSurveys", method = RequestMethod.GET, produces = { MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public String checkForDuplicateSurveys(@RequestParam Integer surveyId, @RequestParam Integer submittedSurveyId, @RequestParam Integer entityId, @RequestParam(value = "otherId", required = false) Integer otherId, @RequestParam String surveyTag, @RequestParam(value = "answerValues", required = false) List<String> answerValues) throws Exception { boolean duplicateFound = false; if ("Coordinator Hours".equals(surveyTag)) { List<String> questionTags = Arrays.asList("reportMonth", "reportYear"); duplicateFound = surveyManager.checkForDuplicateSurvey(programId, surveyId, submittedSurveyId, entityId, otherId, questionTags, "submittedsurveycoordinators", answerValues); } else if ("CPWI".equals(surveyTag)) { List<String> questionTags = Arrays.asList("reportingYear", "reportingQuarter"); duplicateFound = surveyManager.checkForDuplicateSurvey(programId, surveyId, submittedSurveyId, entityId, otherId, questionTags, "submittedsurveyprogramprofiles", answerValues); } else if ("TribalAnnualReport".equals(surveyTag)) { List<String> questionTags = Arrays.asList("reportingYear"); duplicateFound = surveyManager.checkForDuplicateSurvey(programId, surveyId, submittedSurveyId, entityId, otherId, questionTags, "", answerValues); } else if ("ActivityReporting".equals(surveyTag)) { List<String> questionTags = Arrays.asList("logName"); duplicateFound = surveyManager.checkForDuplicateSurvey(programId, surveyId, submittedSurveyId, entityId, otherId, questionTags, "submittedsurveyprogramprofiles", answerValues); } if (duplicateFound == true) { return "1"; } else { return "0"; } }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
/** * Test the response content types to ensure UTF-8. * * @throws Exception If there is a problem. *//* w ww . j a va 2 s . co m*/ @Test public void testResponseContentType() throws Exception { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final List<String> commandArgs = Lists.newArrayList("-c", "'echo hello'"); final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, Lists.newArrayList(new ClusterCriteria(Sets.newHashSet("localhost"))), Sets.newHashSet("bash")) .withCommandArgs(commandArgs).build(); final String jobId = this.getIdFromLocation(RestAssured.given(this.getRequestSpecification()) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); this.waitForDone(jobId); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/genie/logs/env.log").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/genie/logs/genie.log").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/genie/genie.done").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/stdout").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/stderr").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); // Verify the file is served as UTF-8 even if it's not RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/genie/command/" + CMD1_ID + "/config/" + GB18030_TXT).then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); }
From source file:com.netflix.genie.web.services.impl.JobDirectoryServerServiceImpl.java
private void handleRequest(final URI baseUri, final String relativePath, final HttpServletRequest request, final HttpServletResponse response, final JobDirectoryManifest manifest, final URI jobDirectoryRoot) throws IOException, ServletException { log.debug("Handle request, baseUri: '{}', relpath: '{}', jobRootUri: '{}'", baseUri, relativePath, jobDirectoryRoot);/*from ww w. ja v a 2 s. com*/ final JobDirectoryManifest.ManifestEntry entry; final Optional<JobDirectoryManifest.ManifestEntry> entryOptional = manifest.getEntry(relativePath); if (entryOptional.isPresent()) { entry = entryOptional.get(); } else { log.error("No such entry in job manifest: {}", relativePath); response.sendError(HttpStatus.NOT_FOUND.value(), "Not found: " + relativePath); return; } if (entry.isDirectory()) { // For now maintain the V3 structure // TODO: Once we determine what we want for V4 use v3/v4 flags or some way to differentiate // TODO: there's no unit test covering this section final DefaultDirectoryWriter.Directory directory = new DefaultDirectoryWriter.Directory(); final List<DefaultDirectoryWriter.Entry> files = Lists.newArrayList(); final List<DefaultDirectoryWriter.Entry> directories = Lists.newArrayList(); try { entry.getParent().ifPresent(parentPath -> { final JobDirectoryManifest.ManifestEntry parentEntry = manifest.getEntry(parentPath) .orElseThrow(IllegalArgumentException::new); directory.setParent(createEntry(parentEntry, baseUri)); }); for (final String childPath : entry.getChildren()) { final JobDirectoryManifest.ManifestEntry childEntry = manifest.getEntry(childPath) .orElseThrow(IllegalArgumentException::new); if (childEntry.isDirectory()) { directories.add(this.createEntry(childEntry, baseUri)); } else { files.add(this.createEntry(childEntry, baseUri)); } } } catch (final IllegalArgumentException iae) { log.error("Encountered unexpected problem traversing the manifest for directory entry {}", entry, iae); response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value()); return; } directories.sort(Comparator.comparing(DefaultDirectoryWriter.Entry::getName)); files.sort(Comparator.comparing(DefaultDirectoryWriter.Entry::getName)); directory.setDirectories(directories); directory.setFiles(files); final String accept = request.getHeader(HttpHeaders.ACCEPT); if (accept != null && accept.contains(MediaType.TEXT_HTML_VALUE)) { response.setContentType(MediaType.TEXT_HTML_VALUE); response.getOutputStream().write(DefaultDirectoryWriter.directoryToHTML(entry.getName(), directory) .getBytes(StandardCharsets.UTF_8)); } else { response.setContentType(MediaType.APPLICATION_JSON_VALUE); GenieObjectMapper.getMapper().writeValue(response.getOutputStream(), directory); } } else { final URI location = jobDirectoryRoot.resolve(entry.getPath()); log.debug("Get resource: {}", location); final Resource jobResource = this.resourceLoader.getResource(location.toString()); // Every file really should have a media type but if not use text/plain final String mediaType = entry.getMimeType().orElse(MediaType.TEXT_PLAIN_VALUE); final ResourceHttpRequestHandler handler = this.genieResourceHandlerFactory.get(mediaType, jobResource); handler.handleRequest(request, response); } }
From source file:com.phoenixnap.oss.ramlapisync.naming.NamingHelper.java
/** * Converts an http contentType into a qualifier that can be used within a Java method * /*from ww w .j ava2 s . com*/ * @param contentType The content type to convert application/json * @return qualifier, example V1Html */ public static String convertContentTypeToQualifier(String contentType) { //lets start off simple since qualifers are better if they are simple :) //if we have simple standard types lets add some heuristics if (contentType.equals(MediaType.APPLICATION_JSON_VALUE)) { return "AsJson"; } if (contentType.equals(MediaType.APPLICATION_OCTET_STREAM_VALUE)) { return "AsBinary"; } if (contentType.equals(MediaType.TEXT_PLAIN_VALUE) || contentType.equals(MediaType.TEXT_HTML_VALUE)) { return "AsText"; } //we have a non standard type. lets see if we have a version Matcher versionMatcher = CONTENT_TYPE_VERSION.matcher(contentType); if (versionMatcher.find()) { String version = versionMatcher.group(1); if (version != null) { return StringUtils.capitalize(version).replace(".", "_"); } } //if we got here we have some sort of funky content type. deal with it int seperatorIndex = contentType.indexOf("/"); if (seperatorIndex != -1 && seperatorIndex < contentType.length()) { String candidate = contentType.substring(seperatorIndex + 1).toLowerCase(); String out = ""; if (candidate.contains("json")) { candidate = candidate.replace("json", ""); out += "AsJson"; } candidate = StringUtils.deleteAny(candidate, " ,.+=-'\"\\|~`#$%^&\n\t"); if (StringUtils.hasText(candidate)) { out = StringUtils.capitalize(candidate) + out; } return "_" + out; } return ""; }
From source file:de.appsolve.padelcampus.controller.bookings.BookingsPayMillController.java
@RequestMapping(value = "booking/{UUID}/translate", method = GET, produces = MediaType.TEXT_PLAIN_VALUE) @ResponseBody//from w w w . jav a 2s. co m public String translate(@RequestParam("key") String key, HttpServletResponse response) throws IOException { String translation = msg.get(key); LOG.error("Error while creating PayMill payment: " + translation); return translation; }
From source file:de.appsolve.padelcampus.controller.ImagesController.java
@ResponseBody @RequestMapping(value = "upload", method = POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.TEXT_PLAIN_VALUE) public String postImage(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException, ImageProcessingException { Image image = imageUtil.saveImage(file.getContentType(), file.getBytes(), ImageCategory.cmsImage); return "/images/image/" + image.getSha256(); }
From source file:de.codecentric.boot.admin.server.web.client.InstanceWebClientTest.java
@Test public void should_add_default_logfile_accept_headers() { Instance instance = Instance.create(InstanceId.of("id")) .register(Registration.create("test", wireMock.url("/status")).build()) .withEndpoints(Endpoints.single("logfile", wireMock.url("/log"))); wireMock.stubFor(get("/log").willReturn(ok())); Mono<ClientResponse> exchange = instanceWebClient.instance(instance).get().uri("logfile").exchange(); StepVerifier.create(exchange).expectNextCount(1).verifyComplete(); wireMock.verify(1,/*from ww w.ja v a2 s . c om*/ getRequestedFor(urlEqualTo("/log")).withHeader(ACCEPT, containing(MediaType.TEXT_PLAIN_VALUE)) .withHeader(ACCEPT, containing(MediaType.ALL_VALUE))); }
From source file:dk.dma.ais.track.rest.resource.TrackResource.java
/** * Show status page.//from w w w . ja va2s . c o m * * Example URL: * - http://localhost:8080/?sourceFilter=s.country%20in%20(DK) * * @param sourceFilterExpression Source filter expression * @return */ @RequestMapping(value = "/", produces = MediaType.TEXT_PLAIN_VALUE) String home(@RequestParam(value = "sourceFilter", required = false) String sourceFilterExpression) { StringBuilder sb = new StringBuilder(); sb.append("Danish Maritime Authority - AIS Tracker\n").append("---------------------------------------\n") .append("\n").append("Tracking started: ").append(timeStarted).append('\n').append("Current time: ") .append(Instant.now()).append('\n').append("Total targets tracked: ") .append(trackService.numberOfTargets()).append('\n'); if (!isBlank(sourceFilterExpression)) sb.append("Targets matching source filter expression: ") .append(trackService.numberOfTargets(createSourceFilterPredicate(sourceFilterExpression))) .append('\n'); return sb.toString(); }