Java Code Examples for org.restlet.resource.ResourceException

The following examples show how to use org.restlet.resource.ResourceException. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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
/**
 * 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
/**
 * 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
@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
/**
 * Used by an Agent/Adapter, that is capable of generating events and is willing to send these events to subscribed 
 * objects. A call to this end point activates the channel – from that moment, other objects in the network are able
 * to subscribe for receiving those messages.
 *  
 * @param entity Optional JSON with parameters.
 * @return statusMessage {@link StatusMessage StatusMessage} with the result of the operation.
 */
@Post("json")
public Representation accept(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_BAD_REQUEST, 
				"Invalid identifier.");
	}
	
	String body = getRequestBody(entity, logger);
	
	CommunicationManager communicationManager 
					= (CommunicationManager) getContext().getAttributes().get(Api.CONTEXT_COMMMANAGER);
	
	StatusMessage statusMessage = communicationManager.activateEventChannel(callerOid, attrEid, queryParams, body);
	
	return new JsonRepresentation(statusMessage.buildMessage().toString());
}
 
Example 6
/**
 * 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 7
/**
 * Retrieves status of a remote event channel.
 * 
 * @return Latest property value.
 */
@Get
public Representation represent(Representation entity) {
	String attrOid = getAttribute(ATTR_OID);
	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 (attrOid == null || attrEid == null){
		logger.info("OID: " + attrOid + " EID: " + attrEid + " Invalid identifier.");
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid identifier.");
	}
	
	String body = getRequestBody(entity, logger);
	
	CommunicationManager communicationManager 
			= (CommunicationManager) getContext().getAttributes().get(Api.CONTEXT_COMMMANAGER);
	
	
	return new JsonRepresentation(communicationManager.getEventChannelStatus(callerOid, attrOid, attrEid, 
			queryParams, body).buildMessage().toString()); 
	
}
 
Example 8
Source Project: attic-polygene-java   Source File: RootResource.java    License: Apache License 2.0 6 votes vote down vote up
@SubResource
public void administration()
{
    ChallengeResponse challenge = Request.getCurrent().getChallengeResponse();
    if( challenge == null )
    {
        Response.getCurrent()
            .setChallengeRequests( Collections.singletonList( new ChallengeRequest( ChallengeScheme.HTTP_BASIC, "Forum" ) ) );
        throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
    }

    User user = select( Users.class, Users.USERS_ID ).userNamed( challenge.getIdentifier() );
    if( user == null || !user.isCorrectPassword( new String( challenge.getSecret() ) ) )
    {
        throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
    }

    current().select( user );

    subResource( AdministrationResource.class );
}
 
Example 9
/**
 * Gets a specific task status to perform an action of an available IoT object.
 * 
 * @return Task status.
 */
@Get
public Representation represent(Representation entity) {
	String attrOid = getAttribute(ATTR_OID);
	String attrAid = getAttribute(ATTR_AID);
	String attrTid = getAttribute(ATTR_TID);
	String callerOid = getRequest().getChallengeResponse().getIdentifier();
	Map<String, String> queryParams = getQuery().getValuesMap();
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	
	if (attrOid == null || attrAid == null || attrTid == null){
		logger.info("OID: " + attrOid + " AID: " + attrAid + " TID: " + attrTid 
				+ " Given identifier does not exist.");
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Given identifier does not exist.");
	}
	
	String body = getRequestBody(entity, logger);
	
	return getActionTaskStatus(callerOid, attrOid, attrAid, attrTid, queryParams, body);
}
 
Example 10
Source Project: attic-polygene-java   Source File: FormRequestWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
   if (requestObject instanceof Form)
   {
      // Form as query parameters
      if (request.getMethod().equals(Method.GET))
         request.getResourceRef().setQuery(((Form)requestObject).getQueryString());
      else
         request.setEntity(((Form)requestObject).getWebRepresentation(CharacterSet.UTF_8));

      return true;
   }

   return false;
}
 
Example 11
/**
 * Gets the property value of an available IoT object.
 * 
 * @return Latest property value.
 */
