Package org.restlet.resource

Examples of org.restlet.resource.StringRepresentation


      instanceConfigsMap.get(instanceName)
                        .getRecord()
                        .setSimpleField("Alive", isAlive + "");
    }

    StringRepresentation representation =
        new StringRepresentation(ClusterRepresentationUtil.ObjectToJson(instanceConfigsMap.values()),
                                 MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here


  }

  @Override
  public Representation represent(Variant variant)
  {
    StringRepresentation presentation = null;
    try
    {
      String clusterName = (String) getRequest().getAttributes().get("clusterName");
      String resourceName = (String) getRequest().getAttributes().get("resourceName");
      presentation = getIdealStateRepresentation(clusterName, resourceName);
    }

    catch (Exception e)
    {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);

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

        ClusterRepresentationUtil.getClusterPropertyAsString(zkClient,
                                                             clusterName,
                                                             keyBuilder.idealStates(resourceName),
                                                             MediaType.APPLICATION_JSON);

    StringRepresentation representation =
        new StringRepresentation(message, MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here

        stringBuilder.append("</td>");
        stringBuilder.append("</tr>");
        stringBuilder.append("</table>");
        stringBuilder.append("</body>");
        stringBuilder.append("</html>");
        response.setEntity(new StringRepresentation(stringBuilder.toString(),
            MediaType.TEXT_HTML));
      }
    };
    router.attach("", mainpage);
    return router;
View Full Code Here

  }

  @Override
  public Representation represent(Variant variant)
  {
    StringRepresentation presentation = null;
    try
    {
      String clusterName = (String) getRequest().getAttributes().get("clusterName");
      presentation = getHostedEntitiesRepresentation(clusterName);
    }

    catch (Exception e)
    {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);

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

        setupTool.getClusterManagementTool().getResourcesInCluster(clusterName);

    ZNRecord hostedEntitiesRecord = new ZNRecord("ResourceGroups");
    hostedEntitiesRecord.setListField("ResourceGroups", hostedEntities);

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

    return representation;
  }
View Full Code Here

     * Handle get requests
     * @see org.restlet.resource.Resource#represent(org.restlet.resource.Variant)
     */
    public Representation represent(Variant variant)
    {
      StringRepresentation presentation = null;
      try
      {
        String databaseId = (String)getRequest().getAttributes().get(MockEspressoService.DATABASENAME);
        String tableId = (String)getRequest().getAttributes().get(MockEspressoService.TABLENAME);
        String resourceId = (String)getRequest().getAttributes().get(MockEspressoService.RESOURCENAME);
        String subResourceId = (String)getRequest().getAttributes().get(MockEspressoService.SUBRESOURCENAME);
        logger.debug("Done getting request components");
        logger.debug("method: "+getRequest().getMethod());
        String composedKey = databaseId + tableId + resourceId; // + subResourceId;
        EspressoStorageMockNode mock = (EspressoStorageMockNode)_context.getAttributes().get(MockEspressoService.CONTEXT_MOCK_NODE_NAME);

       
        if (getRequest().getMethod() == Method.PUT) {
          logger.debug("processing PUT");
          Reader postBodyReader;
          //TODO: get to no fixed size on buffer
          char[] postBody = new char[POST_BODY_BUFFER_SIZE];         
          postBodyReader = getRequest().getEntity().getReader();
          postBodyReader.read(postBody);
          logger.debug("postBody: "+new String(postBody));
          mock.doPut(databaseId, composedKey, new String(postBody));
          presentation = new StringRepresentation("Put succeeded", MediaType.APPLICATION_JSON);
        }
        else if (getRequest().getMethod() == Method.GET) {
          logger.debug("processing GET");
          String result = mock.doGet(databaseId, composedKey);
            logger.debug("result: "+result);
            if (result == null) {
              presentation = new StringRepresentation("Record not found", MediaType.APPLICATION_JSON);
              getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND,"Record not found");
            }
            else {
              getResponse().setStatus(Status.SUCCESS_OK,"Success");
              presentation = new StringRepresentation(result, MediaType.APPLICATION_JSON);
            }
        }
      }

      catch (IOException e) {
        presentation = new StringRepresentation(e.getMessage(), MediaType.APPLICATION_JSON);
        e.printStackTrace();
      }

      catch(Exception e)
      {
        String error = "Error with op"; //ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
        presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);       
        e.printStackTrace();
     
      return presentation;
    }
