Package org.restlet.resource

Examples of org.restlet.resource.Representation


      entity = entity + "&" + (key + "=" + extraForm.get(key));
    }
    request.setEntity(entity, 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);

    Assert.assertTrue(response.getStatus().getCode() == Status.SUCCESS_OK.getCode());
    Assert.assertTrue(hasException == sw.toString().toLowerCase().contains("exception"));
    return sw.toString();
  }
View Full Code Here


  {
    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

   * Extract text from response
   */
  public String extractText(final Response response)
      throws IOException
  {
    final Representation entity = response.getEntity();
    assertThat(entity, notNullValue());
    final String responseText = entity.getText();
    return responseText;
  }
View Full Code Here

    checkNotNull(serviceURIpart);
    Response response = null;
    try {
      // deliberately passing null for matcher since we do the check after getting the text below.
      response = sendMessage(toNexusURL(serviceURIpart), Method.GET, representation, null);
      final Representation entity = response.getEntity();
      assertThat(entity, notNullValue());
      final String responseText = entity.getText();
      if (responseMatcher != null) {
        assertThat(response, responseMatcher);
      }
      return responseText;
    }
View Full Code Here

      }
    }

    @Override
    protected boolean matchesSafely(Response item) {
      final Representation entity = item.getEntity();
      MatcherAssert.assertThat(entity, CoreMatchers.notNullValue());
      String responseText;
      try {
        responseText = entity.getText();
      }
      catch (IOException e) {
        this.exception = e;
        return false;
      }
View Full Code Here

        }
      }
    }

    if (MediaType.TEXT_HTML.equals(variant.getMediaType())) {
      Representation result = serialize(context, req, variant, response);

      result.setModificationDate(new Date(coll.getModified()));

      return result;
    }
    else {
      return response;
View Full Code Here

        String redirectMessage =
            "If you are not automatically redirected use this url: " + fileReference.toString();
        return redirectMessage;
      }
      else {
        Representation result = new StorageFileItemRepresentation(file);

        result.setDownloadable(true);

        result.setDownloadName(file.getName());

        return result;
      }

    }
View Full Code Here

  }

  private Representation doRepresent(Object payload, Variant variant, Response response)
      throws ResourceException
  {
    final Representation representation = doRepresent(payload, variant);
    if (representation != null && representation instanceof RestletResponseCustomizer) {
      ((RestletResponseCustomizer) representation).customize(response);
    }
    return representation;
  }
View Full Code Here

  @Override
  public Status sendRequest(Request request) {
    Status result = null;

    try {
      final Representation entity = request.getEntity();

      // Set the request headers
      for (final Parameter header : getRequestHeaders()) {
        if ("Content-Length".equalsIgnoreCase(header.getName())) {
          // HC4 is picky about duplicate content-length header
          continue;
        }
        getHttpMethod().setHeader(header.getName(),
            header.getValue());
      }

      // For those method that accept enclosing entities, provide it if there is any
      if ((entity != null)
          && (getHttpMethod() instanceof HttpEntityEnclosingRequestBase)) {
        final HttpEntityEnclosingRequestBase eem = (HttpEntityEnclosingRequestBase) getHttpMethod();
        eem.setEntity(new HttpEntity()
        {
          @Override
          public void writeTo(final OutputStream outstream)
              throws IOException
          {
            entity.write(outstream);
          }

          @Override
          public boolean isStreaming() {
            return entity.isTransient();
          }

          @Override
          public boolean isRepeatable() {
            return !entity.isTransient();
          }

          @Override
          public boolean isChunked() {
            return false;
          }

          @Override
          public Header getContentType() {
            final String contentType = (entity.getMediaType() != null) ? entity
                .getMediaType().toString() : null;
            if (contentType != null) {
              return new BasicHeader("Content-Type", contentType);
            }
            else {
              return null;
            }
          }

          @Override
          public long getContentLength() {
            return entity.getSize();
          }

          @Override
          public Header getContentEncoding() {
            return null;
          }

          @Override
          public InputStream getContent()
              throws IOException, IllegalStateException
          {
            return entity.getStream();
          }

          @Override
          @Deprecated
          public void consumeContent()
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);
                    output.setIdentifier(request.getResourceRef());
                    response.setEntity(output);
                    response.setStatus(Status.SUCCESS_OK);
                }
            } catch (IOException e) {
                getLogger().log(Level.WARNING,
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.