本文整理汇总了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"));
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}