当前位置: 首页>>代码示例>>Java>>正文


Java Client.handle方法代码示例

本文整理汇总了Java中org.restlet.Client.handle方法的典型用法代码示例。如果您正苦于以下问题:Java Client.handle方法的具体用法?Java Client.handle怎么用?Java Client.handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.restlet.Client的用法示例。


在下文中一共展示了Client.handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import org.restlet.Client; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:helix,代码行数:17,代码来源:AdminTestHelper.java

示例2: post

import org.restlet.Client; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:helix,代码行数:24,代码来源:AdminTestHelper.java

示例3: postConfig

import org.restlet.Client; //导入方法依赖的package包/类
private void postConfig(Client client, String url, ObjectMapper mapper, String command,
    String configs) throws Exception {
  Map<String, String> params = new HashMap<String, String>();

  params.put(JsonParameters.MANAGEMENT_COMMAND, command);
  params.put(JsonParameters.CONFIGS, configs);

  Request request = new Request(Method.POST, new Reference(url));
  request.setEntity(
      JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(params),
      MediaType.APPLICATION_ALL);

  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);
}
 
开发者ID:apache,项目名称:helix,代码行数:21,代码来源:TestClusterManagementWebapp.java

示例4: testConsumer

import org.restlet.Client; //导入方法依赖的package包/类
@Test
public void testConsumer() throws IOException {
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(new Request(Method.GET, 
        "http://localhost:" + portNum + "/orders/99991/6"));
    assertEquals("received GET request with id=99991 and x=6",
        response.getEntity().getText());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:RestletRouteBuilderTest.java

示例5: testConsumerWithSpaces

import org.restlet.Client; //导入方法依赖的package包/类
@Test
public void testConsumerWithSpaces() throws IOException {
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(new Request(Method.GET, 
        "http://localhost:" + portNum + "/orders with spaces in path/99991/6"));
    assertEquals("received GET request with id=99991 and x=6",
        response.getEntity().getText());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:RestletRouteBuilderTest.java

示例6: testUnhandledConsumer

import org.restlet.Client; //导入方法依赖的package包/类
@Test
public void testUnhandledConsumer() throws IOException {
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(new Request(Method.POST, 
        "http://localhost:" + portNum + "/orders/99991/6"));
    // expect error status as no Restlet consumer to handle POST method
    assertEquals(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED, response.getStatus());
    assertNotNull(response.getEntity().getText());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:RestletRouteBuilderTest.java

示例7: testNotFound

import org.restlet.Client; //导入方法依赖的package包/类
@Test
public void testNotFound() throws IOException {
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(new Request(Method.POST,
        "http://localhost:" + portNum + "/unknown"));
    // expect error status as no Restlet consumer to handle POST method
    assertEquals(Status.CLIENT_ERROR_NOT_FOUND, response.getStatus());
    assertNotNull(response.getEntity().getText());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:RestletRouteBuilderTest.java

示例8: getRequestResult

import org.restlet.Client; //导入方法依赖的package包/类
private Response getRequestResult(String path) {
    Client client =  new Client(Protocol.HTTP);
    Request request = new Request(Method.GET, serverUrl+path);
    Response response = client.handle(request);
    String s = response.getEntityAsText();
    return response;
}
 
开发者ID:eternnoir,项目名称:MCRest,代码行数:8,代码来源:AuthResourceTest.java

示例9: getRequestResultWithAuth

import org.restlet.Client; //导入方法依赖的package包/类
private Response getRequestResultWithAuth(String path,String user,String password){
    Request request = new Request(Method.GET, serverUrl+path);
    Client client = new Client(Protocol.HTTP);

    ChallengeResponse authentication = new ChallengeResponse(
            ChallengeScheme.HTTP_BASIC, user, password);
    request.setChallengeResponse(authentication);

    Response response = client.handle(request);
    return response;
}
 
开发者ID:eternnoir,项目名称:MCRest,代码行数:12,代码来源:AuthResourceTest.java

示例10: testUploadBogusData

import org.restlet.Client; //导入方法依赖的package包/类
@Test
public void testUploadBogusData() {
  Client client = new Client(Protocol.HTTP);
  Request request =
      new Request(Method.POST, ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forDataFileUpload());
  request.setEntity("blah", MediaType.MULTIPART_ALL);
  Response response = client.handle(request);

  Assert.assertEquals(response.getStatus(), Status.SERVER_ERROR_INTERNAL);
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:11,代码来源:PinotFileUploadTest.java

示例11: get

import org.restlet.Client; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:helix,代码行数:14,代码来源:TestClusterManagementWebapp.java

示例12: something

import org.restlet.Client; //导入方法依赖的package包/类
public void something() throws IOException {
	Request request = new Request(Method.GET, requestUrl);
	Client client = new Client(Protocol.HTTP);

	Response response = client.handle(request);
	Representation representation = response.getEntity();
	System.out.println("http response: " +response.getStatus().getCode()+" "+response.getStatus().getDescription());
	System.out.println("text: \n"+representation.getText());
	
}
 
开发者ID:paulkling,项目名称:checklooks,代码行数:11,代码来源:TestHttpGet.java

示例13: testGetTemperature

import org.restlet.Client; //导入方法依赖的package包/类
@Test
public void testGetTemperature() {
	// Arrange
	doReturn(17.5f).when(tempSensor).getLastReading();
	
	Request request = new Request(Method.GET, "https://localhost:8111/garage/beer/fermenter/temperature");
	
	// Act
	Client client = new Client(Protocol.HTTP);
	Response response = client.handle(request);
	
	// Assert
	assertTrue(response.getStatus().isSuccess());
	assertEquals("{\"TemperatureSensor.temperature\":\"17.5\"}", response.getEntityAsText());
}
 
开发者ID:sebykrueger,项目名称:PiBeerController,代码行数:16,代码来源:BeerServerComponentTest.java

示例14: testGetHeatbeltStatus

import org.restlet.Client; //导入方法依赖的package包/类
@Test
public void testGetHeatbeltStatus() {
	// Arrange
	doReturn(State.OFF).when(powerSwitch).getPinState();
	
	Request request = new Request(Method.GET, "https://localhost:8111/garage/beer/heatbelt/status");
	
	// Act
	Client client = new Client(Protocol.HTTP);
	Response response = client.handle(request);
	
	// Assert
	assertTrue(response.getStatus().isSuccess());
	assertEquals("{\"PowerSwitch.status\":\"OFF\"}", response.getEntityAsText());
}
 
开发者ID:sebykrueger,项目名称:PiBeerController,代码行数:16,代码来源:BeerServerComponentTest.java

示例15: delete

import org.restlet.Client; //导入方法依赖的package包/类
public static void delete(Client client, String url) throws IOException {
  Reference resourceRef = new Reference(url);
  Request request = new Request(Method.DELETE, resourceRef);
  Response response = client.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_NO_CONTENT);
}
 
开发者ID:apache,项目名称:helix,代码行数:7,代码来源:AdminTestHelper.java


注:本文中的org.restlet.Client.handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。