isCompatible()源码实例Demo

javax.ws.rs.core.MediaType#isCompatible()源码实例Demo

下面列出了javax.ws.rs.core.MediaType#isCompatible() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: swagger-inflector   文件: JsonExampleProvider.java
@Override
public void writeTo(Example data,
                    Class<?> type,
                    Type genericType,
                    Annotation[] annotations,
                    MediaType mediaType,
                    MultivaluedMap<String, Object> headers,
                    OutputStream out) throws IOException {
  if (mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)) {
    if (prettyPrint) {
        out.write(Json.pretty().writeValueAsString(data).getBytes("utf-8"));
    } else {
        out.write(Json.mapper().writeValueAsString(data).getBytes("utf-8"));
    }
  }
}
 
源代码2 项目: trellis   文件: HttpUtils.java
/**
 * Given a list of acceptable media types, get an RDF syntax.
 *
 * @param ioService the I/O service
 * @param acceptableTypes the types from HTTP headers
 * @param mimeType an additional "default" mimeType to match
 * @return an RDFSyntax or, in the case of binaries, null
 * @throws NotAcceptableException if no acceptable syntax is available
 */
public static RDFSyntax getSyntax(final IOService ioService, final List<MediaType> acceptableTypes,
        final String mimeType) {
    if (acceptableTypes.isEmpty()) {
        return mimeType != null ? null : TURTLE;
    }
    final MediaType mt = mimeType != null ? MediaType.valueOf(mimeType) : null;
    for (final MediaType type : acceptableTypes) {
        if (type.isCompatible(mt)) {
            return null;
        }
        final RDFSyntax syntax = ioService.supportedReadSyntaxes().stream()
            .filter(s -> MediaType.valueOf(s.mediaType()).isCompatible(type))
            .findFirst().orElse(null);
        if (syntax != null) {
            return syntax;
        }
    }
    LOGGER.debug("Valid syntax not found among {} or {}", acceptableTypes, mimeType);
    throw new NotAcceptableException();
}
 
源代码3 项目: presto   文件: PagesResponseWriter.java
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
{
    return List.class.isAssignableFrom(type) &&
            TypeToken.of(genericType).resolveType(LIST_GENERIC_TOKEN).getRawType().equals(SerializedPage.class) &&
            mediaType.isCompatible(PRESTO_PAGES_TYPE);
}
 
源代码4 项目: cxf   文件: JAXBElementProvider.java
private void addXslProcessingInstruction(Marshaller ms, MediaType mt, XSLTTransform ann)
    throws Exception {
    if (ann.type() == XSLTTransform.TransformType.CLIENT
        || ann.type() == XSLTTransform.TransformType.BOTH && ann.mediaTypes().length > 0) {
        for (String s : ann.mediaTypes()) {
            if (mt.isCompatible(JAXRSUtils.toMediaType(s))) {
                return;
            }
        }
        String absRef = resolveXMLResourceURI(ann.value());
        String xslPi = "<?xml-stylesheet type=\"text/xsl\" href=\"" + absRef + "\"?>";
        setXmlPiProperty(ms, xslPi);
    }
}
 
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
                           MediaType mediaType) {
    if (Collection.class.isAssignableFrom(type) && mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)) {
        if (genericType instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType)genericType;
            if (Arrays.asList(parameterizedType.getActualTypeArguments()).contains(IndexerDefinition.class)) {
                return true;
            }
        }
    }
    return false;
}
 
源代码6 项目: swagger-inflector   文件: PlainExampleProvider.java
@Override
public void writeTo(Example data,
                    Class<?> type,
                    Type genericType,
                    Annotation[] annotations,
                    MediaType mediaType,
                    MultivaluedMap<String, Object> headers,
                    OutputStream out) throws IOException {
    if (mediaType.isCompatible(MediaType.TEXT_PLAIN_TYPE)) {
        out.write(data.asString().getBytes("utf-8"));
    }
}
 
源代码7 项目: cxf   文件: FormEncodingProvider.java
/**
 * Retrieve map of parameters from the passed in message
 */
protected void populateMap(MultivaluedMap<String, String> params,
                           Annotation[] anns,
                           InputStream is,
                           MediaType mt,
                           boolean decode) {
    if (mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
        MultipartBody body =
            AttachmentUtils.getMultipartBody(mc, attachmentDir, attachmentThreshold, attachmentMaxSize);
        FormUtils.populateMapFromMultipart(params, body, PhaseInterceptorChain.getCurrentMessage(),
                                           decode);
    } else {
        String enc = HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name());

        Object servletRequest = mc != null ? mc.getHttpServletRequest() : null;
        if (servletRequest == null) {
            FormUtils.populateMapFromString(params,
                                            PhaseInterceptorChain.getCurrentMessage(),
                                            FormUtils.readBody(is, enc),
                                            enc,
                                            decode);
        } else {
            FormUtils.populateMapFromString(params,
                                            PhaseInterceptorChain.getCurrentMessage(),
                                            FormUtils.readBody(is, enc),
                                            enc,
                                            decode,
                                            (javax.servlet.http.HttpServletRequest)servletRequest);
        }
    }
}
 