View Full Code Here

     * Handle put requests (non-Javadoc)
     * @see org.restlet.resource.Resource#storeRepresentation(org.restlet.resource.Representation)
     */
   public void storeRepresentation(Representation entity) throws ResourceException {
     logger.debug("in storeRepresentation");
     StringRepresentation presentation = null;
    // try {
     Form requestHeaders = (Form) getRequest().getAttributes().get("org.restlet.http.headers");
     Map<String, String> headerMap = requestHeaders.getValuesMap();
     logger.debug("HEADERS MAP");
     for (String key : headerMap.keySet()) {
       logger.debug(key+" : "+headerMap.get(key));
     }
  //  } catch (IOException e1) {
      // TODO Auto-generated catch block
      //e1.printStackTrace();
    //}  
     try
        {
          logger.debug("in PutResource handle");
          String databaseId = (String)getRequest().getAttributes().get(MockEspressoService.DATABASENAME);
          String tableId = (String)getRequest().getAttributes().get(MockEspressoService.TABLENAME);
          String resourceId = (String)getRequest().getAttributes().get(MockEspressoService.RESOURCENAME);
          String subResourceId = (String)getRequest().getAttributes().get(MockEspressoService.SUBRESOURCENAME);
          logger.debug("Done getting request components");
          logger.debug("method: "+getRequest().getMethod());
          String composedKey = databaseId + tableId + resourceId; // + subResourceId;
          EspressoStorageMockNode mock = (EspressoStorageMockNode)_context.getAttributes().get(MockEspressoService.CONTEXT_MOCK_NODE_NAME);

          if (getRequest().getMethod() == Method.PUT) {
            logger.debug("processing PUT");
            Reader postBodyReader;
            //TODO: get to no fixed size on buffer
            char[] postBody = new char[POST_BODY_BUFFER_SIZE];
            postBodyReader = getRequest().getEntity().getReader();
            postBodyReader.read(postBody);
            logger.debug("postBody: "+new String(postBody));
            mock.doPut(databaseId, composedKey, new String(postBody));
            presentation = new StringRepresentation("Put succeeded", MediaType.APPLICATION_JSON);
          }
          else if (getRequest().getMethod() == Method.GET) {
            logger.debug("Processing GET");
            String result = mock.doGet(databaseId, composedKey);
              logger.debug("result: "+result);
              if (result == null) {
                presentation = new StringRepresentation("Record not found", MediaType.APPLICATION_JSON);
              }
              else {
                presentation = new StringRepresentation(result, MediaType.APPLICATION_JSON);
              }
          }
        }

        catch (IOException e) {
          presentation = new StringRepresentation(e.getMessage(), MediaType.APPLICATION_JSON);
          e.printStackTrace();
        }

        catch(Exception e)
        {
          String error = "Error with op";
          presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);       
          e.printStackTrace();
       
        finally {
          entity.release();
        }
View Full Code Here

 
  //XXX: handling both gets and puts here for now
  public Representation represent(Variant variant)
  {
    System.out.println("StopServiceResource.represent()");
    StringRepresentation presentation = null;
    try
    {
      logger.debug("in represent, stopping service");
      Component component = (Component)_context.getAttributes().get(MockEspressoService.COMPONENT_NAME);
      EspressoStorageMockNode mock = (EspressoStorageMockNode)_context.getAttributes().get(MockEspressoService.CONTEXT_MOCK_NODE_NAME);
      presentation = new StringRepresentation("Stopping in 1 second", MediaType.APPLICATION_JSON);
      Thread stopper = new Thread(new StopThread(component, mock));
      stopper.start();
    }

    catch(Exception e)
    {
      String error = "Error shutting down";
      presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);       
      e.printStackTrace();
   
    return presentation;
  }
View Full Code Here

        stringBuilder.append("</td>");
        stringBuilder.append("</tr>");
        stringBuilder.append("</table>");
        stringBuilder.append("</body>");
        stringBuilder.append("</html>");
        response.setEntity(new StringRepresentation(stringBuilder.toString(),
            MediaType.TEXT_HTML));
      }
    };
   
    if (_mockNode == null) {
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.