Java Code Examples for org.springframework.http.MediaType#TEXT_PLAIN_VALUE

The following examples show how to use org.springframework.http.MediaType#TEXT_PLAIN_VALUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MonitoringController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@RequestMapping(path = "/setSubmissionDeadline", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE)
   @ResponseBody
   public String setSubmissionDeadline(HttpServletRequest request) {
Long contentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID);
VoteContent voteContent = voteService.getVoteContent(contentID);

Long dateParameter = WebUtil.readLongParam(request, VoteAppConstants.ATTR_SUBMISSION_DEADLINE, true);
Date tzSubmissionDeadline = null;
String formattedDate = "";
if (dateParameter != null) {
    Date submissionDeadline = new Date(dateParameter);
    HttpSession ss = SessionManager.getSession();
    org.lamsfoundation.lams.usermanagement.dto.UserDTO teacher = (org.lamsfoundation.lams.usermanagement.dto.UserDTO) ss
	    .getAttribute(AttributeNames.USER);
    TimeZone teacherTimeZone = teacher.getTimeZone();
    tzSubmissionDeadline = DateUtil.convertFromTimeZoneToDefault(teacherTimeZone, submissionDeadline);
    formattedDate = DateUtil.convertToStringForJSON(tzSubmissionDeadline, request.getLocale());
}
voteContent.setSubmissionDeadline(tzSubmissionDeadline);
voteService.updateVote(voteContent);

return formattedDate;
   }
 
Example 2
Source File: MonitoringController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Set Submission Deadline
    */
   @RequestMapping(path = "/setSubmissionDeadline", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE)
   @ResponseBody
   public String setSubmissionDeadline(HttpServletRequest request) {
Long contentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID);
QaContent content = qaService.getQaContent(contentID);

Long dateParameter = WebUtil.readLongParam(request, QaAppConstants.ATTR_SUBMISSION_DEADLINE, true);
Date tzSubmissionDeadline = null;
String formattedDate = "";
if (dateParameter != null) {
    Date submissionDeadline = new Date(dateParameter);
    HttpSession ss = SessionManager.getSession();
    UserDTO teacher = (UserDTO) ss.getAttribute(AttributeNames.USER);
    TimeZone teacherTimeZone = teacher.getTimeZone();
    tzSubmissionDeadline = DateUtil.convertFromTimeZoneToDefault(teacherTimeZone, submissionDeadline);
    formattedDate = DateUtil.convertToStringForJSON(tzSubmissionDeadline, request.getLocale());
} else {
    //set showOtherAnswersAfterDeadline to false
    content.setShowOtherAnswersAfterDeadline(false);
}
content.setSubmissionDeadline(tzSubmissionDeadline);
qaService.saveOrUpdateQaContent(content);

return formattedDate;
   }
 
Example 3
Source File: AccountResource.java    From OpenIoE with Apache License 2.0 6 votes vote down vote up
/**
 * POST   /account/reset_password/init : Send an e-mail to reset the password of the user
 *
 * @param mail the mail of the user
 * @param request the HTTP request
 * @return the ResponseEntity with status 200 (OK) if the e-mail was sent, or status 400 (Bad Request) if the e-mail address is not registred
 */