@Get
public Representation represent(Representation entity) {
	String attrOid = getAttribute(ATTR_OID);
	String attrPid = getAttribute(ATTR_PID);
	String callerOid = getRequest().getChallengeResponse().getIdentifier();
	Map<String, String> queryParams = getQuery().getValuesMap();
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	
	if (attrOid == null || attrPid == null){
		logger.info("OID: " + attrOid + " PID: " + attrPid + " Invalid identifier.");
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid identifier.");
	}
	
	String body = getRequestBody(entity, logger);
	
	return getObjectProperty(callerOid, attrOid, attrPid, body, queryParams);
	
}
 
Example 12
/**
 * Sets the property value of an available IoT object.
 * 
 * @param entity Representation of the incoming JSON.
 * @param object Model.
 */
@Put("json")
public Representation store(Representation entity) {
	String attrOid = getAttribute(ATTR_OID);
	String attrPid = getAttribute(ATTR_PID);
	String callerOid = getRequest().getChallengeResponse().getIdentifier();
	Map<String, String> queryParams = getQuery().getValuesMap();
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	
	if (attrOid == null || attrPid == null){
		logger.info("OID: " + attrOid + " PID: " + attrPid 
								+ " Invalid identifier.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid identifier.");
	}
	
	String body = getRequestBody(entity, logger);
	
	return updateProperty(callerOid, attrOid, attrPid, body, queryParams);
}
 
Example 13
Source Project: attic-polygene-java   Source File: EntitiesResource.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Representation post( Representation entity, Variant variant )
    throws ResourceException
{
    try
    {
        /*
         * InputStream in = entity.getStream(); ObjectInputStream oin = new ObjectInputStream( in ); String reference
         * = oin.readUTF(); Usecase usecase = (Usecase) oin.readUnshared(); MetaInfo unitofwork = (MetaInfo)
         * oin.readUnshared(); Iterable<UnitOfWorkEvent> events = (Iterable<UnitOfWorkEvent>) oin.readUnshared();
         *
         * // Store state try { entityStore.apply( reference, events, usecase, unitofwork ).commit(); } catch(
         * ConcurrentEntityStateModificationException e ) { throw new ResourceException(
         * Status.CLIENT_ERROR_CONFLICT ); }
         */
    }
    catch( Exception e )
    {
        throw new ResourceException( e );
    }

    return new EmptyRepresentation();
}
 
Example 14
Source Project: attic-polygene-java   Source File: IndexResource.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Representation get( Variant variant )
    throws ResourceException
{
    if( variant.getMediaType().equals( MediaType.APPLICATION_RDF_XML ) )
    {
        return new RdfXmlOutputRepresentation();
    }
    else if( variant.getMediaType().equals( MediaType.APPLICATION_RDF_TRIG ) )
    {
        return new RdfTrigOutputRepresentation( MediaType.APPLICATION_RDF_TRIG );
    }
    else if( variant.getMediaType().equals( MediaType.TEXT_PLAIN ) )
    {
        return new RdfTrigOutputRepresentation( MediaType.TEXT_PLAIN );
    }

    return null;
}
 
Example 15
Source Project: unitime   Source File: XEBatchSolverSaver.java    License: Apache License 2.0 6 votes vote down vote up
protected XEInterface.RegisterResponse postChanges(ClientResource resource, XEInterface.RegisterRequest req) throws IOException {
	if (req.isEmpty()) req.empty();
	try {
        resource.post(new GsonRepresentation<XEInterface.RegisterRequest>(req));
	} catch (ResourceException e) {
		handleError(resource, e);
	}

	XEInterface.RegisterResponse response = new GsonRepresentation<XEInterface.RegisterResponse>(resource.getResponseEntity(), XEInterface.RegisterResponse.class).getObject();

	if (response == null)
        throw new SectioningException("Failed to enroll student.");
	else if (!response.validStudent) {
		String reason = null;
		if (response.failureReasons != null)
			for (String m: response.failureReasons) {
				if (reason == null) reason = m;
				else reason += "\n" + m;
			}
		if (reason != null) throw new SectioningException(reason);
		throw new SectioningException("Failed to enroll student.");
	}
	
    return response;
}
 
