Search in sources :

Example 26 with Response

use of org.restlet.Response in project helix by apache.

the class TestClusterManagementWebapp method verifyAddStateModel.

void verifyAddStateModel() throws JsonGenerationException, JsonMappingException, IOException {
    String httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/StateModelDefs/MasterSlave";
    Reference resourceRef = new Reference(httpUrlBase);
    Request request = new Request(Method.GET, resourceRef);
    Response response = _gClient.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    ObjectMapper mapper = new ObjectMapper();
    ZNRecord zn = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
    Map<String, String> paraMap = new HashMap<String, String>();
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addStateModelDef);
    ZNRecord r = new ZNRecord("Test");
    r.merge(zn);
    httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/StateModelDefs";
    resourceRef = new Reference(httpUrlBase);
    request = new Request(Method.POST, resourceRef);
    request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paraMap) + "&" + JsonParameters.NEW_STATE_MODEL_DEF + "=" + ClusterRepresentationUtil.ZNRecordToJson(r), MediaType.APPLICATION_ALL);
    response = _gClient.handle(request);
    result = response.getEntity();
    sw = new StringWriter();
    result.write(sw);
    // System.out.println(sw.toString());
    AssertJUnit.assertTrue(sw.toString().contains("Test"));
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) Reference(org.restlet.data.Reference) TypeReference(org.codehaus.jackson.type.TypeReference) 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 27 with Response

use of org.restlet.Response in project helix by apache.

the class TestClusterManagementWebapp method verifyEnableCluster.

void verifyEnableCluster() throws Exception {
    System.out.println("START: verifyEnableCluster()");
    String httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/Controller";
    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableCluster);
    paramMap.put(JsonParameters.ENABLED, "" + false);
    Reference resourceRef = new Reference(httpUrlBase);
    Request request = new Request(Method.POST, resourceRef);
    request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paramMap), MediaType.APPLICATION_ALL);
    Response response = _gClient.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    System.out.println(sw.toString());
    // verify pause znode exists
    String pausePath = PropertyPathBuilder.pause(clusterName);
    System.out.println("pausePath: " + pausePath);
    boolean exists = _gZkClient.exists(pausePath);
    Assert.assertTrue(exists, pausePath + " should exist");
    // Then enable it
    paramMap.put(JsonParameters.ENABLED, "" + true);
    request = new Request(Method.POST, resourceRef);
    request.setEntity(JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paramMap), MediaType.APPLICATION_ALL);
    response = _gClient.handle(request);
    result = response.getEntity();
    sw = new StringWriter();
    result.write(sw);
    System.out.println(sw.toString());
    // verify pause znode doesn't exist
    exists = _gZkClient.exists(pausePath);
    Assert.assertFalse(exists, pausePath + " should be removed");
    System.out.println("END: verifyEnableCluster()");
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) Reference(org.restlet.data.Reference) TypeReference(org.codehaus.jackson.type.TypeReference) Request(org.restlet.Request) Representation(org.restlet.representation.Representation)

Example 28 with Response

use of org.restlet.Response in project helix by apache.

the class TestHelixAdminScenariosRest method testGetInstances.

