org.osgi.framework.dto.ServiceReferenceDTO#org.restlet.data.Method源码实例Demo

下面列出了org.osgi.framework.dto.ServiceReferenceDTO#org.restlet.data.Method 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: scava   文件: ApiHelper.java
public Response createTask(String projectId, String taskId, String label, AnalysisExecutionMode mode,
		List<String> metrics, String start, String end) {
	Request request = new Request(Method.POST, "http://localhost:8182/analysis/task/create");

	ObjectMapper mapper = new ObjectMapper();
	ObjectNode n = mapper.createObjectNode();
	n.put("analysisTaskId", taskId);
	n.put("label", label);
	n.put("type", mode.name());
	n.put("startDate", start);
	n.put("endDate", end);
	n.put("projectId", projectId);
	ArrayNode arr = n.putArray("metricProviders");
	for (String m : metrics)
		arr.add(m);

	request.setEntity(n.toString(), MediaType.APPLICATION_JSON);

	return client.handle(request);
}
 
源代码2 项目: scava   文件: TestProjectImportResource.java
@Test
public void testEclipse() {
	Client client = new Client(Protocol.HTTP);
	Request request = new Request(Method.POST, "http://localhost:8182/projects/import");
	
	ObjectMapper mapper = new ObjectMapper();
	ObjectNode n = mapper.createObjectNode();
	n.put("url", "https://projects.eclipse.org/projects/modeling.epsilon");
	
	request.setEntity(n.toString(), MediaType.APPLICATION_JSON);
	
	Response response = client.handle(request);
	
	validateResponse(response, 201);
	
	System.out.println(response.getEntityAsText());
}
 
源代码3 项目: scava   文件: TestProjectImportResource.java
@Test
public void testGitHub() {
	Client client = new Client(Protocol.HTTP);
	Request request = new Request(Method.POST, "http://localhost:8182/projects/import");
	
	ObjectMapper mapper = new ObjectMapper();
	ObjectNode n = mapper.createObjectNode();
	n.put("url", "https://github.com/jrwilliams/gif-hook");
	
	request.setEntity(n.toString(), MediaType.APPLICATION_JSON);
	
	Response response = client.handle(request);
	
	validateResponse(response, 201);
	
	System.out.println(response.getEntityAsText());
}
 
源代码4 项目: helix   文件: AdminTestHelper.java
public static ZNRecord post(Client client, String url, String body)
    throws IOException {
  Reference resourceRef = new Reference(url);
  Request request = new Request(Method.POST, resourceRef);

  request.setEntity(body, MediaType.APPLICATION_ALL);

  Response response = client.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Representation result = response.getEntity();
  StringWriter sw = new StringWriter();

  if (result != null) {
    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;
}
 
源代码5 项目: ontopia   文件: AbstractResourceTest.java
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() + "]");
	}
}
 
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
   if (requestObject == null)
   {
      if (!Method.GET.equals(request.getMethod()))
         request.setEntity(new EmptyRepresentation());

      return true;
   }

   if (requestObject instanceof Representation)
   {
      request.setEntity((Representation) requestObject);
      return true;
   }

   for (RequestWriter requestWriter : requestWriters)
   {
      if (requestWriter.writeRequest(requestObject, request))
         return true;
   }

   return false;
}
 
@Test
public void getMethodReturnsSuccessStatus() throws Exception {

  // Rarely used Teapot Code to check.
  final Boolean successStatusIs200 = true;

  final ServiceEnabledCommand operation = mockedOperation(HttpMethod.GET, successStatusIs200);

  classUnderTest = new GeoWaveOperationServiceWrapper(operation, null);
  classUnderTest.setResponse(new Response(null));
  classUnderTest.setRequest(new Request(Method.GET, "foo.bar"));
  classUnderTest.restGet();
  Assert.assertEquals(
      successStatusIs200,
      classUnderTest.getResponse().getStatus().equals(Status.SUCCESS_OK));
}
 
源代码8 项目: scava   文件: ApiHelper.java
public Response setProperty(String key, String value) {
	Request request = new Request(Method.POST, "http://localhost:8182/platform/properties/create");

	ObjectMapper mapper = new ObjectMapper();
	ObjectNode n = mapper.createObjectNode();
	n.put("key", key);
	n.put("value", value);

	request.setEntity(n.toString(), MediaType.APPLICATION_JSON);

	return client.handle(request);
}
 
源代码9 项目: scava   文件: ApiHelper.java
public Response importProject(String url) {
	Request request = new Request(Method.POST, "http://localhost:8182/projects/import");

	ObjectMapper mapper = new ObjectMapper();
	ObjectNode n = mapper.createObjectNode();
	n.put("url", url);

	request.setEntity(n.toString(), MediaType.APPLICATION_JSON);

	return client.handle(request);
}
 
源代码10 项目: scava   文件: ApiHelper.java
public Response startTask(String taskId) {
	Request request = new Request(Method.POST, "http://localhost:8182/analysis/task/start");

	ObjectMapper mapper = new ObjectMapper();
	ObjectNode n = mapper.createObjectNode();
	n.put("analysisTaskId", taskId);

	request.setEntity(n.toString(), MediaType.APPLICATION_JSON);

	return client.handle(request);
}
 
