Java Code Examples for org.restlet.data.Status#CLIENT_ERROR_NOT_FOUND

The following examples show how to use org.restlet.data.Status#CLIENT_ERROR_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: AgentsAgidObjects.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the list of IoT objects registered under given Agent.
 * 
 * @return All VICINITY identifiers of objects registered under specified agent.
 */
@Get
public Representation represent() {
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	XMLConfiguration config = (XMLConfiguration) getContext().getAttributes().get(Api.CONTEXT_CONFIG);
	
	
	String attrAgid = getAttribute(ATTR_AGID);
	
	if (attrAgid == null){
		logger.info("AGID: " + attrAgid + " Invalid Agent ID.");
		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
				"Invalid Agent ID.");
	}
	
	return getAgentObjects(attrAgid, logger, config);
}
 
Example 2
Source File: AgentsAgidObjects.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Register the IoT object(s) of the underlying eco-system e.g. devices, VA service.
 * 
 * @param entity Representation of the incoming JSON. List of IoT thing descriptions that are to be registered 
 * (from request).
 * @return All VICINITY identifiers of objects registered under VICINITY Gateway by this call.
 * 
 */
@Post("json")
public Representation accept(Representation entity) {
	
	String attrAgid = getAttribute(ATTR_AGID);
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	XMLConfiguration config = (XMLConfiguration) getContext().getAttributes().get(Api.CONTEXT_CONFIG);
	
	
	if (attrAgid == null){
		logger.info("AGID: " + attrAgid + " Invalid Agent ID.");
		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
				"Invalid Agent ID.");
	}
	
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.info("AGID: " + attrAgid + " Invalid object descriptions.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid object descriptions");
	}
	
	return storeObjects(entity, logger, config);
}
 
Example 3
Source File: AgentsAgidObjects.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Update the thing descriptions of objects registered under the Agent.
 * 
 * @param entity Representation of the incoming JSON.
 * 
 */
@Put("json")
public Representation store(Representation entity) {
	
	String attrAgid = getAttribute(ATTR_AGID);
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	XMLConfiguration config = (XMLConfiguration) getContext().getAttributes().get(Api.CONTEXT_CONFIG);
	
	if (attrAgid == null){
		logger.info("AGID: " + attrAgid + " Invalid Agent ID.");
		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
				"Invalid Agent ID.");
	}
	
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.info("AGID: " + attrAgid + " Invalid object descriptions.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid object descriptions");
	}
	
	return heavyweightUpdate(entity, logger, config);
}
 
Example 4
Source File: AgentsAgidObjectsUpdate.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
@Put("json")
public Representation store(Representation entity) {
	
	String attrAgid = getAttribute(ATTR_AGID);
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	XMLConfiguration config = (XMLConfiguration) getContext().getAttributes().get(Api.CONTEXT_CONFIG);
	
	if (attrAgid == null){
		logger.info("AGID: " + attrAgid + " Invalid Agent ID.");
		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
				"Invalid Agent ID.");
	}
	
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.info("AGID: " + attrAgid + " Invalid object descriptions.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid object descriptions");
	}
	
	return lightweightUpdate(entity, logger, config);
}
 
Example 5
Source File: EventsEid.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Used by an Agent/Adapter that is capable of generating events to de-activate an event channel. This will 
 * prohibit any other new objects to subscribe to that channel, and the objects that are already subscribed are 
 * notified and removed from subscription list.
 * 
 * @return statusMessage {@link StatusMessage StatusMessage} with the result of the operation.
 */
@Delete
public Representation remove(Representation entity) {
	String attrEid = getAttribute(ATTR_EID);
	String callerOid = getRequest().getChallengeResponse().getIdentifier();
	Map<String, String> queryParams = getQuery().getValuesMap();
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	
	if (attrEid == null){
		logger.info("EID: " + attrEid + " Invalid identifier.");
		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
				"Invalid identifier.");
	}
	
	String body = getRequestBody(entity, logger);
	
	CommunicationManager communicationManager 
					= (CommunicationManager) getContext().getAttributes().get(Api.CONTEXT_COMMMANAGER);
	
	StatusMessage statusMessage = communicationManager.deactivateEventChannel(callerOid, attrEid, queryParams, body);
	
	return new JsonRepresentation(statusMessage.buildMessage().toString());
}
 
