Java Code Examples for org.restlet.data.Method#GET

The following examples show how to use org.restlet.data.Method#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: AdminTestHelper.java    From helix with Apache License 2.0 6 votes vote down vote up
public static ZNRecord get(Client client, String url) throws IOException {
  Reference resourceRef = new Reference(url);
  Request request = new Request(Method.GET, resourceRef);
  Response response = client.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Representation result = response.getEntity();
  StringWriter sw = new StringWriter();
  result.write(sw);

  String responseStr = sw.toString();
  Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
  Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
  ObjectMapper mapper = new ObjectMapper();
  ZNRecord record = mapper.readValue(new StringReader(responseStr), ZNRecord.class);
  return record;
}
 
Example 2
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 3
Source File: TestClusterManagementWebapp.java    From helix with Apache License 2.0 5 votes vote down vote up
private ZNRecord get(Client client, String url, ObjectMapper mapper) throws Exception {
  Request request = new Request(Method.GET, new Reference(url));
  Response response = client.handle(request);
  Representation result = response.getEntity();
  StringWriter sw = new StringWriter();
  result.write(sw);
  String responseStr = sw.toString();
  Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
  Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);

  ZNRecord record = mapper.readValue(new StringReader(responseStr), ZNRecord.class);
  return record;
}
 
Example 4
Source File: TestHelixAdminScenariosRest.java    From helix with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetResources() throws IOException {
  final String clusterName = "TestTagAwareness_testGetResources";
  final String TAG = "tag";
  final String URL_BASE =
      "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";

  _gSetupTool.addCluster(clusterName, true);
  HelixAdmin admin = _gSetupTool.getClusterManagementTool();

  // Add a tagged resource
  IdealState taggedResource = new IdealState("taggedResource");
  taggedResource.setInstanceGroupTag(TAG);
  taggedResource.setStateModelDefRef("OnlineOffline");
  admin.addResource(clusterName, taggedResource.getId(), taggedResource);

  // Add an untagged resource
  IdealState untaggedResource = new IdealState("untaggedResource");
  untaggedResource.setStateModelDefRef("OnlineOffline");
  admin.addResource(clusterName, untaggedResource.getId(), untaggedResource);

  // Now make a REST call for all resources
  Reference resourceRef = new Reference(URL_BASE);
  Request request = new Request(Method.GET, resourceRef);
  Response response = _gClient.handle(request);
  ZNRecord responseRecord =
      ClusterRepresentationUtil.JsonToObject(ZNRecord.class, response.getEntityAsText());

  // Ensure that the tagged resource has information and the untagged one doesn't
  Assert.assertNotNull(responseRecord.getMapField("ResourceTags"));
  Assert
      .assertEquals(TAG, responseRecord.getMapField("ResourceTags").get(taggedResource.getId()));
  Assert.assertFalse(responseRecord.getMapField("ResourceTags").containsKey(
      untaggedResource.getId()));
}
 
Example 5
Source File: TestHelixAdminScenariosRest.java    From helix with Apache License 2.0 5 votes vote down vote up
String getUrl(String url) throws IOException {
  Reference resourceRef = new Reference(url);
  Request request = new Request(Method.GET, resourceRef);
  Response response = _gClient.handle(request);
  Representation result = response.getEntity();
  StringWriter sw = new StringWriter();
  result.write(sw);
  return sw.toString();
}
 
Example 6
Source File: HeaderTest.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeaders() {
	OntopiaTestResource request = new OntopiaTestResource(Method.GET, getUrl(null), defaultMediatype);
	request.request();
	Series<Header> headers = request.getResponse().getHeaders();

	Assert.assertNotNull(headers);
	Assert.assertEquals("v1", headers.getFirstValue("X-Ontopia-API-Version"));
	Assert.assertEquals("n.o.t.r.OntopiaRestApplication", headers.getFirstValue("X-Ontopia-Application"));
	Assert.assertEquals("n.o.t.r.v1.topic.TopicsResource", headers.getFirstValue("X-Ontopia-Resource"));
	Assert.assertEquals("topics.ltm", headers.getFirstValue("X-Ontopia-Topicmap"));
}
 
