下面列出了javax.ws.rs.core.Response.Status#NOT_ACCEPTABLE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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");
}
@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");
}
protected void initProduceProcessor() {
produceProcessor = restOperationMeta.ensureFindProduceProcessor(requestEx);
if (produceProcessor == null) {
LOGGER.error("Accept {} is not supported, operation={}.", requestEx.getHeader(HttpHeaders.ACCEPT),
restOperationMeta.getOperationMeta().getMicroserviceQualifiedName());
String msg = String.format("Accept %s is not supported", requestEx.getHeader(HttpHeaders.ACCEPT));
throw new InvocationException(Status.NOT_ACCEPTABLE, msg);
}
}
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");
}
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");
}
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");
}
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");
}
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");
}
protected void internalSetAutoTopicCreation(AsyncResponse asyncResponse, AutoTopicCreationOverride autoTopicCreationOverride) {
final int maxPartitions = pulsar().getConfig().getMaxNumPartitionsPerPartitionedTopic();
validateAdminAccessForTenant(namespaceName.getTenant());
validatePoliciesReadOnlyAccess();
if (!AutoTopicCreationOverride.isValidOverride(autoTopicCreationOverride)) {
throw new RestException(Status.PRECONDITION_FAILED, "Invalid configuration for autoTopicCreationOverride");
}
if (maxPartitions > 0 && autoTopicCreationOverride.defaultNumPartitions > maxPartitions) {
throw new RestException(Status.NOT_ACCEPTABLE, "Number of partitions should be less than or equal to " + maxPartitions);
}
// Force to read the data s.t. the watch to the cache content is setup.
policiesCache().getWithStatAsync(path(POLICIES, namespaceName.toString())).thenApply(
policies -> {
if (policies.isPresent()) {
Entry<Policies, Stat> policiesNode = policies.get();
policiesNode.getKey().autoTopicCreationOverride = autoTopicCreationOverride;
try {
// Write back the new policies into zookeeper
globalZk().setData(path(POLICIES, namespaceName.toString()),
jsonMapper().writeValueAsBytes(policiesNode.getKey()), policiesNode.getValue().getVersion(),
(rc, path1, ctx, stat) -> {
if (rc == KeeperException.Code.OK.intValue()) {
policiesCache().invalidate(path(POLICIES, namespaceName.toString()));
String autoOverride = autoTopicCreationOverride.allowAutoTopicCreation ? "enabled" : "disabled";
log.info("[{}] Successfully {} autoTopicCreation on namespace {}", clientAppId(), autoOverride, namespaceName);
asyncResponse.resume(Response.noContent().build());
} else {
String errorMsg = String.format(
"[%s] Failed to modify autoTopicCreation status for namespace %s",
clientAppId(), namespaceName);
if (rc == KeeperException.Code.NONODE.intValue()) {
log.warn("{} : does not exist", errorMsg);
asyncResponse.resume(new RestException(Status.NOT_FOUND, "Namespace does not exist"));
} else if (rc == KeeperException.Code.BADVERSION.intValue()) {
log.warn("{} : concurrent modification", errorMsg);
asyncResponse.resume(new RestException(Status.CONFLICT, "Concurrent modification"));
} else {
asyncResponse.resume(KeeperException.create(KeeperException.Code.get(rc), errorMsg));
}
}
}, null);
return null;
} catch (Exception e) {
log.error("[{}] Failed to modify autoTopicCreation status on namespace {}", clientAppId(), namespaceName, e);
asyncResponse.resume(new RestException(e));
return null;
}
} else {
asyncResponse.resume(new RestException(Status.NOT_FOUND, "Namespace " + namespaceName + " does not exist"));
return null;
}
}
).exceptionally(e -> {
log.error("[{}] Failed to modify autoTopicCreation status on namespace {}", clientAppId(), namespaceName, e);
asyncResponse.resume(new RestException(e));
return null;
});
}
@Override
Status getResponseStatus() {
return Status.NOT_ACCEPTABLE;
}
@Override
Status getResponseStatus() {
return Status.NOT_ACCEPTABLE;
}
@GET
@Path("/{deid}/es")
@Produces(MediaType.APPLICATION_JSON)
public Response getExtractionSpec(
@QueryParam("specification-format") String specificationFormat,
@QueryParam("content-model") String contentModel,
@PathParam("deid") String deid) {
Repository repository = RepositoryManager.getInstance().getRepository();
OntModel ontModel = repository.getMDRDatabase().getOntModel();
List<String> extractionSpecifications = new ArrayList<String>();
if (specificationFormat == null || contentModel == null) {
throw new WebApplicationException(Status.NOT_ACCEPTABLE);
}
File getExtractionFile = new File(QUERY_FILE_GET_EXTRACTIONS);
String queryString = "";
try {
queryString = FileUtils.readFileToString(getExtractionFile);
} catch (IOException e) {
logger.error("File with context serialization query could not be found ");
return Response.serverError().build();
}
ParameterizedSparqlString query = new ParameterizedSparqlString(
queryString);
query.setLiteral("uuid", ResourceFactory.createTypedLiteral(deid));
query.setLiteral("specFormat",
ResourceFactory.createTypedLiteral(specificationFormat));
query.setLiteral("contentModel",
ResourceFactory.createTypedLiteral(contentModel));
QueryExecution qe = QueryExecutionFactory.create(query.asQuery(),
ontModel);
String spec = "";
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
spec = qs.getLiteral("extractionSpec").getString();
if (spec != null && !spec.equals("")) {
extractionSpecifications.add(spec);
}
}
return Response.ok(extractionSpecifications).build();
}