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

The following examples show how to use javax.ws.rs.core.Response.Status#NOT_FOUND . 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
private RestException topicNotFoundReason(TopicName topicName) {
    if (!topicName.isPartitioned()) {
        return new RestException(Status.NOT_FOUND, "Topic not found");
    }

    PartitionedTopicMetadata partitionedTopicMetadata = getPartitionedTopicMetadata(
            TopicName.get(topicName.getPartitionedTopicName()), false, false);
    if (partitionedTopicMetadata == null || partitionedTopicMetadata.partitions == 0) {
        final String topicErrorType = partitionedTopicMetadata == null ?
                "has no metadata" : "has zero partitions";
        return new RestException(Status.NOT_FOUND, String.format(
                "Partitioned Topic not found: %s %s", topicName.toString(), topicErrorType));
    } else if (!internalGetList().contains(topicName.toString())) {
        return new RestException(Status.NOT_FOUND, "Topic partitions were not yet created");
    }
    return new RestException(Status.NOT_FOUND, "Partitioned Topic not found");
}
 
Example 2
Source File: IdpServiceImpl.java    From cxf-fediz with Apache License 2.0 6 votes vote down vote up
@Override
public Response removeClaimFromIdp(UriInfo ui, String realm, String claimType) {
    Idp idp = idpDAO.getIdp(realm, Arrays.asList("all"));

    Claim foundItem = null;
    for (Claim item : idp.getClaimTypesOffered()) {
        if (item.getClaimType().toString().equals(claimType)) {
            foundItem = item;
            break;
        }
    }
    if (foundItem == null) {
        LOG.warn("Claim '" + claimType + "' not found");
        throw new WebApplicationException(Status.NOT_FOUND);
    }
    idpDAO.removeClaimFromIdp(idp, foundItem);

    return Response.noContent().build();
}
 
Example 3
Source File: AlbResource.java    From Baragon with Apache License 2.0 6 votes vote down vote up
@POST
@Path("/load-balancers/{elbName}/listeners")
public Listener createListeners(@PathParam("elbName") String elbName,
                                @Valid CreateListenerRequest createListenerRequest) {
  if (config.isPresent()) {
      Optional<LoadBalancer> maybeLoadBalancer = applicationLoadBalancer
          .getLoadBalancer(elbName);
      if (maybeLoadBalancer.isPresent()) {
        return applicationLoadBalancer
            .createListener(createListenerRequest
                .withLoadBalancerArn(maybeLoadBalancer.get().getLoadBalancerArn()));
      } else {
        throw new WebApplicationException(String.format("Could not find an elb with name %s", elbName), Status.NOT_FOUND);
      }
  } else {
    throw new BaragonWebException("ElbSync and related actions are not currently enabled");
  }
}
 
Example 4
Source File: MetaServerResource.java    From hermes with Apache License 2.0 6 votes vote down vote up
@GET
@Path("servers")
public List<String> getServers(@QueryParam("clientTimeMillis") @DefaultValue("0") long clientTimeMillis, //
      @Context HttpServletResponse res) {
	Meta meta = m_metaHolder.getMeta();
	if (meta == null) {
		throw new RestException("Meta not found", Status.NOT_FOUND);
	}

	if (clientTimeMillis > 0) {
		long diff = clientTimeMillis - System.currentTimeMillis();
		if (Math.abs(diff) > m_coreConfig.getMaxClientTimeDiffMillis()) {
			res.addHeader(CoreConfig.TIME_UNSYNC_HEADER, Long.toString(diff));
		}
	}

	Collection<Server> servers = meta.getServers().values();
	List<String> result = new ArrayList<>();
	for (Server server : servers) {
		result.add(String.format("%s:%s", server.getHost(), server.getPort()));
	}

	return result;
}
 
Example 5
Source File: ItemResourceImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Response readAllCsv ( final String contextId )
{
    final DataContext context = this.provider.getContext ( contextId );

    if ( context == null )
    {
        logger.trace ( "Context '{}' not found", contextId ); //$NON-NLS-1$
        throw new WebApplicationException ( Status.NOT_FOUND );
    }

    final SortedMap<String, DataItemValue> values = context.getAllValues ();

    final StreamingOutput out = new StreamingOutput () {

        @Override
        public void write ( final OutputStream output ) throws IOException, WebApplicationException
        {
            streamAsCSV ( new PrintWriter ( new OutputStreamWriter ( output, StandardCharsets.UTF_8 ) ), values, ",", "\r\n" ); //$NON-NLS-1$  //$NON-NLS-2$
        }
    };
    return Response.ok ( out ).header ( "Content-Disposition", "attachment; filename=\"data.csv\"" ).build (); //$NON-NLS-1$
}
 
