Java Code Examples for org.restlet.resource.ClientResource#get()

The following examples show how to use org.restlet.resource.ClientResource#get() . 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: TestGetAllUsers.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	ClientResource client = new ClientResource("http://localhost:8889/foxbpm-webapps-base/service/identity/allUsers");
	client.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "111", "111");
	Representation result = client.get();
	try {
		BufferedReader br = new BufferedReader(result.getReader());
		String line = null;
		while ((line = br.readLine()) != null) {
			System.out.println(line);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	
}
 
Example 3
Source File: RestClientImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.osgi.rest.client.RestClient#getBundles()
 */
public Collection<String> getBundlePaths() throws Exception {
	final ClientResource res = new ClientResource(Method.GET,
			baseUri.resolve("framework/bundles"));
	final Representation repr = res.get(BUNDLES);

	return DTOReflector.getStrings(repr);
}
 
Example 4
Source File: RestClientImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.osgi.rest.client.RestClient#getServices(java.lang.String)
 */
public Collection<String> getServicePaths(final String filter) throws Exception {
	final ClientResource res = new ClientResource(Method.GET,
			baseUri.resolve("framework/services"));

	if (filter != null) {
		res.getQuery().add("filter", filter);
	}

	final Representation repr = res.get(SERVICES);

	return DTOReflector.getStrings(repr);
}
 
Example 5
Source File: RestClientImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.osgi.rest.client.RestClient#getServiceRepresentations(java.lang.String
 *      )
 */
public Collection<ServiceReferenceDTO> getServiceReferences(
		final String filter) throws Exception {
	final ClientResource res = new ClientResource(Method.GET,
			baseUri.resolve("framework/services/representations"));
	if (filter != null) {
		res.getQuery().add("filter", filter);
	}
	final Representation repr = res.get(SERVICES_REPRESENTATIONS);

	return DTOReflector.getDTOs(ServiceReferenceDTO.class, repr);
}
 
Example 6
Source File: XEBatchSolverSaver.java    From unitime with Apache License 2.0 5 votes vote down vote up
protected XEInterface.RegisterResponse getSchedule(Student student, ClientResource resource) throws IOException {
	try {
		resource.get(MediaType.APPLICATION_JSON);
	} catch (ResourceException e) {
		handleError(resource, e);
	}
	
	List<XEInterface.RegisterResponse> current = new GsonRepresentation<List<XEInterface.RegisterResponse>>(resource.getResponseEntity(), XEInterface.RegisterResponse.TYPE_LIST).getObject();
	XEInterface.RegisterResponse original = null;
    if (current != null && !current.isEmpty())
    	original = current.get(0);
    
    if (original == null || !original.validStudent) {
    	String reason = null;
    	if (original != null && original.failureReasons != null) {
    		for (String m: original.failureReasons) {
    			if ("Holds prevent registration.".equals(m) && iHoldPassword != null && !iHoldPassword.isEmpty())
    				return getHoldSchedule(student, resource);
    			if ("Invalid or undefined Enrollment Status or date range invalid.".equals(m) && iRegistrationDate != null && !iRegistrationDate.isEmpty())
    				return getHoldSchedule(student, resource);
    			if (m != null) reason = m;
	    	}	
    	}
    	if (reason != null) throw new SectioningException(reason);
    	throw new SectioningException("Failed to check student registration status.");
    }
    
    return original;
}
 
Example 7
Source File: TestBizDataObjectResouce.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	ClientResource client = new ClientResource("http://localhost:8889/foxbpm-webapps-base/service/bizDataObjects/dataBaseMode/foxbpmDataSource");
	client.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "111", "111");
	Representation result = client.get();
	try {
		BufferedReader br = new BufferedReader(result.getReader());
		String line = null;
		while ((line = br.readLine()) != null) {
			System.out.println(line);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	
}
 
Example 8
Source File: RestRequestByRestlet.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    ClientResource resource = new ClientResource(REST_URI);

    // 设置Base Auth认证
    resource.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "kermit", "kermit");

    Representation representation = resource.get();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(representation.getStream());
    Iterator<String> fieldNames = jsonNode.fieldNames();
    while (fieldNames.hasNext()) {
        String fieldName = fieldNames.next();
        System.out.println(fieldName + " : " + jsonNode.get(fieldName));
    }
}
 
Example 9
Source File: UIDesignerServerManager.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void connectToURL(final URL url) throws URISyntaxException {
    ClientResource cr = new ClientResource(url.toURI());
    cr.setRetryOnError(true);
    cr.setRetryDelay(500);
    cr.setRetryAttempts(120);
    cr.get();
}
 
Example 10
Source File: WebPageFileStore.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public Collection<String> getPageResources() {
    try {
        ClientResource clientResource = new ClientResource(
                PageDesignerURLFactory.INSTANCE.resources(getId()).toURI());
        clientResource.getLogger().setLevel(Level.OFF);
        final Representation representation = clientResource.get();
        return representation != null ? parseExtensionResources( representation.getText() ) : Collections.emptyList();
    } catch (URISyntaxException | IOException e) {
        BonitaStudioLog.error(e);
        return null;
    }
}
 
Example 11
Source File: CustomPageBarResourceFactory.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected InputStream get(final String exportURL) throws IOException {
    ClientResource clientResource = new ClientResource(exportURL);
    clientResource.getLogger().setLevel(Level.OFF);
    final Representation representation = clientResource.get();
    return representation != null && representation.isAvailable() ? representation.getStream() : null;
}
 
Example 12
Source File: NeighbourhoodManagerConnector.java    From vicinity-gateway-api with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Retrieves the list of IoT objects registered under given Agent from the Neighbourhood Manager. 
 * 
 * @param agid The ID of the Agent in question.
 * @return All VICINITY identifiers of objects registered under specified agent.
 */
public synchronized Representation getAgentObjects(String agid){
	
	String endpointUrl = SERVER_PROTOCOL + neighbourhoodManagerServer + ":" + port + API_PATH + DISCOVERY_SERVICE_1 + agid + DISCOVERY_SERVICE_2;
	
	ClientResource clientResource = createRequest(endpointUrl);
	
	Representation representation = clientResource.get(MediaType.APPLICATION_JSON);
	
	return representation;

}