當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。