Example 6
Source File: TodoResource.java    From quarkus-deep-dive with Apache License 2.0 5 votes vote down vote up
@DELETE
@Transactional
@Path("/{id}")
public Response deleteOne(@PathParam("id") Long id) {
    Todo entity = Todo.findById(id);
    if (entity == null) {
        throw new WebApplicationException("Todo with id of " + id + " does not exist.", Status.NOT_FOUND);
    }
    entity.delete();
    return Response.noContent().build();
}
 
Example 7
Source File: RoutingRulesResource.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@PUT
@Path("/{name}")
@RequiresAuthentication
@RequiresPermissions("nexus:*")
public void updateRoutingRule(@PathParam("name") final String name, RoutingRuleXO routingRuleXO) {
  RoutingRule routingRule = routingRuleStore.getByName(name);
  if (null == routingRule) {
    throw new WebApplicationException(Status.NOT_FOUND);
  }
  routingRule.name(routingRuleXO.getName());
  routingRule.description(routingRuleXO.getDescription());
  routingRule.mode(routingRuleXO.getMode());
  routingRule.matchers(routingRuleXO.getMatchers());
  routingRuleStore.update(routingRule);
}
 
Example 8
Source File: TodoResource.java    From quarkus-deep-dive with Apache License 2.0 5 votes vote down vote up
@DELETE
@Transactional
@Path("/{id}")
public Response deleteOne(@PathParam("id") Long id) {
    Todo entity = Todo.findById(id);
    if (entity == null) {
        throw new WebApplicationException("Todo with id of " + id + " does not exist.", Status.NOT_FOUND);
    }
    entity.delete();
    return Response.noContent().build();
}
 
Example 9
Source File: ObjectsResource.java    From imagej-server with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the information of an object.
 * 
 * @param id object ID
 * @return a JSON node containing the object information
 */
@GET
@Path("{id}")
public ObjectInfo getObjectInfo(@PathParam("id") final String id) {
	if (!objectService.contains(id)) {
		throw new WebApplicationException("ID does not exist", Status.NOT_FOUND);
	}
	return objectService.find(id);
}
 
Example 10
Source File: ExternalTaskResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void unlock() {
  ExternalTaskService externalTaskService = engine.getExternalTaskService();

  try {
    externalTaskService.unlock(externalTaskId);
  } catch (NotFoundException e) {
    throw new RestException(Status.NOT_FOUND, e, "External task with id " + externalTaskId + " does not exist");
  }
}
 
Example 11
Source File: CaseInstanceResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public CaseInstanceDto getCaseInstance() {
  CaseService caseService = engine.getCaseService();

  CaseInstance instance = caseService
      .createCaseInstanceQuery()
      .caseInstanceId(caseInstanceId)
      .singleResult();

  if (instance == null) {
    throw new InvalidRequestException(Status.NOT_FOUND, "Case instance with id " + caseInstanceId + " does not exist.");
  }

  CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);
  return result;
}
 
Example 12
Source File: HistoricActivityInstanceResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public HistoricActivityInstanceDto getHistoricActivityInstance() {
  HistoryService historyService = engine.getHistoryService();
  HistoricActivityInstance instance = historyService.createHistoricActivityInstanceQuery()
    .activityInstanceId(activityInstanceId).singleResult();

  if (instance == null) {
    throw new InvalidRequestException(Status.NOT_FOUND, "Historic activity instance with id '" + activityInstanceId + "' does not exist");
  }

  final HistoricActivityInstanceDto historicActivityInstanceDto = new HistoricActivityInstanceDto();
  HistoricActivityInstanceDto.fromHistoricActivityInstance(historicActivityInstanceDto, instance);
  return historicActivityInstanceDto;
}
 