源代码8 项目: heroic   文件: JacksonMessageBodyWriter.java
@Override
public boolean isWriteable(
    final Class<?> type, final Type genericType, final Annotation[] annotations,
    final MediaType mediaType
) {
    return mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
}
 
源代码9 项目: trellis   文件: PostHandler.java
private static RDFSyntax getRdfSyntax(final String contentType, final List<RDFSyntax> supported) {
    if (contentType != null) {
        final MediaType type = MediaType.valueOf(contentType);
        for (final RDFSyntax s : supported) {
            if (type.isCompatible(MediaType.valueOf(s.mediaType()))) {
                return s;
            }
        }
    }
    return null;
}
 
源代码10 项目: swagger-inflector   文件: JacksonProcessor.java
@Override
public boolean supports(MediaType mediaType) {
    for (MediaType item : SUPPORTED_TYPES) {
        if (item.isCompatible(mediaType) && !mediaType.isWildcardType()) {
            return true;
        }
    }
    return false;
}
 
源代码11 项目: cougar   文件: MediaTypeUtils.java
public static boolean isValid(List<MediaType> consumes, MediaType contentType) {
    for (MediaType allowed : consumes) {
        if (contentType.isCompatible(allowed)) {
            return true;
        }
    }
    return false;
}
 
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
	// TODO Auto-generated method stub
	return mediaType.isCompatible(MediaType.APPLICATION_XML_TYPE);
}
 
源代码13 项目: jax-rs-moshi   文件: MoshiMessageBodyWriter.java
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
    MediaType mediaType) {
  return mediaType.isCompatible(APPLICATION_JSON_TYPE);
}
 
源代码14 项目: jax-rs-moshi   文件: MoshiMessageBodyReader.java
@Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
    MediaType mediaType) {
  return mediaType.isCompatible(APPLICATION_JSON_TYPE);
}
 
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
}
 
源代码16 项目: sling-whiteboard   文件: JsonMessageBodyWriter.java
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
}
 
源代码17 项目: cxf   文件: JAXRSUtils.java
private static Object processRequestBodyParameter(Class<?> parameterClass,
                                                  Type parameterType,
                                                  Annotation[] parameterAnns,
                                                  Message message,
                                                  OperationResourceInfo ori)
    throws IOException, WebApplicationException {

    if (parameterClass == AsyncResponse.class) {
        return new AsyncResponseImpl(message);
    }

    String contentType = (String)message.get(Message.CONTENT_TYPE);

    if (contentType == null) {
        String defaultCt = (String)message.getContextualProperty(DEFAULT_CONTENT_TYPE);
        contentType = defaultCt == null ? MediaType.APPLICATION_OCTET_STREAM : defaultCt;
    }

    MessageContext mc = new MessageContextImpl(message);
    MediaType mt = mc.getHttpHeaders().getMediaType();

    InputStream is;
    if (mt == null || mt.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE)) {
        is = copyAndGetEntityStream(message);
    } else {
        is = message.getContent(InputStream.class);
    }

    if (is == null) {
        Reader reader = message.getContent(Reader.class);
        if (reader != null) {
            is = new ReaderInputStream(reader);
        }
    }

    return readFromMessageBody(parameterClass,
                               parameterType,
                               parameterAnns,
                               is,
                               toMediaType(contentType),
                               ori,
                               message);
}
 
源代码18 项目: cxf   文件: AttachmentUtils.java
private static void checkMediaTypes(MediaType mt1, String mt2) {
    if (!mt1.isCompatible(JAXRSUtils.toMediaType(mt2))) {
        throw ExceptionUtils.toNotSupportedException(null, null);
    }
}
 
源代码19 项目: mycore   文件: MCRPropertiesToJSONTransformer.java
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return Properties.class.isAssignableFrom(type) && mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
}
 
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {

	LOGGER.debug("Called with media type: {} and type: {}", mediaType.toString(), type);

	boolean willReturn = (mediaType.isCompatible(MediaType.TEXT_PLAIN_TYPE) || mediaType.toString().equals(ExampleMediaTypes.PLAINTEXT_0_1_0)) && type == ExamplesIterable.class;

	LOGGER.debug("Returning: {}", willReturn);

	return willReturn;
}