当前位置: 首页>>代码示例>>Java>>正文


Java MediaType.isCompatible方法代码示例

本文整理汇总了Java中javax.ws.rs.core.MediaType.isCompatible方法的典型用法代码示例。如果您正苦于以下问题:Java MediaType.isCompatible方法的具体用法?Java MediaType.isCompatible怎么用?Java MediaType.isCompatible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.core.MediaType的用法示例。


在下文中一共展示了MediaType.isCompatible方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: filter

import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
    if (!requestContext.getMethod().equals("POST")) {
        return;
    }

    final MinijaxRequestContext ctx = (MinijaxRequestContext) requestContext;
    final Security<?> security = ctx.get(Security.class);
    if (!security.isLoggedIn() || security.getAuthenticationScheme() != SecurityContext.FORM_AUTH) {
        return;
    }

    final MediaType contentType = ctx.getMediaType();
    if (contentType == null) {
        return;
    }

    if (!contentType.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE) &&
            !contentType.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
        return;
    }

    security.validateSession(ctx.getForm().getString("csrf"));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:25,代码来源:CsrfFilter.java

示例2: readForm

import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
private void readForm() {
    final MediaType contentType = getMediaType();

    if (contentType == null) {
        return;
    }

    try {
        if (contentType.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE)) {
            form = new MinijaxUrlEncodedForm(IOUtils.toString(getEntityStream(), StandardCharsets.UTF_8));
        } else if (contentType.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
            form = new MinijaxMultipartForm(request.getParts());
        } else {
            throw new BadRequestException("Unsupported content type (" + contentType + ")");
        }

    } catch (final IOException | ServletException ex) {
        throw new WebApplicationException(ex.getMessage(), ex);
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:21,代码来源:MinijaxRequestContext.java

示例3: isReadable

import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override
public boolean isReadable ( final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType )
{
    logger.trace ( "isReadable - mediaType: {}", mediaType );

    for ( final MediaType mt : SUPPORTED_TYPES_ARRAY )
    {
        if ( mt.isCompatible ( mediaType ) )
        {
            return true;
        }
    }
    return false;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:VariantProvider.java

示例4: toResponse

import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override
public Response toResponse(final Throwable exception) {

    log(exception);
    int status = Status.INTERNAL_SERVER_ERROR.getStatusCode();
    if (exception instanceof WebApplicationException) {
        final WebApplicationException internalException = (WebApplicationException) exception;
        if (internalException.getResponse().hasEntity()) {
            return internalException.getResponse();
        } else {
            status = internalException.getResponse().getStatus();
        }
    }
    final MediaType mediaType = getAppropriateMediaType();

    if (mediaType.isCompatible(MediaType.TEXT_PLAIN_TYPE) || mediaType.isCompatible(MediaType.TEXT_HTML_TYPE)) {
        return Response.status(status)
            .entity(exception.getMessage())
            .type(mediaType)
            .build();
    } else {
        return Response.status(status)
            .entity(new ErrorResponse(exception, uriInfo, showStackTrace))
            .type(mediaType)
            .build();
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:28,代码来源:JsonExceptionMapper.java

示例5: isWriteable

import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override
public boolean isWriteable(
        final Class<?> type,
        final Type genericType,
        final Annotation[] annotations,
        final MediaType mediaType) {

    return mediaType != null && mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:MinijaxJsonWriter.java

示例6: isReadable

import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override
public boolean isReadable(
        final Class<?> type,
        final Type genericType,
        final Annotation[] annotations,
        final MediaType mediaType) {

    return mediaType != null && mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:MinijaxJsonReader.java

示例7: isWriteable

import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
    MediaType mediaType) {
  return mediaType.isCompatible(APPLICATION_JSON_TYPE);
}
 
开发者ID:JakeWharton,项目名称:jax-rs-moshi,代码行数:5,代码来源:MoshiMessageBodyWriter.java

示例8: isReadable

import javax.ws.rs.core.MediaType; //导入方法依赖的package包/类
@Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
    MediaType mediaType) {
  return mediaType.isCompatible(APPLICATION_JSON_TYPE);
}
 
开发者ID:JakeWharton,项目名称:jax-rs-moshi,代码行数:5,代码来源:MoshiMessageBodyReader.java


注:本文中的javax.ws.rs.core.MediaType.isCompatible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。