Example 6
Source File: AgentsAgidObjectsDelete.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Deletes - unregisters the IoT object(s).
 * 
 * @param entity Representation of the incoming JSON. List of IoT thing descriptions that are to be removed 
 * (taken from request).
 * @return Notification of success or failure.
 * 
 */
@Post("json")
public Representation accept(Representation entity) {
	
	String attrAgid = getAttribute(ATTR_AGID);
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	XMLConfiguration config = (XMLConfiguration) getContext().getAttributes().get(Api.CONTEXT_CONFIG);
	
	if (attrAgid == null){
		logger.info("AGID: " + attrAgid + " Invalid Agent ID.");
		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
				"Invalid Agent ID.");
	}
	
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.info("AGID: " + attrAgid + " Invalid object descriptions.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid object descriptions");
	}
	
	return deleteObjects(entity, logger, config);
}
 
Example 7
Source File: EntitiesResource.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
protected Representation get( Variant variant )
    throws ResourceException
{
    // Generate the right representation according to its media type.
    if( MediaType.APPLICATION_JSON.equals( variant.getMediaType() ) )
    {
        return representJson();
    }
    else if( MediaType.APPLICATION_RDF_XML.equals( variant.getMediaType() ) )
    {
        return representRdf();
    }
    else if( MediaType.TEXT_HTML.equals( variant.getMediaType() ) )
    {
        return representHtml();
    }
    else if( MediaType.APPLICATION_ATOM.equals( variant.getMediaType() ) )
    {
        return representAtom();
    }

    throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
}
 
Example 8
Source File: ContextResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
protected <T> T select( Class<T> entityClass, Identity id )
    throws ResourceException
{
    try
    {
        T composite = uowf.currentUnitOfWork().get( entityClass,  id );
        current().select( composite );
        return composite;
    }
    catch( NoSuchEntityTypeException | NoSuchEntityException e )
    {
        throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
    }
}
 
Example 9
Source File: ContextResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
protected <T> T selectFromManyAssociation( ManyAssociation<T> manyAssociation, Identity id )
    throws ResourceException
{
    T entity = (T) uowf.currentUnitOfWork().get( Object.class, id  );
    if( !manyAssociation.contains( entity ) )
    {
        throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
    }

    current().select( entity );
    return entity;
}
 
Example 10
Source File: ContextResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
protected <T> T selectFromNamedAssociation( NamedAssociation<T> namedAssociation, Identity id )
    throws ResourceException
{
    T entity = (T) uowf.currentUnitOfWork().get( Object.class, id );
    String name = namedAssociation.nameOf( entity );
    if( name == null )
    {
        throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
    }

    current().select( entity );
    return entity;
}
 
Example 11
Source File: ContextResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
protected void selectFromList( List<?> list, String indexString )
{
    Integer index = Integer.decode( indexString );

    if( index < 0 || index >= list.size() )
    {
        throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
    }

    current().select( index );

    Object value = list.get( index );
    current().select( value );
}
 
Example 12
Source File: ContextResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private Method getSubResourceMethod( String resourceName )
    throws ResourceException
{
    Method method = subResources.get( resourceName );
    if( method != null )
    {
        return method;
    }

    throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
}
 
Example 13
Source File: EntityResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private EntityState getEntityState( EntityStoreUnitOfWork unitOfWork )
    throws ResourceException
{
    EntityState entityState;
    try
    {
        EntityReference entityReference = EntityReference.create( identity );
        entityState = unitOfWork.entityStateOf( module, entityReference );
    }
    catch( EntityNotFoundException e )
    {
        throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
    }
    return entityState;
}
 
