Java Code Examples for org.restlet.representation.Representation#getText()

The following examples show how to use org.restlet.representation.Representation#getText() . 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: NeighbourhoodManagerConnector.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Perform handshake and expects NM to validate identity.
 * 
 * @param JSON containing array records with all the messages 
 * @return Server acknowledgment
 */
public synchronized void handshake(){
	try {
		String endpointUrl = SERVER_PROTOCOL + neighbourhoodManagerServer + ":" + port + API_PATH + HANDSHAKE;
		ClientResource clientResource = createRequest(endpointUrl);
		Representation responseRepresentation = clientResource.get(MediaType.APPLICATION_JSON);
		JSONObject jsonDocument = new JSONObject(responseRepresentation.getText());
		logger.info(jsonDocument.getString("message"));
	} catch(IOException i) {
		i.printStackTrace();
	} catch(Exception e) {
		e.printStackTrace();
		logger.warning("There might be a problem authenticating your signature, please check that you uploaded the right public key to the server.");
	}
	
}
 
Example 2
Source File: TopicManagementRestletResource.java    From uReplicator with Apache License 2.0 6 votes vote down vote up
@Override
@Put("json")
public Representation put(Representation entity) {
  try {
    String jsonRequest = entity.getText();
    TopicPartition topicPartitionInfo = TopicPartition.init(jsonRequest);
    if (_autoTopicWhitelistingManager != null) {
      _autoTopicWhitelistingManager.removeFromBlacklist(topicPartitionInfo.getTopic());
    }
    if (_helixMirrorMakerManager.isTopicExisted(topicPartitionInfo.getTopic())) {
      _helixMirrorMakerManager.expandTopicInMirrorMaker(topicPartitionInfo);
      return new StringRepresentation(
          String.format("Successfully expand topic: %s", topicPartitionInfo));
    } else {
      getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
      return new StringRepresentation(String.format(
          "Failed to expand topic, topic: %s is not existed!", topicPartitionInfo.getTopic()));
    }
  } catch (Exception e) {
    LOGGER.error("Got error during processing Put request", e);
    getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
    return new StringRepresentation(
        String.format("Failed to expand topic, with exception: %s", e));
  }
}
 
Example 3
Source File: SearchSemantic.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 4
Source File: EventsEid.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 5
Source File: ObjectsOidEventsEid.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 6
Source File: ObjectsOidActionsAidTasksTid.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 7
Source File: ObjectsOidPropertiesPid.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 8
Source File: ObjectsOidProperties.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 9
Source File: ObjectsOidEvents.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 10
Source File: ObjectsOidActions.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 11
Source File: SearchSparql.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 12
Source File: ObjectsOid.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 13
Source File: ObjectsOidActionsAid.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 14
Source File: ProjectEditionResource.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
@Put
public Representation editProject(Representation entity) {
	try {
		Platform platform = Platform.getInstance();
		ObjectMapper mapper = new ObjectMapper();

		String j = entity.getText();

		JsonNode json = mapper.readTree(j);
		String sortName = json.get("shortName").asText();

		// Retrieve the older project
		ProjectRepository projectRepo = platform.getProjectRepositoryManager().getProjectRepository();
		Project project = projectRepo.getProjects().findOneByShortName(sortName);
		
		if (project instanceof GitHubRepository) {
			this.editGithubProject(json, project);
		} else if (project instanceof GitLabRepository) {
			this.editGitlabProject(json, project);
		} else if (project instanceof EclipseProject) {
			this.editEclipseProject(json, project);
		} else {
			this.editProject(json, project);
		}

		platform.getProjectRepositoryManager().getProjectRepository().getProjects().sync();

		getResponse().setStatus(Status.SUCCESS_CREATED);
		return new StringRepresentation(project.getDbObject().toString());

	} catch (IOException e) {
		e.printStackTrace(); // TODO
		StringRepresentation rep = new StringRepresentation(
				"{\"status\":\"error\", \"message\" : \"" + e.getMessage() + "\"}");
		rep.setMediaType(MediaType.APPLICATION_JSON);
		getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
		return rep;
	}
}