org.restlet.Response.getEntityAsText()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(20.4k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中org.restlet.Response.getEntityAsText方法的一些代码示例,展示了Response.getEntityAsText的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getEntityAsText方法的具体详情如下:
包路径:org.restlet.Response
类名称:Response
方法名:getEntityAsText

Response.getEntityAsText介绍

暂无

代码示例

代码示例来源:origin: uber/chaperone

@Test
public void testPost() {
 // Create topic
 Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
   .getTopicCreationRequestUrl("testTopic1", 16);
 Response response = HTTP_CLIENT.handle(request);
 Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
 Assert.assertEquals(response.getEntityAsText(),
   "Successfully add new topic: {topic: testTopic1, partition: 16}");
 Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic1"));
 // Create existed topic
 request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
   .getTopicCreationRequestUrl("testTopic1", 16);
 response = HTTP_CLIENT.handle(request);
 Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
 Assert.assertEquals(response.getEntityAsText(),
   "Failed to add new topic: testTopic1, it is already existed!");
 // Delete topic
 request =
   ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic1");
 response = HTTP_CLIENT.handle(request);
 Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
 Assert.assertEquals(response.getEntityAsText(),
   "Successfully finished delete topic: testTopic1");
}

代码示例来源:origin: uber/chaperone

Response response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully add new topic: {topic: testTopic2, partition: 8}");
Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic2"));
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully expand topic: {topic: testTopic2, partition: 16}");
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(response.getEntityAsText(),
  "Failed to expand topic, topic: testTopic22 is not existed!");
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully finished delete topic: testTopic2");

代码示例来源:origin: uber/chaperone

Response response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(), "No topic is added in MirrorMaker Controller!");
System.out.println(response.getEntityAsText());
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully add new topic: {topic: testTopic0, partition: 8}");
Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic0"));
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(), "Current serving topics: [testTopic0]");
System.out.println(response.getEntityAsText());
try {
 Thread.sleep(4000);
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
JSONObject jsonObject = JSON.parseObject(response.getEntityAsText());
System.out.println(jsonObject);
Assert.assertEquals(jsonObject.getJSONObject("serverToNumPartitionsMapping").size(), 4);
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully finished delete topic: testTopic0");

代码示例来源:origin: uber/chaperone

Response response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully add new topic: {topic: testTopic3, partition: 8}");
Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic3"));
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully finished delete topic: testTopic3");
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(response.getEntityAsText(),
  "Failed to delete not existed topic: testTopic4");

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Test(threadPoolSize = 10, invocationCount = 100, timeOut = 5000)
public void makeCall() {
  Request request = new Request(Method.GET, "http://localhost:8111/");
  Response response = component.handle(request);
  Assert.assertTrue(response.getStatus().isSuccess());
  Assert.assertEquals("Welcome to the RESTful Mail Server application !",
      response.getEntityAsText());
}

代码示例来源:origin: net.smartcosmos/smartcosmos-java-client

protected void throwServiceException(ClientResource service, Exception e) throws ServiceException
  {
    if (e instanceof ResourceException)
    {
      log.error("Unexpected HTTP status code returned: {}", service.getStatus().getCode());
      throwServiceException(service.getResponse().getEntityAsText());
    } else
    {
      log.error("Unexpected Exception", e);
      throw new ServiceException(e);
    }
  }
}

代码示例来源:origin: apache/attic-polygene-java

@Override
  public Object readResponse( Response response, Class<?> resultType ) throws ResourceException
  {
    if( MediaType.APPLICATION_JSON.equals( response.getEntity().getMediaType() ) )
    {
      if( resultType.equals( String.class ) || Number.class.isAssignableFrom( resultType ) )
      {
        try
        {
          return jsonDeserializer.deserialize( module, resultType, response.getEntityAsText() );
        }
        catch( Exception e )
        {
          throw new ResourceException( e );
        }
      }
    }
    return null;
  }
}

代码示例来源:origin: uber/uReplicator