Example 16
Source Project: lucene-solr   Source File: RestManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
  
  // filter results by /schema or /config
  String path = ManagedEndpoint.resolveResourceId(endpoint.getRequest());
  Matcher resourceIdMatcher = resourceIdRegex.matcher(path);
  if (!resourceIdMatcher.matches()) {
    // extremely unlikely but didn't want to squelch it either
    throw new ResourceException(Status.SERVER_ERROR_NOT_IMPLEMENTED, path);
  }
  
  String filter = resourceIdMatcher.group(1);
        
  List<Map<String,String>> regList = new ArrayList<>();
  for (ManagedResourceRegistration reg : restManager.registry.getRegistered()) {
    if (!reg.resourceId.startsWith(filter))
      continue; // doesn't match filter
    
    if (RestManagerManagedResource.class.isAssignableFrom(reg.implClass))
      continue; // internal, no need to expose to outside
    
    regList.add(reg.getInfo());          
  }
  
  endpoint.getSolrResponse().add("managedResources", regList);      
}
 
Example 17
Source Project: attic-polygene-java   Source File: ResourceValidity.java    License: Apache License 2.0 6 votes vote down vote up
void checkRequest()
    throws ResourceException
{
    // Check command rules
    Instant unmodifiedSince = request.getConditions().getUnmodifiedSince().toInstant();
    EntityState state = spi.entityStateOf( entity );
    Instant lastModifiedSeconds = state.lastModified().with(ChronoField.NANO_OF_SECOND, 0 );
    if( unmodifiedSince != null )
    {
        if( lastModifiedSeconds.isAfter( unmodifiedSince ) )
        {
            throw new ResourceException( Status.CLIENT_ERROR_CONFLICT );
        }
    }

    // Check query rules
    Instant modifiedSince = request.getConditions().getModifiedSince().toInstant();
    if( modifiedSince != null )
    {
        if( !lastModifiedSeconds.isAfter( modifiedSince ) )
        {
            throw new ResourceException( Status.REDIRECTION_NOT_MODIFIED );
        }
    }
}
 
Example 18
Source Project: attic-polygene-java   Source File: EntityResource.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Representation delete( Variant variant )
    throws ResourceException
{
    Usecase usecase = UsecaseBuilder.newUsecase( "Remove entity" );
    EntityStoreUnitOfWork uow = entityStore.newUnitOfWork( module, usecase, SystemTime.now() );
    try
    {
        EntityReference reference = EntityReference.create( identity );
        uow.entityStateOf( module, reference ).remove();
        uow.applyChanges().commit();
        getResponse().setStatus( Status.SUCCESS_NO_CONTENT );
    }
    catch( EntityNotFoundException e )
    {
        uow.discard();
        getResponse().setStatus( Status.CLIENT_ERROR_NOT_FOUND );
    }

    return new EmptyRepresentation();
}
 
Example 19
Source Project: attic-polygene-java   Source File: EntityResource.java    License: Apache License 2.0 6 votes vote down vote up
private Representation representRdfXml( final EntityState entity )
    throws ResourceException
{
    Representation representation = new WriterRepresentation( MediaType.APPLICATION_RDF_XML )
    {
        @Override
        public void write( Writer writer )
            throws IOException
        {
            try
            {
                Iterable<Statement> statements = entitySerializer.serialize( entity );
                new RdfXmlSerializer().serialize( statements, writer );
            }
            catch( RDFHandlerException e )
            {
                throw new IOException( e );
            }
        }
    };
    representation.setCharacterSet( CharacterSet.UTF_8 );
    return representation;
}
 