Example 7
Source File: ContextResourceClient.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private HandlerCommand invokeQuery( Reference ref, Object queryRequest, ResponseHandler resourceHandler, ResponseHandler processingErrorHandler )
{
    Request request = new Request( Method.GET, ref );

    if( queryRequest != null )
    {
        contextResourceFactory.writeRequest( request, queryRequest );
    }

    contextResourceFactory.updateQueryRequest( request );

    User user = request.getClientInfo().getUser();
    if ( user != null)
        request.setChallengeResponse( new ChallengeResponse( ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret() ) );

    Response response = new Response( request );

    contextResourceFactory.getClient().handle( request, response );

    if( response.getStatus().isSuccess() )
    {
        contextResourceFactory.updateCache( response );

        return resourceHandler.handleResponse( response, this );
    } else if (response.getStatus().isRedirection())
    {
        Reference redirectedTo = response.getLocationRef();
        return invokeQuery( redirectedTo, queryRequest, resourceHandler, processingErrorHandler );
    } else
    {
        if (response.getStatus().equals(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY) && processingErrorHandler != null)
        {
            return processingErrorHandler.handleResponse( response, this );
        } else
        {
            // TODO This needs to be expanded to allow custom handling of all the various cases
            return errorHandler.handleResponse( response, this );
        }
    }
}
 
Example 8
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 9
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 10
Source File: TestProjectResource.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGet() {
	Client client = new Client(Protocol.HTTP);
	Request request = new Request(Method.GET, "http://localhost:8182/projects/p/ant");
	Response response = client.handle(request);
	
	validateResponse(response, 200);
	
	// TODO: check the JSON
}
 
Example 11
Source File: ManagerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getTopicExternalViewRequestUrl(String topic) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 12
Source File: ManagerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getHealthCheck() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/health"
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 13
Source File: ControllerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getWorkloadInfoUrl() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/admin/workloadinfo"
  });
  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 14
Source File: ControllerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getBlacklistRequestUrl() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/blacklist"
  });
  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 15
Source File: ControllerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getNoProgressRequestUrl() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/noprogress"
  });
  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 16
Source File: ControllerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getTopicExternalViewRequestUrl(String topic) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 17
Source File: ManagerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getControllerRebalanceStatus() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/admin/controller_autobalancing"
  });
  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 18
Source File: ManagerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getTopicExternalViewRequestUrl(String topic) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 19
Source File: ManagerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getHealthCheck() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/health"
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example 20
Source File: TestHelixAdminScenariosRest.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetInstances() throws IOException {
  final String clusterName = "TestTagAwareness_testGetResources";
  final String[] TAGS = {
      "tag1", "tag2"
  };
  final String URL_BASE =
      "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/instances";

  _gSetupTool.addCluster(clusterName, true);
  HelixAdmin admin = _gSetupTool.getClusterManagementTool();

  // Add 4 participants, each with differint tag characteristics
  InstanceConfig instance1 = new InstanceConfig("localhost_1");
  instance1.addTag(TAGS[0]);
  admin.addInstance(clusterName, instance1);
  InstanceConfig instance2 = new InstanceConfig("localhost_2");
  instance2.addTag(TAGS[1]);
  admin.addInstance(clusterName, instance2);
  InstanceConfig instance3 = new InstanceConfig("localhost_3");
  instance3.addTag(TAGS[0]);
  instance3.addTag(TAGS[1]);
  admin.addInstance(clusterName, instance3);
  InstanceConfig instance4 = new InstanceConfig("localhost_4");
  admin.addInstance(clusterName, instance4);

  // Now make a REST call for all resources
  Reference resourceRef = new Reference(URL_BASE);
  Request request = new Request(Method.GET, resourceRef);
  Response response = _gClient.handle(request);
  ListInstancesWrapper responseWrapper =
      ClusterRepresentationUtil.JsonToObject(ListInstancesWrapper.class,
          response.getEntityAsText());
  Map<String, List<String>> tagInfo = responseWrapper.tagInfo;

  // Ensure tag ownership is reported correctly
  Assert.assertTrue(tagInfo.containsKey(TAGS[0]));
  Assert.assertTrue(tagInfo.containsKey(TAGS[1]));
  Assert.assertTrue(tagInfo.get(TAGS[0]).contains("localhost_1"));
  Assert.assertFalse(tagInfo.get(TAGS[0]).contains("localhost_2"));
  Assert.assertTrue(tagInfo.get(TAGS[0]).contains("localhost_3"));
  Assert.assertFalse(tagInfo.get(TAGS[0]).contains("localhost_4"));
  Assert.assertFalse(tagInfo.get(TAGS[1]).contains("localhost_1"));
  Assert.assertTrue(tagInfo.get(TAGS[1]).contains("localhost_2"));
  Assert.assertTrue(tagInfo.get(TAGS[1]).contains("localhost_3"));
  Assert.assertFalse(tagInfo.get(TAGS[1]).contains("localhost_4"));
}