Java Code Examples for javax.ws.rs.core.Response.Status#CONFLICT

The following examples show how to use javax.ws.rs.core.Response.Status#CONFLICT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersistentTopicsBase.java    From pulsar with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: NamespacesBase.java    From pulsar with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 3
Source File: ApplicationSlaManagementResource.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 4
Source File: PolicyService.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: ApplicationServiceImpl.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 6
Source File: IdpServiceImpl.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 7
Source File: IdpServiceImpl.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: IdpServiceImpl.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 9
Source File: BrokerStatsBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 10
Source File: AdminResource.java    From pulsar with Apache License 2.0 5 votes vote down vote up
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.");
    }
}
 
Example 11
Source File: RoleApiResource.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
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);
}
 
Example 12
Source File: GatewayResponseTest.java    From jrestless with Apache License 2.0 4 votes vote down vote up
@Test
public void getStatusCode_StatusTypeGiven_ShouldReturnStatusCodeFromType() {
	GatewayResponse resp = new GatewayResponse(null, ImmutableMap.of(), Status.CONFLICT, false);
	assertEquals(409, resp.getStatusCode());
}
 
Example 13
Source File: ConflictExceptionMapper.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
Status getResponseStatus() {
    return Status.CONFLICT;
}
 
Example 14
Source File: CloudbreakApiExceptionMapper.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
Status getResponseStatus() {
    return Status.CONFLICT;
}
 
Example 15
Source File: IssueTypeToHttpStatusMapper.java    From FHIR with Apache License 2.0 4 votes vote down vote up
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;
    }
}
 
Example 16
Source File: CloudbreakApiExceptionMapper.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
Status getResponseStatus() {
    return Status.CONFLICT;
}
 
Example 17
Source File: DuplicatedKeyValueExceptionMapper.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
Status getResponseStatus() {
    return Status.CONFLICT;
}
 
Example 18
Source File: WebExceptions.java    From Singularity with Apache License 2.0 4 votes vote down vote up
public static WebApplicationException conflict(String message, Object... args) {
  if (args.length > 0) {
    message = format(message, args);
  }
  throw new WebApplicationException(message, Status.CONFLICT);
}
 
Example 19
Source File: AbstractMachineResource.java    From Singularity with Apache License 2.0 4 votes vote down vote up
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;
  }
}
 
Example 20
Source File: WebException.java    From development with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a builder for a conflicted request
 * 
 * @return the exception builder
 */
public static ExceptionBuilder conflict() {
    return new ExceptionBuilder(Status.CONFLICT);
}