Example 20
Source Project: attic-polygene-java   Source File: EntitiesResource.java    License: 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 21
Source Project: ontopia   Source File: AbstractResourceTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void assertRequestFails(String url, Method method, MediaType preferred, Object object, OntopiaRestErrors expected) {
	OntopiaTestResource cr = new OntopiaTestResource(method, getUrl(url), preferred);
	try {
		cr.request(object, Object.class);
		Assert.fail("Expected Ontopia error " + expected.name() + ", but request succeeded");
	} catch (OntopiaTestResourceException e) {
		Error result = e.getError();
		try {
			Assert.assertNotNull("Expected error, found null", result);
			Assert.assertEquals("Ontopia error code mismatch", expected.getCode(), result.getCode());
			Assert.assertEquals("HTTP status code mismatch", expected.getStatus().getCode(), result.getHttpcode());
			Assert.assertNotNull("Error message is empty", result.getMessage());
		} catch (AssertionError ae) {
			Assert.fail("Expected ontopia error " + expected.name() + 
					", but received [" + result.getHttpcode() + ":" + result.getCode() + ", " + result.getMessage() + "]");
		}
	} catch (ResourceException re) {
		Assert.fail("Expected ontopia error " + expected.name() + 
				", but received [" + re.getStatus().getCode() + ":" + re.getStatus().getDescription() + "]");
	}
}
 
Example 22
/**
 * Retrieves a request body.
 * 
 * @param entity Entity to extract the body from.
 * @param logger Logger.
 * @return Text representation of the body.
 */
private String getRequestBody(Representation entity, Logger logger) {
	
	if (entity == null) {
		return null;
	}
	
	// check the body of the event to be sent
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.warning("Invalid request body - must be a valid JSON.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body - must be a valid JSON.");
	}
	
	// get the json
	String eventJsonString = null;
	try {
		eventJsonString = entity.getText();
	} catch (IOException e) {
		logger.info(e.getMessage());
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body");
	}
	
	return eventJsonString;
}
 
Example 23
/**
 * Used by an Agent/Adapter that is capable of generating events, to send an event to all subscribed objects on 
 * the network.
 * 
 * @param entity JSON with the event.
 * @return statusMessage {@link StatusMessage StatusMessage} with the result of the operation.
 */
@Put("json")
public Representation store(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);
	
	// check the mandatory attributes
	if (attrEid == null){
		logger.info("EID: " + attrEid + " Invalid identifier.");
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid identifier.");
	}
	
	String body = getRequestBody(entity, logger);
	
	CommunicationManager communicationManager 
					= (CommunicationManager) getContext().getAttributes().get(Api.CONTEXT_COMMMANAGER);
	
	StatusMessage statusMessage 
					= communicationManager.sendEventToSubscribedObjects(callerOid, attrEid, body, 
							queryParams);
	
	return new JsonRepresentation(statusMessage.buildMessage().toString());
}
 
Example 24
Source Project: attic-polygene-java   Source File: ForumsResource.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void resource( String segment )
    throws ResourceException
{
    select( Forum.class, StringIdentity.identityOf( segment ) );
    subResource( ForumResource.class );
}
 
Example 25
Source Project: unitime   Source File: XEBatchSolverSaver.java    License: Apache License 2.0 5 votes vote down vote up
protected XEInterface.RegisterResponse getHoldSchedule(Student student, ClientResource resource) throws IOException {
	if (iHoldPassword != null && !iHoldPassword.isEmpty())
		iProgress.debug("[" + student.getExternalId() + "] " + "Using hold password...");
	if (iRegistrationDate != null && !iRegistrationDate.isEmpty())
		iProgress.debug("[" + student.getExternalId() + "] " + "Using registration date...");
	
	XEInterface.RegisterRequest req = new XEInterface.RegisterRequest(resource.getQueryValue("term"), resource.getQueryValue("bannerId"), null, true);
	req.empty();
	if (iHoldPassword != null && !iHoldPassword.isEmpty())
        req.holdPassword = iHoldPassword;
	if (iRegistrationDate != null && !iRegistrationDate.isEmpty())
        req.registrationDate = iRegistrationDate;
	try {
		resource.post(new GsonRepresentation<XEInterface.RegisterRequest>(req));
	} catch (ResourceException e) {
		handleError(resource, e);
	}

	XEInterface.RegisterResponse response = new GsonRepresentation<XEInterface.RegisterResponse>(resource.getResponseEntity(), XEInterface.RegisterResponse.class).getObject();
	if (response == null)
		throw new SectioningException("Failed to check student registration status.");
	else if (!response.validStudent) {
		String reason = null;
		if (response.failureReasons != null)
			for (String m: response.failureReasons) {
				if (reason == null) reason = m;
				else reason += "\n" + m;
			}
		if (reason != null) throw new SectioningException(reason);
		throw new SectioningException("Failed to check student registration status.");
	}
    return response;
}
 
