本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}