Example usage for org.springframework.http MediaType parseMediaType

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

Introduction

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

Prototype

public static MediaType parseMediaType(String mediaType) 

Source Link

Document

Parse the given String into a single MediaType .

Usage

From source file:be.solidx.hot.utils.AbstractHttpDataDeserializer.java

public static void main(String[] args) {
    System.out.println(MediaType.parseMediaType("application/json").getSubtype());
}

From source file:org.unitedinternet.cosmo.dav.property.ContentType.java

private static String mt(String type, String encoding) {
    final MediaType mediaType = MediaType.parseMediaType(type);
    if (StringUtils.hasText(encoding)) {
        return new MediaType(mediaType.getType(), mediaType.getSubtype(), Charset.forName(encoding)).toString();
    }//  www .jav a  2s .c o  m
    return mediaType.toString();
}

From source file:th.co.geniustree.intenship.advisor.controller.IndexController.java

@RequestMapping(value = "/teacher/{id}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getFileTeacher(@PathVariable("id") FileUpload uploadFile) {
    ResponseEntity<InputStreamResource> body = ResponseEntity.ok().contentLength(uploadFile.getContent().length)
            .contentType(MediaType.parseMediaType(uploadFile.getMimeType()))
            .header("Content-Disposition", "attachment; filename=\"" + uploadFile.getName() + "\"")
            .body(new InputStreamResource(new ByteArrayInputStream(uploadFile.getContent())));
    return body;//from  w w w.j  av  a2  s .  co m
}

From source file:rugal.sample.controller.StudentActionClientSideTest.java

@Test
//    @Ignore//from   www.j a va2s .c  om
public void test() throws Exception {
    this.mockMvc
            .perform(get("/student/1").contentType(MediaType.APPLICATION_JSON)
                    .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
            .andExpect(status().isOk());
    System.out.println("Rugal Bernstein");
}

From source file:learning.candystore.controller.CandyActionClientSideTest.java

@Test
@Ignore/*w w  w. j av a  2  s  . com*/
public void test() throws Exception {
    this.mockMvc
            .perform(get("/student/1").contentType(MediaType.APPLICATION_JSON)
                    .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
            .andExpect(status().isOk());
    System.out.println("Rugal Bernstein");
}

From source file:nd.dev.framework.basedemo.controllers.StudentActionClientSideTest.java

@Test
@Ignore//  ww  w  . j  a  v  a 2 s. c o m
public void test() throws Exception {
    this.mockMvc
            .perform(get("/student/1").contentType(MediaType.APPLICATION_JSON)
                    .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
            .andExpect(status().isOk());
    System.out.println("johnny zh");
}

From source file:am.ik.categolj3.api.entry.EntryFileDownloadController.java

@RequestMapping(path = "new")
ResponseEntity<Resource> download() {
    return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.parseMediaType("text/x-markdown"))
            .body(downloadFile);//from  w  ww. j  av  a  2  s .c  om
}

From source file:io.spring.initializr.web.mapper.InitializrMetadataVersion.java

InitializrMetadataVersion(String mediaType) {
    this.mediaType = MediaType.parseMediaType(mediaType);
}

From source file:com.trenako.web.images.validation.ImageValidator.java

@Override
public boolean isValid(MultipartFile file, ConstraintValidatorContext context) {
    // skip validation for empty files.
    if (file == null || file.isEmpty())
        return true;

    // validate file size
    if (file.getSize() > AppGlobals.MAX_UPLOAD_SIZE) {
        return false;
    }//from  ww  w .j  a v a  2  s  .  co m

    // validate content type
    MediaType contentType = MediaType.parseMediaType(file.getContentType());
    if (!AppGlobals.ALLOWED_MEDIA_TYPES.contains(contentType.toString())) {
        return false;
    }

    return true;
}

From source file:com.eu.evaluation.server.mvc.DefaultClientHttpRequestInterceptor.java

public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution execution)
        throws IOException {
    HttpRequestWrapper wrapper = new HttpRequestWrapper(httpRequest);
    wrapper.getHeaders().setAccept(acceptyTypes);

    List<Charset> chars = new ArrayList<Charset>();
    chars.add(Charset.forName("GBK"));
    wrapper.getHeaders().setAcceptCharset(chars);
    wrapper.getHeaders().setContentType(MediaType.parseMediaType("application/xml;GBK"));
    return execution.execute(httpRequest, bytes);
}