Example 26
/**
 * Retrieves a request body.
 * 
 * @param entity Entity to extract the body from.
 * @param logger Logger.
 * @return Text representation of the body.
 */
private String getRequestBody(Representation entity, Logger logger) {
	
	if (entity == null) {
		return null;
	}
	
	// check the body of the event to be sent
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.warning("Invalid request body - must be a valid JSON.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body - must be a valid JSON.");
	}
	
	// get the json
	String eventJsonString = null;
	try {
		eventJsonString = entity.getText();
	} catch (IOException e) {
		logger.info(e.getMessage());
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body");
	}
	
	return eventJsonString;
}
 
Example 27
/**
 * Retrieves a request body.
 * 
 * @param entity Entity to extract the body from.
 * @param logger Logger.
 * @return Text representation of the body.
 */
private String getRequestBody(Representation entity, Logger logger) {
	
	if (entity == null) {
		return null;
	}
	
	// check the body of the event to be sent
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.warning("Invalid request body - must be a valid JSON.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body - must be a valid JSON.");
	}
	
	// get the json
	String eventJsonString = null;
	try {
		eventJsonString = entity.getText();
	} catch (IOException e) {
		logger.info(e.getMessage());
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body");
	}
	
	return eventJsonString;
}
 
Example 28
/**
 * Retrieves a request body.
 * 
 * @param entity Entity to extract the body from.
 * @param logger Logger.
 * @return Text representation of the body.
 */
private String getRequestBody(Representation entity, Logger logger) {
	
	if (entity == null) {
		return null;
	}
	
	// check the body of the event to be sent
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.warning("Invalid request body - must be a valid JSON.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body - must be a valid JSON.");
	}
	
	// get the json
	String eventJsonString = null;
	try {
		eventJsonString = entity.getText();
	} catch (IOException e) {
		logger.info(e.getMessage());
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body");
	}
	
	return eventJsonString;
}
 
Example 29
/**
 * Retrieves a request body.
 * 
 * @param entity Entity to extract the body from.
 * @param logger Logger.
 * @return Text representation of the body.
 */
private String getRequestBody(Representation entity, Logger logger) {
	
	if (entity == null) {
		return null;
	}
	
	// check the body of the event to be sent
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.warning("Invalid request body - must be a valid JSON.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body - must be a valid JSON.");
	}
	
	// get the json
	String eventJsonString = null;
	try {
		eventJsonString = entity.getText();
	} catch (IOException e) {
		logger.info(e.getMessage());
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body");
	}
	
	return eventJsonString;
}
 
Example 30
/**
 * Retrieves a request body.
 * 
 * @param entity Entity to extract the body from.
 * @param logger Logger.
 * @return Text representation of the body.
 */
private String getRequestBody(Representation entity, Logger logger) {
	
	if (entity == null) {
		return null;
	}
	
	// check the body of the event to be sent
	if (!entity.getMediaType().equals(MediaType.APPLICATION_JSON)){
		logger.warning("Invalid request body - must be a valid JSON.");
		
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body - must be a valid JSON.");
	}
	
	// get the json
	String eventJsonString = null;
	try {
		eventJsonString = entity.getText();
	} catch (IOException e) {
		logger.info(e.getMessage());
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid request body");
	}
	
	return eventJsonString;
}