Java Code Examples for org.restlet.Client#handle()
The following examples show how to use
org.restlet.Client#handle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdminTestHelper.java From helix with Apache License 2.0 | 7 votes |
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; }
Example 2
Source File: TestProjectImportResource.java From scava with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example 3
Source File: TestProjectImportResource.java From scava with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example 4
Source File: AdminTestHelper.java From helix with Apache License 2.0 | 6 votes |
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; }
Example 5
Source File: TestClusterManagementWebapp.java From helix with Apache License 2.0 | 6 votes |
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); }
Example 6
Source File: TestProjectResource.java From scava with Eclipse Public License 2.0 | 5 votes |
@Test public void testGet() { Client client = new Client(Protocol.HTTP); Request request = new Request(Method.GET, "http://localhost:8182/projects/p/ant"); Response response = client.handle(request); validateResponse(response, 200); // TODO: check the JSON }
Example 7
Source File: TestProjectResource.java From scava with Eclipse Public License 2.0 | 5 votes |
@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(); }
Example 8
Source File: TestClusterManagementWebapp.java From helix with Apache License 2.0 | 5 votes |
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; }
Example 9
Source File: AdminTestHelper.java From helix with Apache License 2.0 | 4 votes |
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); }