@Test
 public void testHealthCheck() {
  Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).getHealthCheck();
  Response response = HTTP_CLIENT.handle(request);
  String responseString = response.getEntityAsText();
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(responseString, "OK\n");
 }
}

代码示例来源:origin: uber/uReplicator

@Test
public void testGetControllerRebalance() {
 Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).getControllerRebalanceStatus();
 Response response = HTTP_CLIENT.handle(request);
 String responseString = response.getEntityAsText();
 Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
 Assert.assertEquals(responseString, "{}");
}

代码示例来源:origin: uber/uReplicator

@Test
public void testPostRebalance() {
 Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postInstanceRebalance(true);
 Response response = HTTP_CLIENT.handle(request);
 String responseString = response.getEntityAsText();
 Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
 Assert.assertEquals(responseString, "{\"status\":200}");
 request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postInstanceRebalance(false);
 response = HTTP_CLIENT.handle(request);
 responseString = response.getEntityAsText();
 Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_BAD_REQUEST);
 Assert.assertEquals(responseString, "{\"message\":\"invalid operation\",\"status\":400}");
}

代码示例来源:origin: uber/uReplicator

@Test
public void testPostControllerRebalance() {
 Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postSetControllerRebalance(true);
 Response response = HTTP_CLIENT.handle(request);
 String responseString = response.getEntityAsText();
 Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
 Assert.assertEquals(responseString, "{\"execution\":{},\"managerAutoscaling\":true,\"status\":{}}");
 request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postSetControllerRebalance("sjc1a", "sjc1-agg1", true);
 response = HTTP_CLIENT.handle(request);
 responseString = response.getEntityAsText();
 Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
 Assert.assertEquals(responseString, "{\"execution\":{},\"managerAutoscaling\":true,\"status\":{}}");
}
@Test

代码示例来源:origin: uber/uReplicator

@Test
public void testPost() {
 // Create topic
 Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
   .getTopicCreationRequestUrl("testTopic1", 16);
 Response response = HTTP_CLIENT.handle(request);
 Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
 Assert.assertEquals(response.getEntityAsText(),
   "Successfully add new topic: {topic: testTopic1, partition: 16}");
 Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic1"));
 // Create existed topic
 request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
   .getTopicCreationRequestUrl("testTopic1", 16);
 response = HTTP_CLIENT.handle(request);
 Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
 Assert.assertEquals(response.getEntityAsText(),
   "Failed to add new topic: testTopic1, it is already existed!");
 // Delete topic
 request =
   ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic1");
 response = HTTP_CLIENT.handle(request);
 Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
 Assert.assertEquals(response.getEntityAsText(),
   "Successfully finished delete topic: testTopic1");
}

代码示例来源:origin: uber/uReplicator

Response response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully add new topic: {topic: testTopic2, partition: 8}");
Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic2"));
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully expand topic: {topic: testTopic2, partition: 16}");
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(response.getEntityAsText(),
  "Failed to expand topic, topic: testTopic22 is not existed!");
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully finished delete topic: testTopic2");

代码示例来源:origin: uber/uReplicator

