本文整理了Java中javax.ws.rs.core.Request.selectVariant
方法的一些代码示例,展示了Request.selectVariant
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.selectVariant
方法的具体详情如下:
包路径:javax.ws.rs.core.Request
类名称:Request
方法名:selectVariant
[英]Select the representation variant that best matches the request. Returns null in case there is no matching variant in the list.
More explicit variants are chosen ahead of less explicit ones. A vary header is computed from the supplied list and automatically added to the response.
[中]选择与请求最匹配的表示变量。如果列表中没有匹配的变量,则返回null。
在不太明确的变体之前,选择更明确的变体。根据提供的列表计算vary头,并自动添加到响应中。
代码示例来源:origin: jersey/jersey
@GET
public Response content() {
if (content.isEmpty()) {
return Response.noContent().build();
}
final Variant variant = request.selectVariant(supportedVariants);
if (variant == null) {
return Response.notAcceptable(supportedVariants).build();
} else {
return Response.ok(content, variant.getMediaType()).build();
}
}
代码示例来源:origin: jersey/jersey
MediaType.APPLICATION_XML_TYPE,
MediaType.APPLICATION_JSON_TYPE).build();
final Variant variant = request.get().selectVariant(variants);
if (variant != null) {
response.type(variant.getMediaType());
代码示例来源:origin: com.sun.jersey/jersey-server
Variant v = request.selectVariant(vl);
if (v==null) {
return Response.notAcceptable(vl).build();
代码示例来源:origin: apache/incubator-pinot
@GET
@Produces({"application/hocon", "text/x-java-properties", "text/plain"})
@Path("/v2/tables/{tableName}")
@ApiOperation("Displays the configuration of a table")
public Response readTableConfiguration(@PathParam("tableName") String tableName, @Context Request request) {
TableConfig offlineTableConfig =
_resourceManager.getTableConfig(tableName, CommonConstants.Helix.TableType.OFFLINE);
TableConfig realtimeTableConfig =
_resourceManager.getTableConfig(tableName, CommonConstants.Helix.TableType.REALTIME);
Schema tableSchema = _resourceManager.getTableSchema(tableName);
if (offlineTableConfig == null && realtimeTableConfig == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
CombinedConfig combinedConfig = new CombinedConfig(offlineTableConfig, realtimeTableConfig, tableSchema);
String serializedConfig;
List<Variant> variants =
Variant.mediaTypes(APPLICATION_HOCON, TEXT_JAVA_PROPERTIES, MediaType.TEXT_PLAIN_TYPE).build();
Variant variant = request.selectVariant(variants);
if (variant == null) {
return Response.notAcceptable(variants).build();
} else if (APPLICATION_HOCON.equals(variant.getMediaType()) || MediaType.TEXT_PLAIN_TYPE
.equals(variant.getMediaType())) {
serializedConfig = Serializer.serializeToString(combinedConfig);
} else if (TEXT_JAVA_PROPERTIES.equals(variant.getMediaType())) {
serializedConfig = Serializer.serializeToPropertiesString(combinedConfig);
} else {
return Response.notAcceptable(variants).build();
}
return Response.ok(serializedConfig, variant).header("Content-Disposition", "inline").build();
}
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
public static MediaType variantFor(Request request) {
Variant v = request.selectVariant(POSSIBLE_VARIANTS);
if (v == null) {
v = POSSIBLE_VARIANTS.get(0);
}
return v.getMediaType();
}
}
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
public static MediaType variantFor(Request request) {
Variant v = request.selectVariant(POSSIBLE_VARIANTS);
if (v == null) {
v = POSSIBLE_VARIANTS.get(0);
}
/* If we include the charset in the variant then it gets prioritised as a default. Select
* it as text/plain and then switch in the variant with the charset here.
*/
MediaType t = v.getMediaType();
if (t.equals(MediaType.TEXT_PLAIN_TYPE)) {
return TEXT_PLAIN_UTF8_TYPE;
} else {
return t;
}
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Response getTaskCountByCandidateGroupReport(Request request) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
MediaType mediaType = variant.getMediaType();
if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
List<TaskCountByCandidateGroupResultDto> result = getTaskCountByCandidateGroupResultAsJson();
return Response.ok(result, mediaType).build();
}
else if (APPLICATION_CSV_TYPE.equals(mediaType) || TEXT_CSV_TYPE.equals(mediaType)) {
String csv = getReportResultAsCsv();
return Response
.ok(csv, mediaType)
.header("Content-Disposition", "attachment; filename=task-count-by-candidate-group.csv")
.build();
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Override
public Response getHistoricProcessInstancesReport(UriInfo uriInfo, Request request) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
MediaType mediaType = variant.getMediaType();
if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
List<ReportResultDto> result = getReportResultAsJson(uriInfo);
return Response.ok(result, mediaType).build();
}
else if (APPLICATION_CSV_TYPE.equals(mediaType) || TEXT_CSV_TYPE.equals(mediaType)) {
String csv = getReportResultAsCsv(uriInfo);
return Response
.ok(csv, mediaType)
.header("Content-Disposition", "attachment; filename=process-instance-report.csv")
.build();
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object queryList(Request request, String extendingQuery, Integer firstResult, Integer maxResults) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return queryJsonList(extendingQuery, firstResult ,maxResults);
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return queryHalList(extendingQuery, firstResult, maxResults);
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object getTasks(Request request, UriInfo uriInfo, Integer firstResult, Integer maxResults) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return getJsonTasks(uriInfo, firstResult, maxResults);
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return getHalTasks(uriInfo, firstResult, maxResults);
}
}
throw new InvalidRequestException(Response.Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object queryList(Request request, String extendingQuery, Integer firstResult, Integer maxResults) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return queryJsonList(extendingQuery, firstResult ,maxResults);
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return queryHalList(extendingQuery, firstResult, maxResults);
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object executeSingleResult(Request request) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return executeJsonSingleResult();
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return executeHalSingleResult();
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object getTasks(Request request, UriInfo uriInfo, Integer firstResult, Integer maxResults) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return getJsonTasks(uriInfo, firstResult, maxResults);
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return getHalTasks(uriInfo, firstResult, maxResults);
}
}
throw new InvalidRequestException(Response.Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object getTask(Request request) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return getJsonTask();
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return getHalTask();
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object executeSingleResult(Request request) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return executeJsonSingleResult();
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return executeHalSingleResult();
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object querySingleResult(Request request, String extendingQuery) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return queryJsonSingleResult(extendingQuery);
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return queryHalSingleResult(extendingQuery);
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object executeList(Request request, Integer firstResult, Integer maxResults) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return executeJsonList(firstResult, maxResults);
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return executeHalList(firstResult, maxResults);
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object querySingleResult(Request request, String extendingQuery) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return queryJsonSingleResult(extendingQuery);
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return queryHalSingleResult(extendingQuery);
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object executeList(Request request, Integer firstResult, Integer maxResults) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return executeJsonList(firstResult, maxResults);
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return executeHalList(firstResult, maxResults);
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Object getTask(Request request) {
Variant variant = request.selectVariant(VARIANTS);
if (variant != null) {
if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) {
return getJsonTask();
}
else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) {
return getHalTask();
}
}
throw new InvalidRequestException(Status.NOT_ACCEPTABLE, "No acceptable content-type found");
}
内容来源于网络,如有侵权,请联系作者删除!