Example 14
Source File: AbstractTMObjectResource.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public TMO remove(TMO object) throws OntopiaRestException {
	if (object == null) {
		// todo: OntopiaRestErrors
		throw new OntopiaClientException(Status.CLIENT_ERROR_NOT_FOUND, "Cannot find " + objectClass.getSimpleName() + " to remove");
	}
	
	// todo: move to controller
	
	object.remove();
	store.commit();
	return object;
}
 
Example 15
Source File: RestManager.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize objects needed to handle a request to the REST API. Specifically,
 * we lookup the RestManager using the ThreadLocal SolrRequestInfo and then
 * dynamically locate the ManagedResource associated with the request URI.
 */
@Override
public void doInit() throws ResourceException {
  super.doInit();      
  
  // get the relative path to the requested resource, which is
  // needed to locate ManagedResource impls at runtime
  String resourceId = resolveResourceId(getRequest());

  // supports a request for a registered resource or its child
  RestManager restManager = 
      RestManager.getRestManager(SolrRequestInfo.getRequestInfo());
  
  managedResource = restManager.getManagedResourceOrNull(resourceId);      
  if (managedResource == null) {
    // see if we have a registered endpoint one-level up ...
    int lastSlashAt = resourceId.lastIndexOf('/');
    if (lastSlashAt != -1) {
      String parentResourceId = resourceId.substring(0,lastSlashAt);          
      log.info("Resource not found for {}, looking for parent: {}",
          resourceId, parentResourceId);          
      managedResource = restManager.getManagedResourceOrNull(parentResourceId);
      if (managedResource != null) {
        // verify this resource supports child resources
        if (!(managedResource instanceof ManagedResource.ChildResourceSupport)) {
          String errMsg = String.format(Locale.ROOT,
              "%s does not support child resources!", managedResource.getResourceId());
          throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, errMsg);
        }
        
        childId = resourceId.substring(lastSlashAt+1);
        log.info("Found parent resource {} for child: {}", 
            parentResourceId, childId);
      }
    }
  }    
  
  if (managedResource == null) {
    if (Method.PUT.equals(getMethod()) || Method.POST.equals(getMethod())) {
      // delegate create requests to the RestManager
      managedResource = restManager.endpoint;
    } else {        
      throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
          "No REST managed resource registered for path "+resourceId);
    }
  }
  
  log.info("Found ManagedResource [{}] for {}", managedResource, resourceId);
}
 
Example 16
Source File: EntityResource.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
@Override
protected Representation get( Variant variant )
    throws ResourceException
{
    EntityStoreUnitOfWork uow = entityStore.newUnitOfWork( module, UsecaseBuilder.newUsecase( "Get entity" ),
                                                           SystemTime.now() );

    try
    {
        EntityState entityState = getEntityState( uow );

        // Check modification date
        java.util.Date lastModified = getRequest().getConditions().getModifiedSince();
        if( lastModified != null )
        {
            if( lastModified.toInstant().getEpochSecond() == entityState.lastModified().getEpochSecond() )
            {
                throw new ResourceException( Status.REDIRECTION_NOT_MODIFIED );
            }
        }

        // Generate the right representation according to its media type.
        if( MediaType.APPLICATION_RDF_XML.equals( variant.getMediaType() ) )
        {
            return entityHeaders( representRdfXml( entityState ), entityState );
        }
        else if( MediaType.TEXT_HTML.equals( variant.getMediaType() ) )
        {
            return entityHeaders( representHtml( entityState ), entityState );
        }
        else if( MediaType.APPLICATION_JSON.equals( variant.getMediaType() ) )
        {
            return entityHeaders( representJson( entityState ), entityState );
        }
    }
    catch( ResourceException ex )
    {
        uow.discard();
        throw ex;
    }

    throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
}