Package org.restlet.resource

Examples of org.restlet.resource.Representation


  {
    Reference resourceRef = new Reference(url);
    Request request = new Request(Method.DELETE, resourceRef);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    Assert.assertTrue(hasException == sw.toString().toLowerCase().contains("exception"));
  }
View Full Code Here


  {
    Reference resourceRef = new Reference(url);
    Request request = new Request(Method.GET, resourceRef);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    return sw.toString();
  }
View Full Code Here

            + "/StateModelDefs/MasterSlave";
    Reference resourceRef = new Reference(httpUrlBase);
    Request request = new Request(Method.GET, resourceRef);
    Client client = new Client(Protocol.HTTP);
    Response response = client.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);
    StateModelDefinition newStateModel = new StateModelDefinition(r);

    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);
    client = new Client(Protocol.HTTP);
    response = client.handle(request);

    result = response.getEntity();
    sw = new StringWriter();
    result.write(sw);

    System.out.println(sw.toString());

    AssertJUnit.assertTrue(sw.toString().contains("Test"));
  }
View Full Code Here

    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(paraMap), MediaType.APPLICATION_ALL);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);

    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);

    System.out.println(sw.toString());

    ObjectMapper mapper = new ObjectMapper();
    ZNRecord zn = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
View Full Code Here

    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(paraMap), MediaType.APPLICATION_ALL);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);

    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);

    System.out.println(sw.toString());

    ObjectMapper mapper = new ObjectMapper();
    ZNRecord zn = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
    AssertJUnit.assertTrue(zn.getListField("ResourceGroups").contains(resourceGroupName));

    httpUrlBase =
        "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups/"
            + resourceGroupName;
    resourceRef = new Reference(httpUrlBase);

    request = new Request(Method.GET, resourceRef);

    client = new Client(Protocol.HTTP);
    response = client.handle(request);

    result = response.getEntity();
    sw = new StringWriter();
    result.write(sw);

    System.out.println(sw.toString());
  }
View Full Code Here

    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(paraMap), MediaType.APPLICATION_ALL);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);

    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);

    System.out.println(sw.toString());

    ObjectMapper mapper = new ObjectMapper();

    TypeReference<ArrayList<ZNRecord>> typeRef = new TypeReference<ArrayList<ZNRecord>>()
    {
    };
    List<ZNRecord> znList = mapper.readValue(new StringReader(sw.toString()), typeRef);
    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);
    client = new Client(Protocol.HTTP);
    response = client.handle(request);

    result = response.getEntity();
    sw = new StringWriter();
    result.write(sw);

    System.out.println(sw.toString());

    mapper = new ObjectMapper();
View Full Code Here

    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(paraMap), MediaType.APPLICATION_ALL);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);

    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);

    System.out.println(sw.toString());

    ObjectMapper mapper = new ObjectMapper();
    ZNRecord r = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);

    for (int i = 0; i < partitions; i++)
    {
      String partitionName = resourceGroupName + "_" + i;
      assert (r.getMapField(partitionName).size() == replicas);
    }

    httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName;
    resourceRef = new Reference(httpUrlBase);
    request = new Request(Method.GET, resourceRef);

    client = new Client(Protocol.HTTP);
    response = client.handle(request);

    result = response.getEntity();
    sw = new StringWriter();
    result.write(sw);

  }
View Full Code Here

            }

            // If an entity was set during the call, copy it to the output
            // stream;
            if (response.getEntity() != null) {
                Representation entity = response.getEntity();

                if (entity.getExpirationDate() != null) {
                    responseHeaders.add(HttpConstants.HEADER_EXPIRES, response
                            .getHttpCall().formatDate(
                                    entity.getExpirationDate(), false));
                }

                if (!entity.getEncodings().isEmpty()) {
                    StringBuilder value = new StringBuilder();
                    for (Encoding encoding : entity.getEncodings()) {
                        if (!encoding.equals(Encoding.IDENTITY)) {
                            if (value.length() > 0)
                                value.append(", ");
                            value.append(encoding.getName());
                        }
                        responseHeaders.add(
                                HttpConstants.HEADER_CONTENT_ENCODING, value
                                        .toString());
                    }
                }

                if (!entity.getLanguages().isEmpty()) {
                    StringBuilder value = new StringBuilder();
                    for (int i = 0; i < entity.getLanguages().size(); i++) {
                        if (i > 0)
                            value.append(", ");
                        value.append(entity.getLanguages().get(i).getName());
                    }
                    responseHeaders.add(HttpConstants.HEADER_CONTENT_LANGUAGE,
                            value.toString());
                }

                if (entity.getMediaType() != null) {
                    StringBuilder contentType = new StringBuilder(entity
                            .getMediaType().getName());

                    if (entity.getCharacterSet() != null) {
                        // Specify the character set parameter
                        contentType.append("; charset=").append(
                                entity.getCharacterSet().getName());
                    }

                    responseHeaders.add(HttpConstants.HEADER_CONTENT_TYPE,
                            contentType.toString());
                }

                if (entity.getModificationDate() != null) {
                    responseHeaders.add(HttpConstants.HEADER_LAST_MODIFIED,
                            response.getHttpCall().formatDate(
                                    entity.getModificationDate(), false));
                }

                if (entity.getTag() != null) {
                    responseHeaders.add(HttpConstants.HEADER_ETAG, entity
                            .getTag().format());
                }

                if (response.getEntity().getSize() != Representation.UNKNOWN_SIZE) {
                    responseHeaders.add(HttpConstants.HEADER_CONTENT_LENGTH,
View Full Code Here

        File file = new File(LocalReference.localizePath(path));
        MetadataService metadataService = getMetadataService(request);

        if (request.getMethod().equals(Method.GET)
                || request.getMethod().equals(Method.HEAD)) {
            Representation output = null;

            // Get variants for a resource
            boolean found = false;
            Iterator<Preference<MediaType>> iterator = request.getClientInfo()
                    .getAcceptedMediaTypes().iterator();
View Full Code Here

                    response.setEntity(rl.getTextRepresentation());
                    response.setStatus(Status.SUCCESS_OK);
                } else {
                    // Return the file content
                    Representation output = new InputRepresentation(war
                            .getInputStream(entry), null);
                    updateMetadata(getMetadataService(request), path, output);
                    response.setEntity(output);
                    response.setStatus(Status.SUCCESS_OK);
                }
View Full Code Here

TOP

Related Classes of org.restlet.resource.Representation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.