JSONObject json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "No topic is added in uReplicator!");
  .getTopicCreationRequestUrl("testTopic0", "cluster2", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(json.getString("message"), "Failed to whitelist topic testTopic0 on uReplicator because of not valid pipeline from cluster2 to cluster3");
  .getTopicCreationRequestUrl("testTopic1", "cluster1", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(json.getString("message"), "Failed to whitelist new topic: testTopic1, it's not existed in source Kafka cluster!");
  .getTopicCreationRequestUrl("testTopic0", "cluster1", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "Failed to add new topic: testTopic0 from: cluster1 to: cluster3, it is already existed!");
  .getTopicDeleteRequestUrl("testTopic0", "cluster1", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "Successfully delete topic: testTopic0 from cluster1 to cluster3");

代码示例来源:origin: uber/uReplicator

JSONObject json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "No topic is added in uReplicator!");
  .getTopicDeleteRequestUrl("testTopic0", "cluster2", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "Failed to delete not existed topic: testTopic0 in pipeline: @cluster2@cluster3");
  .getTopicDeleteRequestUrl("testTopic1", "cluster1", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "Failed to delete not existed topic: testTopic1 in pipeline: @cluster1@cluster3");
  .getTopicDeleteRequestUrl("testTopic0", "cluster1", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "Successfully delete topic: testTopic0 from cluster1 to cluster3");
  .getTopicDeleteRequestUrl("@cluster2@cluster3", "cluster2", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(json.getString("message"), "Failed to delete not existed pipeline: @cluster2@cluster3");
  .getTopicDeleteRequestUrl("@cluster1@cluster3", "cluster1", "cluster3");

代码示例来源:origin: uber/uReplicator

JSONObject json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "No topic is added in uReplicator!");
  .getTopicExpansionRequestUrl("testTopic0", "cluster1", "cluster3", 1);
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(json.getString("message"), "Failed to expand the topic testTopic0 in pipeline @cluster1@cluster3 to 1 partitions due to exception: java.lang.Exception: New partition 1 is not bigger than current partition 1 of topic testTopic0, abandon expanding topic!");
  .getTopicExpansionRequestUrl("testTopic0", "cluster2", "cluster3", 2);
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(json.getString("message"), "Topic testTopic0 doesn't exist in pipeline @cluster2@cluster3, abandon expanding topic!");
  .getTopicExpansionRequestUrl("testTopic1", "cluster1", "cluster3", 2);
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(json.getString("message"), "Topic testTopic1 doesn't exist in pipeline @cluster1@cluster3, abandon expanding topic!");
  .getTopicExpansionRequestUrl("testTopic0", "cluster1", "cluster3", 2);
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "Successfully expand the topic testTopic0 in pipeline @cluster1@cluster3 to 2 partitions");
  .getTopicDeleteRequestUrl("testTopic0", "cluster1", "cluster3");

代码示例来源:origin: uber/uReplicator

JSONObject json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "No topic is added in uReplicator!");
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getJSONObject("message").getString("topics"), "[\"testTopic0\"]");
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getJSONObject("message").getJSONObject("managerView").getString("topic"), "testTopic0");
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(json.getString("message"), "Failed to find topic: testTopic1");
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getJSONObject("message").getString("topic"), "@cluster1@cluster3");
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(json.getString("message"), "Failed to get view for route: @cluster1@cluster4, it is not existed!");
  .getTopicDeleteRequestUrl("testTopic0", "cluster1", "cluster3");
response = HTTP_CLIENT.handle(request);
json = JSONObject.parseObject(response.getEntityAsText());
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(json.getString("message"), "Successfully delete topic: testTopic0 from cluster1 to cluster3");

代码示例来源:origin: uber/uReplicator

Response response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(), "No topic is added in MirrorMaker Controller!");
System.out.println(response.getEntityAsText());
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully add new topic: {topic: testTopic0, partition: 8}");
Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic0"));
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(), "Current serving topics: [testTopic0]");
System.out.println(response.getEntityAsText());
try {
 Thread.sleep(4000);
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
JSONObject jsonObject = JSON.parseObject(response.getEntityAsText());
System.out.println(jsonObject);
Assert.assertEquals(jsonObject.getJSONObject("serverToNumPartitionsMapping").size(), 4);
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully finished delete topic: testTopic0");

代码示例来源:origin: uber/uReplicator

Response response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully add new topic: {topic: testTopic3, partition: 8}");
Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic3"));
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
  "Successfully finished delete topic: testTopic3");
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(response.getEntityAsText(),
  "Failed to delete not existed topic: testTopic4");

代码示例来源:origin: apache/attic-polygene-java

String jsonValue = response.getEntityAsText();
ValueCompositeType valueType = module.valueDescriptor( resultType.getName() ).valueType();
return jsonDeserializer.deserialize( module, valueType, jsonValue );

相关文章