Package org.restlet.resource

Examples of org.restlet.resource.StringRepresentation


            }

            // Hack because root must be a list for dojo tree...
            if ("servers".equals(getRequest().getOriginalRef().getLastSegment(true)))
            {
                return new StringRepresentation(JSONSerializer.toJSON(new Object[]{result})
                        .toString());
            }
            else
            {
                return new StringRepresentation(JSONSerializer.toJSON(result).toString());
            }
        }
        else
        {
            return null;
View Full Code Here


    // if the client wanted JSON, setup the appropriate Representation
    if ("json".equals(type)) {
      String jsonText = "{"
          + ArtifactUsageSerializer.toJson(artifactUsers, 3) + "}";
      return new StringRepresentation(jsonText,
          MediaType.APPLICATION_JSON);
    } else {
      Document doc;
      try {
        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
View Full Code Here

            .getLastSegment()));
    // limiting depth of the data to n levels so that we don't stall out
    String jsonText = "{" + ArtifactUsageSerializer.toJson(artifactList, 5)
        + "}";

    return new StringRepresentation(jsonText, MediaType.APPLICATION_JSON);
  }
View Full Code Here

    Set<GAV> artifacts = new TreeSet<GAV>();
    collectArtifacts(artifacts, artifactList);
    String jsonText = "{" + ArtifactUsageSerializer.toJson(artifacts) + "}";

    return new StringRepresentation(jsonText, MediaType.APPLICATION_JSON);
  }
View Full Code Here

  }

  @Override
  public Representation represent(Variant variant)
  {
    StringRepresentation representation = null;
    String clusterName = getValue("clusterName");
    String constraintTypeStr = getValue("constraintType").toUpperCase();
    String constraintId = getValue("constraintId");

    try {
      ConstraintType constraintType = ConstraintType.valueOf(constraintTypeStr);
      ZkClient zkClient =
          (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
      // ClusterSetup setupTool = new ClusterSetup(zkClient);
      HelixAdmin admin = new ZKHelixAdmin(zkClient)// setupTool.getClusterManagementTool();
 
      ZNRecord record = admin.getConstraints(clusterName, constraintType).getRecord();
      if (constraintId == null) {
        // get all message constraints
        representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
                                         MediaType.APPLICATION_JSON);
      } else {
        // get a specific constraint
        Map<String, String> constraint = record.getMapField(constraintId);
        if (constraint == null) {
          representation = new StringRepresentation("No constraint of type: "
              + constraintType + " associated with id: " + constraintId, MediaType.APPLICATION_JSON);
        } else {
          ZNRecord subRecord = new ZNRecord(record.getId());
          subRecord.setMapField(constraintId, constraint);
          representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(subRecord),
              MediaType.APPLICATION_JSON);
        }
      }
    }
    catch (IllegalArgumentException e) {
      representation = new StringRepresentation("constraint-type: " + constraintTypeStr + " not recognized.",
          MediaType.APPLICATION_JSON);
    }
    catch (Exception e)
    {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      representation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
      LOG.error("", e);
    }

    return representation;
  }
View Full Code Here

  }
 
  @Override
  public Representation represent(Variant variant)
  {
    StringRepresentation presentation = null;
    try
    {
      presentation = getSchedulerTasksRepresentation();
    }
   
    catch(Exception e)
    {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);

      LOG.error("", e);
   
    return presentation;
  }
View Full Code Here

   
    HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
    LiveInstance liveInstance = accessor.getProperty(accessor.keyBuilder().liveInstance(instanceName));
    String sessionId = liveInstance.getSessionId();
   
    StringRepresentation representation = new StringRepresentation("");//(ClusterRepresentationUtil.ObjectToJson(instanceConfigs), MediaType.APPLICATION_JSON);
   
    return representation;
  }
View Full Code Here

    return (String) getRequest().getAttributes().get(key);
  }

  static StringRepresentation getConfigScopes() throws Exception
  {
    StringRepresentation representation = null;
    ZNRecord record = new ZNRecord("Config");

    List<String> scopeList =
        Arrays.asList(ConfigScopeProperty.CLUSTER.toString(),
                      ConfigScopeProperty.RESOURCE.toString(),
                      ConfigScopeProperty.PARTICIPANT.toString(),
                      ConfigScopeProperty.PARTITION.toString());
    record.setListField("scopes", scopeList);

    representation =
        new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
                                 MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here

    return representation;
  }

  StringRepresentation getConfigKeys(ConfigScopeProperty scopeProperty, String... keys) throws Exception
  {
    StringRepresentation representation = null;
    // String clusterName = getValue("clusterName");

    ZkClient zkClient =
        (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    HelixAdmin admin = setupTool.getClusterManagementTool();
    ZNRecord record = new ZNRecord(scopeProperty + " Config");

    HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build();
    // List<String> configKeys = admin.getConfigKeys(scopeProperty, clusterName, keys);
    List<String> configKeys = admin.getConfigKeys(scope);
    record.setListField(scopeProperty.toString(), configKeys);

    representation =
        new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
                                 MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here

  StringRepresentation getConfigs(// ConfigScope scope,
                                  ConfigScopeProperty scopeProperty,
                                  String... keys) throws Exception
  {
    StringRepresentation representation = null;
//    String clusterName = getValue("clusterName");

    ZkClient zkClient =
        (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    HelixAdmin admin = setupTool.getClusterManagementTool();
    ZNRecord record = new ZNRecord(scopeProperty + " Config");

    HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build();
    List<String> configKeys = admin.getConfigKeys(scope);
    Map<String, String> configs = admin.getConfig(scope, configKeys);
    record.setSimpleFields(configs);

    representation =
        new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
                                 MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here

TOP

Related Classes of org.restlet.resource.StringRepresentation

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.