源代码11 项目: scava   文件: TestProjectResource.java
@Test
public void testPostInsert() throws Exception {
	Request request = new Request(Method.POST, "http://localhost:8182/projects/");

	ObjectMapper mapper = new ObjectMapper();
	
	ObjectNode p = mapper.createObjectNode();
	p.put("name", "test");
	p.put("shortName", "test-short");
	p.put("description", "this is a description");

	request.setEntity(p.toString(), MediaType.APPLICATION_JSON);
	
	Client client = new Client(Protocol.HTTP);
	Response response = client.handle(request);
	
	System.out.println(response.getEntity().getText() + " " + response.isEntityAvailable());
	
	validateResponse(response, 201);
	
	// Now try again, it should fail
	response = client.handle(request);
	validateResponse(response, 409);
	
	// Clean up
	Mongo mongo = new Mongo();
	DB db = mongo.getDB("scava");
	DBCollection col = db.getCollection("projects");
	BasicDBObject query = new BasicDBObject("name", "test");
	col.remove(query);

	mongo.close();
}
 
源代码12 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getHealthCheck() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/health"
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
源代码13 项目: helix   文件: TestClusterManagementWebapp.java
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;
}
 
源代码14 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getTopicExternalViewRequestUrl(String topic) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
源代码15 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getTopicDeleteRequestUrl(String topic, String src, String dst) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic, "?src=", src, "&dst=", dst
  });

  Request request = new Request(Method.DELETE, requestUrl);
  return request;
}
 
源代码16 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getTopicCreationRequestUrl(String topic, String src, String dst) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic, "?src=", src, "&dst=", dst
  });

  Request request = new Request(Method.POST, requestUrl);

  return request;
}
 
源代码17 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getTopicExpansionRequestUrl(String topic, String src, String dst, int numPartitions) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic, "?src=", src, "&dst=", dst, "&partitions=", String.valueOf(numPartitions)
  });

  Request request = new Request(Method.PUT, requestUrl);

  return request;
}
 
源代码18 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request postSetControllerRebalance(String srcCluster, String dstCluster, boolean enabled) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/admin/controller_autobalancing?srcCluster="+ srcCluster + "&dstCluster=" + dstCluster
      + "&enabled=" + enabled
  });
  Request request = new Request(Method.POST, requestUrl);
  return request;
}
 
源代码19 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request postSetControllerRebalance(boolean enabled) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/admin/controller_autobalancing?enabled=" + enabled
  });
  Request request = new Request(Method.POST, requestUrl);
  return request;
}
 
源代码20 项目: helix   文件: TestHelixAdminScenariosRest.java
@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()));
}
 
源代码21 项目: uReplicator   文件: ControllerRequestURLBuilder.java
public Request getTopicDeleteRequestUrl(String topic) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic
  });

  Request request = new Request(Method.DELETE, requestUrl);
  return request;
}
 
源代码22 项目: uReplicator   文件: ControllerRequestURLBuilder.java
public Request getWorkloadInfoUrl() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/admin/workloadinfo"
  });
  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
源代码23 项目: uReplicator   文件: ControllerRequestURLBuilder.java
public Request postBlacklistRequestUrl(String topic, String partition, String opt) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, String.format("/blacklist?topic=%s&partition=%s&opt=%s", topic, partition, opt)
  });
  Request request = new Request(Method.POST, requestUrl);
  return request;
}
 
源代码24 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getHealthCheck() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/health"
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
源代码25 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getTopicExternalViewRequestUrl(String topic) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic
  });

  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
源代码26 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getTopicDeleteRequestUrl(String topic, String src, String dst) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic, "?src=", src, "&dst=", dst
  });

  Request request = new Request(Method.DELETE, requestUrl);
  return request;
}
 
源代码27 项目: uReplicator   文件: ManagerRequestURLBuilder.java
public Request getTopicCreationRequestUrl(String topic, String src, String dst) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic, "?src=", src, "&dst=", dst
  });

  Request request = new Request(Method.POST, requestUrl);

  return request;
}
 
源代码28 项目: lucene-solr   文件: BaseSolrResource.java
/** Called by Restlet to get the response body */
@Override
public void write(OutputStream outputStream) throws IOException {
  if (getRequest().getMethod() != Method.HEAD) {
    QueryResponseWriterUtil.writeQueryResponse(outputStream, responseWriter, solrRequest, solrResponse, contentType);
  }
}
 
源代码29 项目: concierge   文件: RestClientImpl.java
/**
 * @see org.osgi.rest.client.RestClient#getFrameworkStartLevel()
 */
public FrameworkStartLevelDTO getFrameworkStartLevel() throws Exception {
	final Representation repr = new ClientResource(Method.GET,
			baseUri.resolve("framework/startlevel"))
			.get(FRAMEWORK_STARTLEVEL);

	return DTOReflector.getDTO(FrameworkStartLevelDTO.class, repr);
}
 
源代码30 项目: concierge   文件: RestClientImpl.java
/**
 * @see org.osgi.rest.client.RestClient#setFrameworkStartLevel(org.osgi.dto.framework
 *      .startlevel.FrameworkStartLevelDTO)
 */
public void setFrameworkStartLevel(final FrameworkStartLevelDTO startLevel)
		throws Exception {
	new ClientResource(Method.PUT, baseUri.resolve("framework/startlevel")).put(
			DTOReflector.getJson(FrameworkStartLevelDTO.class, startLevel),
			FRAMEWORK_STARTLEVEL);
}