@RequestMapping(value = "/account/reset_password/init",
    method = RequestMethod.POST,
    produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity<?> requestPasswordReset(@RequestBody String mail, HttpServletRequest request) {
    return userService.requestPasswordReset(mail)
        .map(user -> {
            String baseUrl = request.getScheme() +
                "://" +
                request.getServerName() +
                ":" +
                request.getServerPort() +
                request.getContextPath();
            mailService.sendPasswordResetMail(user, baseUrl);
            return new ResponseEntity<>("e-mail was sent", HttpStatus.OK);
        }).orElse(new ResponseEntity<>("e-mail address not registered", HttpStatus.BAD_REQUEST));
}
 
Example 4
Source File: SshResource.java    From jhipster-microservices-example with Apache License 2.0 5 votes vote down vote up
/**
 * GET  / : get the SSH public key
 */
@GetMapping(value = "/ssh/public_key", produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity<String> eureka() {
    try {
        String publicKey = getPublicKey();
        if(publicKey != null) return new ResponseEntity<>(publicKey, HttpStatus.OK);
    } catch (IOException e) {
        log.warn("SSH public key could not be loaded: {}", e.getMessage());
    }
    return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
 
Example 5
Source File: FilesController.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
@ApiOperation("Get a valued template file")
@GetMapping(produces = MediaType.TEXT_PLAIN_VALUE + ";charset=UTF-8", path =
        "applications/{application_name}/platforms/{platform_name}/{module_path}/{module_name}/{module_version}/instances/{instance_name}/files/{template_name}")
public ResponseEntity<String> getFile(Authentication authentication,
                                      @PathVariable("application_name") final String applicationName,
                                      @PathVariable("platform_name") final String platformName,
                                      @PathVariable("module_path") final String modulePath,
                                      @PathVariable("module_name") final String moduleName,
                                      @PathVariable("module_version") final String moduleVersion,
                                      @PathVariable("instance_name") final String instanceName,
                                      @PathVariable("template_name") final String templateName,
                                      @RequestParam("isWorkingCopy") final Boolean isWorkingCopy,
                                      @RequestParam("template_namespace") final String templateNamespace,
                                      @RequestParam(value = "simulate", required = false) final Boolean simulate) {

    String fileContent = filesUseCases.getFile(
            applicationName,
            platformName,
            modulePath,
            moduleName,
            moduleVersion,
            instanceName,
            templateName,
            Boolean.TRUE.equals(isWorkingCopy),
            templateNamespace,
            Boolean.TRUE.equals(simulate),
            new User(authentication));

    return ResponseEntity.ok(fileContent);
}
 
Example 6
Source File: AccountResource.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * POST   /account/reset_password/init : Send an e-mail to reset the password of the user
 *
 * @param mail the mail of the user
 * @return the ResponseEntity with status 200 (OK) if the e-mail was sent, or status 400 (Bad Request) if the e-mail address is not registered
 */
@PostMapping(path = "/account/reset_password/init",
    produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity requestPasswordReset(@RequestBody String mail) {
    return userService.requestPasswordReset(mail)
        .map(user -> {
            mailService.sendPasswordResetMail(user);
            return new ResponseEntity<>("e-mail was sent", HttpStatus.OK);
        }).orElse(new ResponseEntity<>("e-mail address not registered", HttpStatus.BAD_REQUEST));
}
 
Example 7
Source File: SshResource.java    From jhipster-registry with Apache License 2.0 5 votes vote down vote up
/**
 * GET  / : get the SSH public key
 */
@GetMapping(value = "/ssh/public_key", produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> getSshPublicKey() {
    try {
        String publicKey = getPublicKey();
        if(publicKey != null) return new ResponseEntity<>(publicKey, HttpStatus.OK);
    } catch (IOException e) {
        log.warn("SSH public key could not be loaded: {}", e.getMessage());
    }
    return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
 
Example 8
Source File: AccountResource.java    From jhipster-microservices-example with Apache License 2.0 5 votes vote down vote up
/**
 * POST   /account/reset_password/init : Send an email to reset the password of the user
 *
 * @param mail the mail of the user
 * @return the ResponseEntity with status 200 (OK) if the email was sent, or status 400 (Bad Request) if the email address is not registered
 */
@PostMapping(path = "/account/reset_password/init",
    produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity requestPasswordReset(@RequestBody String mail) {
    return userService.requestPasswordReset(mail)
        .map(user -> {
            mailService.sendPasswordResetMail(user);
            return new ResponseEntity<>("email was sent", HttpStatus.OK);
        }).orElse(new ResponseEntity<>("email address not registered", HttpStatus.BAD_REQUEST));
}
 
Example 9
Source File: CodeFirstSpringmvc.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@DeleteMapping(path = "/addstring", produces = MediaType.TEXT_PLAIN_VALUE)
public String addString(@RequestParam(name = "s") List<String> s) {
  String result = "";
  for (String x : s) {
    result += x;
  }
  return result;
}
 
Example 10
Source File: MultipartControllerTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldSubmitWithPutAndReturnString() {
    MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE, "Hello, World!".getBytes());
    UploadFileResponse uploadFileResponse = multipartController.uploadFileWithPut(file);

    assertEquals("hello.txt", uploadFileResponse.getFileName());
    assertEquals("text/plain", uploadFileResponse.getFileType());
    assertEquals(13, uploadFileResponse.getSize());
}
 
Example 11
Source File: AccountResource.java    From jhipster-microservices-example with Apache License 2.0 5 votes vote down vote up
/**
 * POST   /account/reset_password/finish : Finish to reset the password of the user
 *
 * @param keyAndPassword the generated key and the new password
 * @return the ResponseEntity with status 200 (OK) if the password has been reset,
 * or status 400 (Bad Request) or 500 (Internal Server Error) if the password could not be reset
 */
@PostMapping(path = "/account/reset_password/finish",
    produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity<String> finishPasswordReset(@RequestBody KeyAndPasswordVM keyAndPassword) {
    if (!checkPasswordLength(keyAndPassword.getNewPassword())) {
        return new ResponseEntity<>("Incorrect password", HttpStatus.BAD_REQUEST);
    }
    return userService.completePasswordReset(keyAndPassword.getNewPassword(), keyAndPassword.getKey())
          .map(user -> new ResponseEntity<String>(HttpStatus.OK))
          .orElse(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR));
}
 
Example 12
Source File: AccountResource.java    From flair-engine with Apache License 2.0 5 votes vote down vote up
/**
 * POST   /account/reset_password/finish : Finish to reset the password of the user
 *
 * @param keyAndPassword the generated key and the new password
 * @return the ResponseEntity with status 200 (OK) if the password has been reset,
 * or status 400 (Bad Request) or 500 (Internal Server Error) if the password could not be reset
 */
@PostMapping(path = "/account/reset_password/finish",
    produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity<String> finishPasswordReset(@RequestBody KeyAndPasswordVM keyAndPassword) {
    if (!checkPasswordLength(keyAndPassword.getNewPassword())) {
        return new ResponseEntity<>(CHECK_ERROR_MESSAGE, HttpStatus.BAD_REQUEST);
    }
    return userService.completePasswordReset(keyAndPassword.getNewPassword(), keyAndPassword.getKey())
          .map(user -> new ResponseEntity<String>(HttpStatus.OK))
          .orElse(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR));
}
 
Example 13
Source File: ValidFeignClientTests.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, path = "/multipart",
		consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
		produces = MediaType.TEXT_PLAIN_VALUE)
String multipart(@RequestPart("hello") String hello,
		@RequestPart("world") String world,
		@RequestPart("file") MultipartFile file);
 
Example 14
Source File: ValidFeignClientTests.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, path = "/singlePart",
		consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
		produces = MediaType.TEXT_PLAIN_VALUE)
String singlePart(@RequestPart("hello") String hello) {
	return hello;
}
 
Example 15
Source File: EnglishGreetingRestEndpoint.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@RequestMapping(path = "", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
@Override
public String home() {
  return super.home();
}
 
Example 16
Source File: CodeFirstSpringmvc.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@PostMapping(path = "/upload", produces = MediaType.TEXT_PLAIN_VALUE)
public String fileUpload(@RequestPart(name = "file1") MultipartFile file1,
    @RequestPart(name = "someFile") Part file2) {
  return _fileUpload(file1, file2);
}
 
Example 17
Source File: HelloWorldController.java    From mutual-tls-ssl with Apache License 2.0 4 votes vote down vote up
@LogClientType
@LogCertificate(detailed = true)
@GetMapping(value = "/api/hello", produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> hello() {
    return ResponseEntity.ok("Hello");
}
 
Example 18
Source File: ValidFeignClientTests.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, path = "/multipartFilenames",
		consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
		produces = MediaType.TEXT_PLAIN_VALUE)
String requestPartListOfMultipartFilesReturnsFileNames(
		@RequestPart("files") List<MultipartFile> files);
 
Example 19
Source File: GlobalCorsConfigIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@GetMapping(value = "/ambiguous", produces = MediaType.TEXT_PLAIN_VALUE)
public String ambiguous1() {
	return "ambiguous";
}
 
Example 20
Source File: TestController.java    From logback-access-spring-boot-starter with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the text.
 *
 * @return the text.
 */
@GetMapping(value = "/text", produces = MediaType.TEXT_PLAIN_VALUE)
public String getText() {
    return "TEST-TEXT";
}