Package org.restlet.representation

Examples of org.restlet.representation.Representation


    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 = PropertyPathConfig.getPath(PropertyType.PAUSE, clusterName);
    System.out.println("pausePath: " + pausePath);
    boolean exists = _zkclient.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 = _zkclient.exists(pausePath);
View Full Code Here


                    + ClusterRepresentationUtil.ObjectToJson(jsonParameters),
                MediaType.APPLICATION_ALL);
      }

      Response response = _gClient.handle(request);
      Representation result = response.getEntity();
      StringWriter sw = new StringWriter();

      if (result != null) {
        result.write(sw);
      }

      int code = response.getStatus().getCode();
      boolean successCode =
          code == Status.SUCCESS_NO_CONTENT.getCode() || code == Status.SUCCESS_OK.getCode();
View Full Code Here

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

  String getUrl(String url) throws IOException {
    Reference resourceRef = new Reference(url);
    Request request = new Request(Method.GET, resourceRef);
    Response response = _gClient.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    return sw.toString();
  }
View Full Code Here

     * @throws IOException
     *             - on failed html xml parsing.
     */
    public static Representation handleFormRedirect(Representation input,
            ClientResource resource) throws IOException {
        Representation output = input;
        /**** COPY COOKIES *******************/
        if (resource != null) {
            for (CookieSetting cs : resource.getCookieSettings()) {
                resource.getCookies().add(cs.getName(), cs.getValue());
            }
View Full Code Here

    // Cache result
    @Override
    protected void afterHandle(Request request, Response response) {
        Cookie c = request.getCookies().getFirst(UserCookieID);
        if (c != null) {
            Representation r = response.getEntity();
            if (r != null && (r instanceof JsonRepresentation)) {
                JsonRepresentation jr = (JsonRepresentation) r;
                try {
                    JSONObject o = jr.getJsonObject();
                    if (o != null && o.has("id")) {
View Full Code Here

        final List<String> mailIdentifiers = getMailIdentifiers();

        // 2 - Process the list of mails
        final List<String> mailsSuccessful = new ArrayList<String>();
        final Map<String, String> mailsUnsuccessful = new HashMap<String, String>();
        Representation mail;
        for (final String mailIdentifier : mailIdentifiers) {
            try {
                mail = getMail(mailIdentifier);
                if (mail != null) {
                    this.resolver = getResolver(mailIdentifier, mail);
View Full Code Here

     *            The list of successfull mails and related error message.
     * @return The response's representation.
     */
    protected Representation getResponseRepresentation(
            List<String> mailsSuccessful, Map<String, String> mailsUnsuccessful) {
        final Representation representation = null;

        return representation;
    }
View Full Code Here

            head.appendChild(sent);
        }
        email.appendChild(head);

        // Complete the XML representation with the text part of the message
        Representation content = null;
        if (message.getContent() instanceof Multipart) {
            // Look for the text part of the mail.
            final Multipart multipart = (Multipart) message.getContent();

            for (int i = 0, n = multipart.getCount(); i < n; i++) {
                final Part part = multipart.getBodyPart(i);

                final String disposition = part.getDisposition();
                if (disposition != null) {
                    if (disposition.equals(Part.ATTACHMENT)
                            || disposition.equals(Part.INLINE)) {
                        // create a representation from part.getInputStream()
                    }
                } else {
                    // Check if plain text
                    final MimeBodyPart mimeBodyPart = (MimeBodyPart) part;
                    final ContentType contentType = new ContentType(
                            mimeBodyPart.getContentType());
                    if (MediaType.TEXT_PLAIN.equals(contentType.getMediaType(),
                            true)) {
                        content = new InputRepresentation(mimeBodyPart
                                .getInputStream(), MediaType.TEXT_PLAIN);
                        break;
                    }

                    // TODO Special non-attachment cases here of
                    // image/gif, text/html, ...
                }
            }
        } else {
            // Add the email body
            if (message.getContentType() != null) {
                final ContentType contentType = new ContentType(message
                        .getContentType());
                if (MediaType.TEXT_PLAIN.equals(contentType.getMediaType(),
                        true)) {
                    content = new InputRepresentation(message.getInputStream(),
                            MediaType.TEXT_PLAIN);
                }
            }
        }
        if (content != null) {
            final Element body = dom.createElement("body");

            final CDATASection bodyContent = dom.createCDATASection(content
                    .getText());
            body.appendChild(bodyContent);
            email.appendChild(body);
        }
    }
View Full Code Here

    static void assertBaseUriAndMediaType(MediaType expectedMT,
            Response response, boolean checkEntityText, String baseRef)
            throws IOException {
        sysOutEntityIfError(response);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        final Representation entity = response.getEntity();
        assertEqualMediaType(expectedMT, entity);
        if (checkEntityText) {
            while (baseRef.endsWith("/"))
                baseRef = baseRef.substring(0, baseRef.length() - 1);
            String entityRef = entity.getText();
            while (entityRef.endsWith("/"))
                entityRef = baseRef.substring(0, entityRef.length() - 1);
            assertEquals(baseRef, entityRef);
        }
    }
View Full Code Here

TOP

Related Classes of org.restlet.representation.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.