Example usage for org.springframework.http MediaType valueOf

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

Introduction

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

Prototype

public static MediaType valueOf(String value) 

Source Link

Document

Parse the given String value into a MediaType object, with this method name following the 'valueOf' naming convention (as supported by org.springframework.core.convert.ConversionService .

Usage

From source file:springfox.documentation.service.MediaTypes.java

private static Function<String, MediaType> parsedMediaType() {
    return new Function<String, MediaType>() {
        @Override//from  w w  w . j a  va2 s  .  c  o  m
        public MediaType apply(String input) {
            try {
                return MediaType.valueOf(input);
            } catch (Exception e) {
                LOGGER.warn(String.format("Unable to parse media type %s", input));
                return null;
            }
        }
    };
}

From source file:com.iflytek.edu.cloud.frame.error.support.ErrorRequestMessageConverter.java

/**
 * ??format?// w  w w .ja v a 2 s  . co  m
 * 
 * @param httpServletResponse
 * @param format
 * @param mainError
 * @throws IOException
 */
public void convertData(HttpServletRequest request, HttpServletResponse httpServletResponse,
        MainError mainError) throws IOException {
    final String format = (String) request.getAttribute(Constants.SYS_PARAM_KEY_FORMAT);

    if (Constants.DATA_FORMAT_JSON.equals(format)) {
        jsonMessageConverter.write(mainError, MediaType.valueOf("application/json;charset=UTF-8"),
                new ServletServerHttpResponse(httpServletResponse));
    } else {
        xmlMessageConverter.write(mainError, MediaType.valueOf("application/xml;charset=UTF-8"),
                new ServletServerHttpResponse(httpServletResponse));
    }
}

From source file:com.ucrisko.libroomreserve.config.WebAppConfig.java

@Bean
public MappingJackson2HttpMessageConverter jsonConverter() {
    MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
    jacksonConverter.setSupportedMediaTypes(Arrays.asList(MediaType.valueOf("application/json")));
    jacksonConverter.setObjectMapper(jacksonObjectMapper());
    return jacksonConverter;
}

From source file:io.spring.initializr.stub.ClientApplicationTests.java

@Test
public void testCurrentMetadata() {
    RequestEntity<Void> request = RequestEntity.get(createUri("/"))
            .accept(MediaType.valueOf("application/vnd.initializr.v2.1+json")).build();

    ResponseEntity<String> response = this.restTemplate.exchange(request, String.class);
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    // other assertions here
}

From source file:com.digitalriver.artifact.NickArtifactServerTests.java

public void testCss() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
    assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(), MediaType.valueOf("text/css"),
            entity.getHeaders().getContentType());
}

From source file:SampleWebStaticApplicationTests.java

@Test
public void testCss() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).contains("body");
    assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.valueOf("text/css"));
}

From source file:business.services.PaNumberService.java

public HttpEntity<InputStreamResource> writePaNumbers(List<PathologyItem> items, Integer labNumber,
        String labRequestCode) throws Exception {

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(out, PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING);
    CSVWriter csvwriter = new CSVWriter(writer, ';', '"');

    csvwriter.writeNext(FILE_HEADER);/* w ww. ja  v  a2 s.  c  om*/

    for (PathologyItem item : items) {
        log.info(item.getPaNumber());
        String[] toppings = { labNumber.toString(), item.getPaNumber(), "", "" };
        csvwriter.writeNext(toppings);
    }

    String filename = "panumbers_" + labRequestCode + ".csv";

    try {
        csvwriter.flush();
        writer.flush();
        out.flush();
        InputStream in = new ByteArrayInputStream(out.toByteArray());
        csvwriter.close();
        writer.close();
        out.close();
        InputStreamResource resource = new InputStreamResource(in);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf("text/csv;charset=" + PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING));
        headers.set("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers);
        return response;
    } catch (IOException e) {
        throw new Exception(e);
    }
}

From source file:sample.webstatic.SampleWebStaticApplicationTests.java

@Test
public void testCss() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
    assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(),
            MediaType.valueOf("text/css;charset=UTF-8"), entity.getHeaders().getContentType());
}

From source file:info.rajesh.ui.SampleWebStaticApplicationTests.java

@Test
public void testCss() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
    assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(), MediaType.valueOf("text/css"),
            entity.getHeaders().getContentType());
}

From source file:comsat.sample.ui.SampleWebStaticApplicationTests.java

@Test
public void testCss() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/webjars/bootstrap/3.3.5/css/bootstrap.min.css", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
    assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(),
            MediaType.valueOf("text/css;charset=UTF-8"), entity.getHeaders().getContentType());
}