Package org.restlet.data

Examples of org.restlet.data.Response


  String getUrl(String url) throws IOException
  {
    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


        "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName
            + "/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());
View Full Code Here

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

    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());
View Full Code Here

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

    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 request = new Request(Method.POST, resourceRef);

    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());
View Full Code Here

    xstream.omitField(Status.class, "truncated");
   
    String URL = BASE_URL+"friendships/create/"+friendId+".xml";
    Request request = new Request(Method.GET, URL);   
    auth(request);
    Response response = client.handle(request);
   
    try {
      //System.out.println(response.getStatus()+response.getEntity().getText());
      UserStatus s = (UserStatus)xstream.unmarshal(
          new DomReader(response.getEntityAsDom().getDocument()));
      System.out.println(s.getScreen_name()+"-"+s.getStatus().getText());
      return s;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
View Full Code Here

    String URL = BASE_URL+"friendships/destroy/"+friendId+".xml";
    Request request = new Request(Method.GET, URL);
    //request.setEntity(status.getTextURLEncoded());
   
    auth(request);
    Response response = client.handle(request);
   
    try {
      //System.out.println(response.getStatus()+response.getEntity().getText());
      User s = (User)xstream.unmarshal(new DomReader(response.getEntityAsDom().getDocument()));
      System.out.println(s.getScreen_name());
      return s;
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

  public Collection<Status> getFriendsLatest20Updates() {
    String URL = BASE_URL+"statuses/friends_timeline.xml";
    Request request = new Request(Method.GET, URL);
    auth(request);   
    Response response = client.handle(request);
    try {
      //System.out.println(response.getStatus()+response.getEntity().getText());
      StatusList s = (StatusList) xstream.unmarshal(
          new DomReader(response.getEntityAsDom().getDocument()));
      System.out.println(s.getStatuses().size());
      for(Status it : s.getStatuses()){
        System.out.println(it);
      }
      return s.getStatuses();
View Full Code Here

    String URL = BASE_URL+"statuses/update.xml?status="+status.getTextURLEncoded();
    Request request = new Request(Method.POST, URL);       
    //request.setEntity(status.getTextURLEncoded());
   
    auth(request);
    Response response = client.handle(request);
   
    try {
      //System.out.println(response.getStatus()+response.getEntity().getText());
      Status s = (Status)xstream.unmarshal(new DomReader(response.getEntityAsDom().getDocument()));
      if(response.getStatus().equals(org.restlet.data.Status.SUCCESS_OK)){
        //TwipsePlugin.getDefault().getStatusList().add(s);
        //TwipsePlugin.getDefault().getStatusList().notifyObservers();       
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
View Full Code Here

    xstream.omitField(Status.class, "truncated");
   
    String URL = BASE_URL+"friendships/create/"+friendId+".xml";
    Request request = new Request(Method.GET, URL);   
    auth(request);
    Response response = client.handle(request);
   
    try {
      //System.out.println(response.getStatus()+response.getEntity().getText());
      UserStatus s = (UserStatus)xstream.unmarshal(
          new DomReader(response.getEntityAsDom().getDocument()));
      System.out.println(s.getScreen_name()+"-"+s.getStatus().getText());
      return s;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.restlet.data.Response

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.