下面列出了javax.ws.rs.core.Response.Status#CONFLICT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void internalCreateNonPartitionedTopic(boolean authoritative) {
validateWriteOperationOnTopic(authoritative);
validateNonPartitionTopicName(topicName.getLocalName());
if (topicName.isGlobal()) {
validateGlobalNamespaceOwnership(namespaceName);
}
validateTopicOwnership(topicName, authoritative);
PartitionedTopicMetadata partitionMetadata = getPartitionedTopicMetadata(topicName, authoritative, false);
if (partitionMetadata.partitions > 0) {
log.warn("[{}] Partitioned topic with the same name already exists {}", clientAppId(), topicName);
throw new RestException(Status.CONFLICT, "This topic already exists");
}
try {
Topic createdTopic = getOrCreateTopic(topicName);
log.info("[{}] Successfully created non-partitioned topic {}", clientAppId(), createdTopic);
} catch (Exception e) {
log.error("[{}] Failed to create non-partitioned topic {}", clientAppId(), topicName, e);
throw new RestException(e);
}
}
/**
* It validates that peer-clusters can't coexist in replication-clusters
*
* @param clusterName:
* given cluster whose peer-clusters can't be present into replication-cluster list
* @param replicationClusters:
* replication-cluster list
*/
private void validatePeerClusterConflict(String clusterName, Set<String> replicationClusters) {
try {
ClusterData clusterData = clustersCache().get(path("clusters", clusterName)).orElseThrow(
() -> new RestException(Status.PRECONDITION_FAILED, "Invalid replication cluster " + clusterName));
Set<String> peerClusters = clusterData.getPeerClusterNames();
if (peerClusters != null && !peerClusters.isEmpty()) {
SetView<String> conflictPeerClusters = Sets.intersection(peerClusters, replicationClusters);
if (!conflictPeerClusters.isEmpty()) {
log.warn("[{}] {}'s peer cluster can't be part of replication clusters {}", clientAppId(),
clusterName, conflictPeerClusters);
throw new RestException(Status.CONFLICT,
String.format("%s's peer-clusters %s can't be part of replication-clusters %s", clusterName,
conflictPeerClusters, replicationClusters));
}
}
} catch (RestException re) {
throw re;
} catch (Exception e) {
log.warn("[{}] Failed to get cluster-data for {}", clientAppId(), clusterName, e);
}
}
@POST
@Override
public Response addApplicationSLA(ApplicationSlaRepresentation applicationSLA) {
ApplicationSLA existing = applicationSlaManagementService.getApplicationSLA(applicationSLA.getAppName());
if (existing != null) {
throw new WebApplicationException(
new IllegalStateException("Application SLA for " + applicationSLA.getAppName() + " already exist"),
Status.CONFLICT
);
}
applicationSlaManagementService.addApplicationSLA(asCoreEntity(applicationSLA)).timeout(1, TimeUnit.MINUTES).toBlocking().firstOrDefault(null);
return Response.created(URI.create(applicationSLA.getAppName())).build();
}
protected void validatePartitionedTopicMetadata(String tenant, String namespace, String encodedTopic) {
String completeTopicName = tenant + "/" + namespace + "/" + Codec.decode(encodedTopic);
try {
PartitionedTopicMetadata partitionedTopicMetadata =
pulsar().getBrokerService().fetchPartitionedTopicMetadataAsync(TopicName.get(completeTopicName)).get();
if (partitionedTopicMetadata.partitions < 1) {
throw new RestException(Status.CONFLICT, "Topic is not partitioned topic");
}
} catch ( InterruptedException | ExecutionException e) {
throw new RestException(Status.INTERNAL_SERVER_ERROR, "Check topic partition meta failed.");
}
}
protected Map<Long, Collection<ResourceUnit>> internalBrokerResourceAvailability(NamespaceName namespace) {
try {
LoadManager lm = pulsar().getLoadManager().get();
if (lm instanceof SimpleLoadManagerImpl) {
return ((SimpleLoadManagerImpl) lm).getResourceAvailabilityFor(namespace).asMap();
} else {
throw new RestException(Status.CONFLICT, lm.getClass().getName() + " does not support this operation");
}
} catch (Exception e) {
log.error("Unable to get Resource Availability", e);
throw new RestException(e);
}
}
@Override
public Response addApplicationToIdp(UriInfo ui, String realm, Application application) {
Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
for (Application idpApplication : idp.getApplications()) {
if (idpApplication.getRealm() != null && idpApplication.getRealm().equals(application.getRealm())) {
LOG.warn("Application '" + application.getRealm() + "' already added");
throw new WebApplicationException(Status.CONFLICT);
}
}
Application application2 = applicationDAO.getApplication(application.getRealm(), null);
idpDAO.addApplicationToIdp(idp, application2);
return Response.noContent().build();
}
@Override
public Response addTrustedIdpToIdp(UriInfo ui, String realm, TrustedIdp trustedIdp) {
Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
for (TrustedIdp idpTrustedIdp : idp.getTrustedIdps()) {
if (idpTrustedIdp.getRealm() != null && idpTrustedIdp.getRealm().equals(trustedIdp.getRealm())) {
LOG.warn("Trusted IDP '" + trustedIdp.getRealm() + "' already added");
throw new WebApplicationException(Status.CONFLICT);
}
}
TrustedIdp trustedIpd2 = trustedIdpDAO.getTrustedIDP(trustedIdp.getRealm());
idpDAO.addTrustedIdpToIdp(idp, trustedIpd2);
return Response.noContent().build();
}
@Override
public Response addClaimToIdp(UriInfo ui, String realm, Claim claim) {
Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));
for (Claim idpClaim : idp.getClaimTypesOffered()) {
if (idpClaim.getClaimType() != null
&& idpClaim.getClaimType().toString().equals(claim.getClaimType().toString())) {
LOG.warn("Claim '" + claim.getClaimType() + "' already added");
throw new WebApplicationException(Status.CONFLICT);
}
}
Claim claim2 = claimDAO.getClaim(claim.getClaimType().toString());
idpDAO.addClaimToIdp(idp, claim2);
return Response.noContent().build();
}
@Override
public Response addClaimToApplication(UriInfo ui, String realm, RequestClaim claim) {
Application application = applicationDAO.getApplication(realm, null);
if (application.getRequestedClaims().contains(claim)) {
LOG.warn("Claim '" + claim.getClaimType() + "' already added");
//[TODO] Status.CONFLICT correct if the relation to with Claim already exists
throw new WebApplicationException(Status.CONFLICT);
}
Claim foundClaim = claimDAO.getClaim(claim.getClaimType().toString());
RequestClaim rc = new RequestClaim(foundClaim);
application.getRequestedClaims().add(rc);
applicationDAO.addClaimToApplication(application, claim);
return Response.noContent().build();
}
public Policy create(AbstractPolicyRepresentation representation) {
PolicyStore policyStore = authorization.getStoreFactory().getPolicyStore();
Policy existing = policyStore.findByName(representation.getName(), resourceServer.getId());
if (existing != null) {
throw new ErrorResponseException("Policy with name [" + representation.getName() + "] already exists", "Conflicting policy", Status.CONFLICT);
}
return policyStore.create(representation, resourceServer);
}
private static Status issueTypeToResponseCode(IssueType.ValueSet value) {
switch (value) {
case INFORMATIONAL:
return Status.OK;
case FORBIDDEN:
case SUPPRESSED:
case SECURITY:
case THROTTLED: // Consider HTTP 429?
return Status.FORBIDDEN;
case PROCESSING:
case BUSINESS_RULE: // Consider HTTP 422?
case CODE_INVALID: // Consider HTTP 422?
case EXTENSION: // Consider HTTP 422?
case INVALID: // Consider HTTP 422?
case INVARIANT: // Consider HTTP 422?
case REQUIRED: // Consider HTTP 422?
case STRUCTURE: // Consider HTTP 422?
case VALUE: // Consider HTTP 422?
case TOO_COSTLY: // Consider HTTP 403?
case DUPLICATE: // Consider HTTP 409?
return Status.BAD_REQUEST;
case DELETED:
return Status.GONE;
case CONFLICT:
return Status.CONFLICT;
case MULTIPLE_MATCHES:
return Status.PRECONDITION_FAILED;
case EXPIRED:
case LOGIN:
case UNKNOWN:
return Status.UNAUTHORIZED;
case NOT_FOUND:
case NOT_SUPPORTED:
return Status.NOT_FOUND;
case TOO_LONG:
return Status.REQUEST_ENTITY_TOO_LARGE;
case EXCEPTION:
case LOCK_ERROR:
case NO_STORE:
case TIMEOUT:
case TRANSIENT:
case INCOMPLETE:
default:
return Status.INTERNAL_SERVER_ERROR;
}
}
@Test
public void getStatusCode_StatusTypeGiven_ShouldReturnStatusCodeFromType() {
GatewayResponse resp = new GatewayResponse(null, ImmutableMap.of(), Status.CONFLICT, false);
assertEquals(409, resp.getStatusCode());
}
private WebApplicationMessageException buildRoleConflictException(final String xoId, final String pathId) {
log.debug("XO id {} and path id {} do not match", xoId, pathId);
return new WebApplicationMessageException(Status.CONFLICT, String.format(ROLE_CONFLICT, xoId, pathId),
MediaType.APPLICATION_JSON);
}
@Override
Status getResponseStatus() {
return Status.CONFLICT;
}
@Override
Status getResponseStatus() {
return Status.CONFLICT;
}
@Override
Status getResponseStatus() {
return Status.CONFLICT;
}
@Override
Status getResponseStatus() {
return Status.CONFLICT;
}
public static WebApplicationException conflict(String message, Object... args) {
if (args.length > 0) {
message = format(message, args);
}
throw new WebApplicationException(message, Status.CONFLICT);
}
private void changeState(
String objectId,
MachineState newState,
Optional<SingularityMachineChangeRequest> changeRequest,
Optional<String> user
) {
Optional<String> message = Optional.empty();
if (changeRequest.isPresent()) {
message = changeRequest.get().getMessage();
}
StateChangeResult result = manager.changeState(objectId, newState, message, user);
switch (result) {
case FAILURE_NOT_FOUND:
throw new WebApplicationException(
String.format(
"Couldn't find an active %s with id %s (result: %s)",
getObjectTypeString(),
objectId,
result.name()
),
Status.NOT_FOUND
);
case FAILURE_ALREADY_AT_STATE:
case FAILURE_ILLEGAL_TRANSITION:
throw new WebApplicationException(
String.format(
"%s - %s %s is in %s state",
result.name(),
getObjectTypeString(),
objectId,
newState
),
Status.CONFLICT
);
default:
break;
}
}
/**
* Creates a builder for a conflicted request
*
* @return the exception builder
*/
public static ExceptionBuilder conflict() {
return new ExceptionBuilder(Status.CONFLICT);
}