當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。