@Test
public void testGetInstances() throws IOException {
    final String clusterName = "TestTagAwareness_testGetResources";
    final String[] TAGS = { "tag1", "tag2" };
    final String URL_BASE = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/instances";
    _gSetupTool.addCluster(clusterName, true);
    HelixAdmin admin = _gSetupTool.getClusterManagementTool();
    // Add 4 participants, each with differint tag characteristics
    InstanceConfig instance1 = new InstanceConfig("localhost_1");
    instance1.addTag(TAGS[0]);
    admin.addInstance(clusterName, instance1);
    InstanceConfig instance2 = new InstanceConfig("localhost_2");
    instance2.addTag(TAGS[1]);
    admin.addInstance(clusterName, instance2);
    InstanceConfig instance3 = new InstanceConfig("localhost_3");
    instance3.addTag(TAGS[0]);
    instance3.addTag(TAGS[1]);
    admin.addInstance(clusterName, instance3);
    InstanceConfig instance4 = new InstanceConfig("localhost_4");
    admin.addInstance(clusterName, instance4);
    // Now make a REST call for all resources
    Reference resourceRef = new Reference(URL_BASE);
    Request request = new Request(Method.GET, resourceRef);
    Response response = _gClient.handle(request);
    ListInstancesWrapper responseWrapper = ClusterRepresentationUtil.JsonToObject(ListInstancesWrapper.class, response.getEntityAsText());
    Map<String, List<String>> tagInfo = responseWrapper.tagInfo;
    // Ensure tag ownership is reported correctly
    Assert.assertTrue(tagInfo.containsKey(TAGS[0]));
    Assert.assertTrue(tagInfo.containsKey(TAGS[1]));
    Assert.assertTrue(tagInfo.get(TAGS[0]).contains("localhost_1"));
    Assert.assertFalse(tagInfo.get(TAGS[0]).contains("localhost_2"));
    Assert.assertTrue(tagInfo.get(TAGS[0]).contains("localhost_3"));
    Assert.assertFalse(tagInfo.get(TAGS[0]).contains("localhost_4"));
    Assert.assertFalse(tagInfo.get(TAGS[1]).contains("localhost_1"));
    Assert.assertTrue(tagInfo.get(TAGS[1]).contains("localhost_2"));
    Assert.assertTrue(tagInfo.get(TAGS[1]).contains("localhost_3"));
    Assert.assertFalse(tagInfo.get(TAGS[1]).contains("localhost_4"));
}
Also used : Response(org.restlet.Response) ListInstancesWrapper(org.apache.helix.webapp.resources.InstancesResource.ListInstancesWrapper) InstanceConfig(org.apache.helix.model.InstanceConfig) Reference(org.restlet.data.Reference) Request(org.restlet.Request) List(java.util.List) HelixAdmin(org.apache.helix.HelixAdmin) Test(org.testng.annotations.Test)

Example 29 with Response

use of org.restlet.Response in project helix by apache.

the class TestHelixAdminScenariosRest method deleteUrl.

void deleteUrl(String url, boolean hasException) throws IOException {
    Reference resourceRef = new Reference(url);
    Request request = new Request(Method.DELETE, resourceRef);
    Response response = _gClient.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    Assert.assertTrue(hasException == sw.toString().toLowerCase().contains("exception"));
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) Reference(org.restlet.data.Reference) Request(org.restlet.Request) Representation(org.restlet.representation.Representation)

Example 30 with Response

use of org.restlet.Response in project AJSC by att.

the class RestletSpringServlet method isDefaultComponent.

/**
 * Indicates if the Component hosted by this Servlet is the default one or
 * one provided by the user.
 *
 * @return True if the Component is the default one, false otherwise.
 */
private boolean isDefaultComponent() {
    // The Component is provided via an XML configuration file.
    Client client = createWarClient(new Context(), getServletConfig());
    Response response = client.handle(new Request(Method.GET, "war:///WEB-INF/restlet.xml"));
    if (response.getStatus().isSuccess() && response.isEntityAvailable()) {
        return false;
    }
    // The Component is provided via a context parameter in the "web.xml"
    // file.
    String componentAttributeName = getInitParameter(COMPONENT_KEY, null);
    if (componentAttributeName != null) {
        return false;
    }
    return true;
}
Also used : Context(org.restlet.Context) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.restlet.Response) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) Client(org.restlet.Client)

Aggregations

Response (org.restlet.Response)82 Request (org.restlet.Request)64 Test (org.testng.annotations.Test)28 Reference (org.restlet.data.Reference)26 Representation (org.restlet.representation.Representation)24 Status (org.restlet.data.Status)17 StringWriter (java.io.StringWriter)16 ChallengeResponse (org.restlet.data.ChallengeResponse)15 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)12 ResponseHandler (org.qi4j.library.rest.client.spi.ResponseHandler)12 HashMap (java.util.HashMap)11 ZNRecord (org.apache.helix.ZNRecord)11 StringReader (java.io.StringReader)10 Map (java.util.Map)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 Test (org.junit.Test)10 Client (org.restlet.Client)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 ContextResourceClient (org.qi4j.library.rest.client.api.ContextResourceClient)7 HandlerCommand (org.qi4j.library.rest.client.api.HandlerCommand)7