Example usage for org.springframework.util MimeType getSubtype

List of usage examples for org.springframework.util MimeType getSubtype

Introduction

In this page you can find the example usage for org.springframework.util MimeType getSubtype.

Prototype

public String getSubtype() 

Source Link

Document

Return the subtype.

Usage

From source file:net.acesinc.convergentui.BaseFilter.java

protected String getContentType(RequestContext context) {
    String contentType = "unknown";
    MimeType type = getMimeType(context);
    if (type != null) {
        contentType = type.getType() + "/" + type.getSubtype();
    }// www . ja va 2 s. c  o m

    return contentType;
}

From source file:net.acesinc.convergentui.ConvergentUIRequestFilter.java

@Override
public Object run() {
    //First we need to build the correct URL
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest req = ctx.getRequest();

    String path = req.getRequestURI();

    String location = path.substring("/cui-req://".length());
    log.debug("RequestFilter for [ " + location + " ] in process");

    RequestContext context = RequestContext.getCurrentContext();
    ContentResponse response = contentManager.getContentFromService(location, location, false, context);

    MimeType type = response.getContentType();

    addResponseHeaders();/*  ww w .  j a  v  a  2  s. c  o m*/

    if (!response.isError()) {
        Object resp = response.getContent();
        try {

            if (String.class.isAssignableFrom(resp.getClass())) {
                writeResponse((String) resp, type);
            } else if (BufferedImage.class.isAssignableFrom(resp.getClass())) {
                writeResponse((BufferedImage) resp, response.getContentType());
            } else if (/*Map.class.isAssignableFrom(resp.getClass()) &&*/ type.getSubtype().contains("json")) {
                writeResponse(mapper.writeValueAsString(resp), type);
            } else {

                log.warn("Unknown response type [ " + response.getContentType()
                        + " ] that we can't handle yet. Content is of type: " + resp.getClass());
            }
        } catch (Exception ex) {
            log.error("Error writing response", ex);
        }
    }
    return null;

}

From source file:com.thoughtworks.go.api.ApiController.java

protected boolean isJsonContentType(Request request) {
    String mime = request.headers("Content-Type");
    if (isBlank(mime)) {
        return false;
    }/*from ww  w. j  a va2s  . c  o m*/
    try {
        MimeType mimeType = MimeType.valueOf(mime);
        return "application".equals(mimeType.getType()) && "json".equals(mimeType.getSubtype());
    } catch (InvalidMimeTypeException e) {
        return false;
    }
}

From source file:org.springframework.integration.x.bus.converter.AbstractFromMessageConverter.java

public boolean supportsTargetMimeType(MimeType mimeType) {
    for (MimeType targetMimeType : targetMimeTypes) {
        if (mimeType.getType().equals(targetMimeType.getType())
                && mimeType.getSubtype().equals(targetMimeType.getSubtype())) {
            return true;
        }/*from   w w  w  .  j  a  v a2  s .  c  o  m*/
    }
    return false;
}

From source file:org.springframework.messaging.converter.AbstractMessageConverter.java

protected boolean supportsMimeType(@Nullable MessageHeaders headers) {
    if (getSupportedMimeTypes().isEmpty()) {
        return true;
    }//from w  ww  .j a  v  a 2 s . c  o  m
    MimeType mimeType = getMimeType(headers);
    if (mimeType == null) {
        return !isStrictContentTypeMatch();
    }
    for (MimeType current : getSupportedMimeTypes()) {
        if (current.getType().equals(mimeType.getType())
                && current.getSubtype().equals(mimeType.getSubtype())) {
            return true;
        }
    }
    return false;
}

From source file:org.springframework.messaging.support.converter.AbstractMessageConverter.java

protected boolean supportsMimeType(MessageHeaders headers) {
    MimeType mimeType = getMimeType(headers);
    if (mimeType == null) {
        return true;
    }/*from w w  w. j  av  a 2  s  .c  o m*/
    if (getSupportedMimeTypes().isEmpty()) {
        return true;
    }
    for (MimeType supported : getSupportedMimeTypes()) {
        if (supported.getType().equals(mimeType.getType())
                && supported.getSubtype().equals(mimeType.getSubtype())) {
            return true;
        }
    }
    return false;
}