Search in sources :

Example 31 with Reference

use of org.restlet.data.Reference in project lucene-solr by apache.

the class TestRestManager method testResolveResourceIdDecodeUrlEntities.

@Test
public void testResolveResourceIdDecodeUrlEntities() throws Exception {
    Request testRequest = new Request();
    Reference rootRef = new Reference("http://solr.apache.org/");
    testRequest.setRootRef(rootRef);
    Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de/%C3%84ndern");
    testRequest.setResourceRef(resourceRef);
    String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
    assertEquals(resourceId, "/schema/analysis/synonyms/de/Ă„ndern");
}
Also used : Reference(org.restlet.data.Reference) Request(org.restlet.Request) Test(org.junit.Test)

Example 32 with Reference

use of org.restlet.data.Reference in project helix by apache.

the class AdminTestHelper method get.

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;
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) Reference(org.restlet.data.Reference) Request(org.restlet.Request) StringReader(java.io.StringReader) Representation(org.restlet.representation.Representation) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ZNRecord(org.apache.helix.ZNRecord)

Example 33 with Reference

use of org.restlet.data.Reference in project helix by apache.

the class AdminTestHelper method post.

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;
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) Reference(org.restlet.data.Reference) Request(org.restlet.Request) StringReader(java.io.StringReader) Representation(org.restlet.representation.Representation) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ZNRecord(org.apache.helix.ZNRecord)

Example 34 with Reference

use of org.restlet.data.Reference in project helix by apache.

the class TestClusterManagementWebapp method get.

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;
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) Reference(org.restlet.data.Reference) TypeReference(org.codehaus.jackson.type.TypeReference) Request(org.restlet.Request) StringReader(java.io.StringReader) Representation(org.restlet.representation.Representation) ZNRecord(org.apache.helix.ZNRecord)

Example 35 with Reference

use of org.restlet.data.Reference in project helix by apache.

the class TestClusterManagementWebapp method verifyAddInstance.

void verifyAddInstance() throws JsonGenerationException, JsonMappingException, IOException {
    String httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/instances";
    Map<String, String> paraMap = new HashMap<String, String>();
    // Add 1 instance
    paraMap.put(JsonParameters.INSTANCE_NAME, instance1 + ":" + instancePort);
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
    Reference resourceRef = new Reference(httpUrlBase);
    Request request = new Request(Method.POST, resourceRef);
    request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paraMap), MediaType.APPLICATION_ALL);
    Response response = _gClient.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    // System.out.println(sw.toString());
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<ListInstancesWrapper> typeRef = new TypeReference<ListInstancesWrapper>() {
    };
    ListInstancesWrapper wrapper = mapper.readValue(new StringReader(sw.toString()), typeRef);
    List<ZNRecord> znList = wrapper.instanceInfo;
    AssertJUnit.assertTrue(znList.get(0).getId().equals(instance1 + "_" + instancePort));
    // the case to add more than 1 instances
    paraMap.clear();
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
    String[] instances = { "test2", "test3", "test4", "test5" };
    String instanceNames = "";
    boolean first = true;
    for (String instance : instances) {
        if (first == true) {
            first = false;
        } else {
            instanceNames += ";";
        }
        instanceNames += (instance + ":" + instancePort);
    }
    paraMap.put(JsonParameters.INSTANCE_NAMES, instanceNames);
    request = new Request(Method.POST, resourceRef);
    request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paraMap), MediaType.APPLICATION_ALL);
    response = _gClient.handle(request);
    result = response.getEntity();
    sw = new StringWriter();
    result.write(sw);
    // System.out.println(sw.toString());
    mapper = new ObjectMapper();
    wrapper = mapper.readValue(new StringReader(sw.toString()), typeRef);
    znList = wrapper.instanceInfo;
    for (String instance : instances) {
        boolean found = false;
        for (ZNRecord r : znList) {
            String instanceId = instance + "_" + instancePort;
            if (r.getId().equals(instanceId)) {
                found = true;
                break;
            }
        }
        AssertJUnit.assertTrue(found);
    }
}
Also used : HashMap(java.util.HashMap) Reference(org.restlet.data.Reference) TypeReference(org.codehaus.jackson.type.TypeReference) Request(org.restlet.Request) Representation(org.restlet.representation.Representation) Response(org.restlet.Response) ListInstancesWrapper(org.apache.helix.webapp.resources.InstancesResource.ListInstancesWrapper) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) TypeReference(org.codehaus.jackson.type.TypeReference) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ZNRecord(org.apache.helix.ZNRecord)

Aggregations

Reference (org.restlet.data.Reference)46 Request (org.restlet.Request)26 Response (org.restlet.Response)26 Representation (org.restlet.representation.Representation)19 StringWriter (java.io.StringWriter)15 HashMap (java.util.HashMap)11 ZNRecord (org.apache.helix.ZNRecord)11 StringReader (java.io.StringReader)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 ResourceException (org.restlet.resource.ResourceException)8 Form (org.restlet.data.Form)5 IOException (java.io.IOException)3 Date (java.util.Date)3 Test (org.junit.Test)3 ContextResourceClient (org.qi4j.library.rest.client.api.ContextResourceClient)3 ContextResourceClientFactory (org.qi4j.library.rest.client.api.ContextResourceClientFactory)3 ErrorHandler (org.qi4j.library.rest.client.api.ErrorHandler)3 HandlerCommand (org.qi4j.library.rest.client.api.HandlerCommand)3 ResponseHandler (org.qi4j.library.rest.client.spi.ResponseHandler)3