Example 13
Source File: NamespacesBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
protected PublishRate internalGetPublishRate() {
    validateNamespacePolicyOperation(namespaceName, PolicyName.RATE, PolicyOperation.READ);

    Policies policies = getNamespacePolicies(namespaceName);
    PublishRate publishRate = policies.publishMaxMessageRate.get(pulsar().getConfiguration().getClusterName());
    if (publishRate != null) {
        return publishRate;
    } else {
        throw new RestException(Status.NOT_FOUND,
                "Publish-rate is not configured for cluster " + pulsar().getConfiguration().getClusterName());
    }
}
 
Example 14
Source File: AbstractRestInvocation.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
protected void findRestOperation(MicroserviceMeta microserviceMeta) {
  ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
  if (servicePathManager == null) {
    LOGGER.error("No schema defined for {}:{}.", microserviceMeta.getAppId(), microserviceMeta.getMicroserviceName());
    throw new InvocationException(Status.NOT_FOUND, Status.NOT_FOUND.getReasonPhrase());
  }

  OperationLocator locator = locateOperation(servicePathManager);
  requestEx.setAttribute(RestConst.PATH_PARAMETERS, locator.getPathVarMap());
  this.restOperationMeta = locator.getOperation();
}
 
Example 15
Source File: AuthorizationResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Authorization getDbAuthorization() {
  Authorization dbAuthorization = authorizationService.createAuthorizationQuery()
    .authorizationId(resourceId)
    .singleResult();

  if (dbAuthorization == null) {
    throw new InvalidRequestException(Status.NOT_FOUND, "Authorization with id " + resourceId + " does not exist.");

  } else {
    return dbAuthorization;

  }
}
 
Example 16
Source File: LegacyUserService.java    From keycloak-user-migration-provider with Apache License 2.0 5 votes vote down vote up
@Override
public Response validateUserExists(String username)
{
    User user = userManager.findByEmail(username);
    Status status = user != null ? Status.OK : Status.NOT_FOUND;
    return Response.status(status).entity("").build();
}
 
Example 17
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 18
Source File: ClustersBase.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/{cluster}/namespaceIsolationPolicies/{policyName}")
@ApiOperation(
        value = "Get the single namespace isolation policy assigned to the cluster.",
        response = NamespaceIsolationData.class,
        notes = "This operation requires Pulsar superuser privileges."
)
@ApiResponses(value = {
        @ApiResponse(code = 403, message = "Don't have admin permission."),
        @ApiResponse(code = 404, message = "Policy doesn't exist."),
        @ApiResponse(code = 412, message = "Cluster doesn't exist."),
        @ApiResponse(code = 500, message = "Internal server error.")
})
public NamespaceIsolationData getNamespaceIsolationPolicy(
    @ApiParam(
        value = "The cluster name",
        required = true
    )
    @PathParam("cluster") String cluster,
    @ApiParam(
        value = "The name of the namespace isolation policy",
        required = true
    )
    @PathParam("policyName") String policyName
) throws Exception {
    validateSuperUserAccess();
    validateClusterExists(cluster);

    try {
        NamespaceIsolationPolicies nsIsolationPolicies = namespaceIsolationPoliciesCache()
                .get(path("clusters", cluster, NAMESPACE_ISOLATION_POLICIES))
                .orElseThrow(() -> new RestException(Status.NOT_FOUND,
                        "NamespaceIsolationPolicies for cluster " + cluster + " does not exist"));
        // construct the response to Namespace isolation data map
        if (!nsIsolationPolicies.getPolicies().containsKey(policyName)) {
            log.info("[{}] Cannot find NamespaceIsolationPolicy {} for cluster {}", clientAppId(), policyName, cluster);
            throw new RestException(Status.NOT_FOUND,
                    "Cannot find NamespaceIsolationPolicy " + policyName + " for cluster " + cluster);
        }
        return nsIsolationPolicies.getPolicies().get(policyName);
    } catch (RestException re) {
        throw re;
    } catch (Exception e) {
        log.error("[{}] Failed to get clusters/{}/namespaceIsolationPolicies/{}", clientAppId(), cluster, e);
        throw new RestException(e);
    }
}
 
Example 19
Source File: NotFoundException.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public NotFoundException(String msg) {
  super(new Exception(msg), Status.NOT_FOUND);
}
 
Example 20
Source File: NotFoundException.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public NotFoundException() {
  super(Status.NOT_FOUND);
}