Example usage for org.springframework.http MediaType TEXT_PLAIN

List of usage examples for org.springframework.http MediaType TEXT_PLAIN

Introduction

In this page you can find the example usage for org.springframework.http MediaType TEXT_PLAIN.

Prototype

MediaType TEXT_PLAIN

To view the source code for org.springframework.http MediaType TEXT_PLAIN.

Click Source Link

Document

Public constant media type for text/plain .

Usage

From source file:com.training.rest.api.MyControllerAdvice.java

@ExceptionHandler(EntityNotFoundException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public ResponseEntity<String> handleEntityNotFoundException(EntityNotFoundException ex) {
    return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.TEXT_PLAIN).body("Nope, dude!");
}

From source file:com.profiles.rest.RestExceptionHandler.java

@ExceptionHandler(value = { ConstraintViolationException.class })
public final ResponseEntity<?> handleException(ConstraintViolationException ex, WebRequest request) {
    Map<String, String> errors = BeanValidators.extractPropertyAndMessage(ex.getConstraintViolations());
    String body = jsonMapper.toJson(errors);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);
    return handleExceptionInternal(ex, body, null, HttpStatus.BAD_REQUEST, request);
}

From source file:org.intermine.app.net.request.post.CreateGenesList.java

@Override
public HttpHeaders getHeaders() {
    HttpHeaders headers = super.getHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);
    return headers;
}

From source file:nl.flotsam.calendar.web.UriHttpMessageConverter.java

public UriHttpMessageConverter() {
    super(MediaType.TEXT_PLAIN, MediaType.APPLICATION_FORM_URLENCODED);
}

From source file:org.openinfinity.sso.common.ss.sp.SpringAuthenticationMessageConverter.java

public SpringAuthenticationMessageConverter() {
    stringHttpMessageConverter = new StringHttpMessageConverter();
    setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
}

From source file:com.aspose.showcase.qrcodegen.web.api.controller.RestResponseEntityExceptionHandler.java

@ExceptionHandler(value = { BarCodeException.class })
protected ResponseEntity<Object> handleConflict(RuntimeException ex, WebRequest request) {

    String bodyOfResponse = "Internal Server Error";
    HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    String detailMessage = ex.getLocalizedMessage();

    if (detailMessage == null) {
        bodyOfResponse = "Internal Server Error";
        httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    } else if (detailMessage.contains("evaluation version")) {

        bodyOfResponse = "Please upgrade to paid license to avail this feature. \n Internal Error - "
                + ex.getMessage();/*  w w w. jav  a 2  s.  c o m*/
        httpStatus = HttpStatus.PAYMENT_REQUIRED;

    } else {
        bodyOfResponse = ex.getMessage();
        httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);

    return handleExceptionInternal(ex, bodyOfResponse, headers, httpStatus, request);
}

From source file:com.rgm.app.ViewsTest.java

@Test
public void home() throws Exception {
    // @formatter:off
    mvc.perform(get("/").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk())
    /*.andExpect(content().string("Hello World!"))*/;
    // @formatter:on
}

From source file:mars.RobotControllerTests.java

@Test
public void postRobotShouldReturnInitialPosition() throws Exception {
    this.mockMvc.perform(post("/rest/mars")).andExpect(status().isOk())
            .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN))
            .andExpect(content().string("(0, 0, N)\n"));
}

From source file:io.pivotal.xd.chaoslemur.reporter.DataDogReporterTest.java

@Test
public void sendEvent() {
    mockServer.expect(requestTo(URI)).andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("resultSuccess", MediaType.TEXT_PLAIN));

    dataDog.sendEvent("Title", "Message");

    this.mockServer.verify();
}

From source file:org.sventon.web.ctrl.ConfigurationReloadController.java

@RequestMapping(method = GET)
@ResponseBody/*from   w ww.  j  a v  a2s  .  co  m*/
public ResponseEntity<String> reloadConfigAndReinitializeApplication() {

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.TEXT_PLAIN);

    if (!application.isConfigurationReloadSupported()) {
        return new ResponseEntity<String>("Forbidden.", responseHeaders, FORBIDDEN);
    }

    try {
        application.reinit();
        return new ResponseEntity<String>("Configuration reloaded.", responseHeaders, OK);
    } catch (Exception e) {
        logger.error("Failed to reload configuration files.", e);
        return new ResponseEntity<String>("Internal error.", responseHeaders, INTERNAL_SERVER_ERROR);
    }
}