Java Code Examples for javax.ws.rs.core.MediaType#MEDIA_TYPE_WILDCARD

The following examples show how to use javax.ws.rs.core.MediaType#MEDIA_TYPE_WILDCARD . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: cxf   File: MediaTypeHeaderProvider.java    License: Apache License 2.0 5 votes vote down vote up
private static MediaType handleMediaTypeWithoutSubtype(String mType) {
    if (mType.startsWith(MediaType.MEDIA_TYPE_WILDCARD)) {
        String mTypeNext = mType.length() == 1 ? "" : mType.substring(1).trim();
        boolean mTypeNextEmpty = StringUtils.isEmpty(mTypeNext);
        if (mTypeNextEmpty || mTypeNext.startsWith(";")) {
            if (!mTypeNextEmpty) {
                Map<String, String> parameters = new LinkedHashMap<>();
                StringTokenizer st = new StringTokenizer(mType.substring(2).trim(), ";");
                while (st.hasMoreTokens()) {
                    addParameter(parameters, st.nextToken());
                }
                return new MediaType(MediaType.MEDIA_TYPE_WILDCARD,
                                     MediaType.MEDIA_TYPE_WILDCARD,
                                     parameters);
            }
            return MediaType.WILDCARD_TYPE;

        }
    }
    Message message = PhaseInterceptorChain.getCurrentMessage();
    if (message != null
        && !MessageUtils.getContextualBoolean(message, STRICT_MEDIA_TYPE_CHECK, false)) {
        MediaType mt = null;
        if (mType.equals(MediaType.TEXT_PLAIN_TYPE.getType())) {
            mt = MediaType.TEXT_PLAIN_TYPE;
        } else if (mType.equals(MediaType.APPLICATION_XML_TYPE.getSubtype())) {
            mt = MediaType.APPLICATION_XML_TYPE;
        } else {
            mt = MediaType.WILDCARD_TYPE;
        }
        LOG.fine("Converting a malformed media type '" + mType + "' to '" + typeToString(mt) + "'");
        return mt;
    }
    throw new IllegalArgumentException("Media type separator is missing");
}