Package org.sonatype.plexus.rest.representation

Examples of org.sonatype.plexus.rest.representation.XStreamRepresentation


    Response response = null;
    try {
      response = RequestFacade.sendMessage(
          RequestFacade.SERVICE_LOCAL + "ldap/logintest",
          Method.PUT,
          new XStreamRepresentation(
              xstream,
              xstream.toXML(ldapServerLoginTestRequest),
              MediaType.APPLICATION_XML));

      String responseText = response.getEntity().getText();
View Full Code Here


    String responseText = RequestFacade.doGetForText("service/local/templates/repositories/" + id
        , not(inError()));

    LOG.debug("responseText: \n" + responseText);

    XStreamRepresentation representation = new XStreamRepresentation(
        XStreamFactory.getXmlXStream(),
        responseText,
        MediaType.APPLICATION_XML);

    RepositoryResourceResponse resourceResponse = (RepositoryResourceResponse) representation
        .getPayload(new RepositoryResourceResponse());

    return resourceResponse.getData();
  }
View Full Code Here

      throws Exception
  {
    String jsonString =
        "{\"data\":{\"id\":null,\"name\":\"Test Role\",\"description\":\"This is a test role\",\"sessionTimeout\":50,"
            + "\"roles\":[\"roleid\"],\"privileges\":[\"privid\"]}}}";
    XStreamRepresentation representation =
        new XStreamRepresentation(xstream, jsonString, MediaType.APPLICATION_JSON);

    RoleResourceRequest request = (RoleResourceRequest) representation.getPayload(new RoleResourceRequest());

    assert request.getData().getId() == null;
    assert request.getData().getName().equals("Test Role");
    assert request.getData().getDescription().equals("This is a test role");
    assert request.getData().getSessionTimeout() == 50;
View Full Code Here

  }

  protected XStreamRepresentation createRepresentation(Variant variant)
      throws ResourceException
  {
    XStreamRepresentation representation = null;

    try {
      // check is this variant a supported one, to avoid calling getText() on potentially huge representations
      if (MediaType.APPLICATION_JSON.equals(variant.getMediaType(), true)
          || MediaType.APPLICATION_XML.equals(variant.getMediaType(), true)
          || MediaType.TEXT_HTML.equals(variant.getMediaType(), true)) {
        String text = (variant instanceof Representation) ? ((Representation) variant).getText() : "";

        XStream xstream;
        if (MediaType.APPLICATION_JSON.equals(variant.getMediaType(), true)
            || MediaType.TEXT_HTML.equals(variant.getMediaType(), true)) {
          xstream = (XStream) getContext().getAttributes().get(PlexusRestletApplicationBridge.JSON_XSTREAM);
        }
        else if (MediaType.APPLICATION_XML.equals(variant.getMediaType(), true)) {
          xstream = (XStream) getContext().getAttributes().get(PlexusRestletApplicationBridge.XML_XSTREAM);
        }
        else {
          return null;
        }

        if (text != null) {
          CharacterSet charset = variant.getCharacterSet();
          if (charset == null) {
            charset = CharacterSet.ISO_8859_1;
          }
          if (!CharacterSet.UTF_8.equals(charset)) {
            // must fix text encoding NXCM-2494
            text = new String(new String(text.getBytes(), "UTF-8").getBytes(charset.getName()));
          }
        }

        representation = new XStreamRepresentation(xstream, text, variant.getMediaType());
        return representation;
      }
      else {
        return null;
      }
View Full Code Here

  {
    if (payload == null) {
      return null;
    }

    XStreamRepresentation result = createRepresentation(variant);

    if (result == null) {
      throw new ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE, "The requested mediaType='"
          + variant.getMediaType() + "' is unsupported!");
    }

    result.setPayload(payload);

    return result;
  }
View Full Code Here

        catch (IOException e) {
          throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Cannot get the representation!", e);
        }
      }

      XStreamRepresentation representation = createRepresentation(getRequest().getEntity());

      if (representation != null) {
        try {
          result = representation.getPayload(root);
        }
        catch (XStreamException e) {
          logger
              .warn("Invalid XML, unable to parse using XStream {}", (delegate == null ? "" : delegate.getClass()), e);
View Full Code Here

                                          Matcher<Response>... matchers)
      throws IOException
  {
    String entityText = doSearchForR(queryArgs, repositoryId, searchType, matchers);

    XStreamRepresentation representation =
        new XStreamRepresentation(xstream, entityText, MediaType.APPLICATION_XML);

    return ((SearchResponse) representation.getPayload(new SearchResponse())).getData();
  }
View Full Code Here

  {
    // GET /identify/sha1/8b1b85d04eea979c33109ea42808b7d3f6d355ab (is log4j:log4j:1.2.13)

    try {
      String responseText = RequestFacade.doGetForText("service/local/identify/sha1/" + sha1);
      XStreamRepresentation representation =
          new XStreamRepresentation(xstream, responseText, MediaType.APPLICATION_XML);

      return (NexusArtifact) representation.getPayload(new NexusArtifact());
    }
    catch (AssertionError e) {
      // unsuccesful GET
      return null;
    }
View Full Code Here

      throws IOException
  {
    String serviceURI = "service/local/repositories/" + repositoryName;

    RepositoryResourceResponse repositoryResponse = new RepositoryResourceResponse();
    XStreamRepresentation representation = new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML);
    repositoryResponse.setData(repository);
    representation.setPayload(repositoryResponse);

    RequestFacade.doPutForStatus(serviceURI, representation, isSuccessful());

  }
View Full Code Here

    Response response = null;
    String entityText;
    try {
      response =
          RequestFacade.sendMessage("service/local/repositories/" + repositoryId + "/content/" + itemPath + "?describe=info",
              Method.GET, new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML));
      entityText = response.getEntity().getText(); // to make Restlet response buffer it
      if (response.getStatus().getCode() == Status.REDIRECTION_FOUND.getCode()) {
        // follow redirection but only ONCE
        RequestFacade.releaseResponse(response);
        response = RequestFacade.sendMessage(new URL(response.getLocationRef().toString()), Method.GET, new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML));
        entityText = response.getEntity().getText(); // to make Restlet response buffer it
      }
      assertThat(response, isSuccessful());
    }
    finally {
      RequestFacade.releaseResponse(response);
    }

    XStreamRepresentation rep =
        new XStreamRepresentation(XStreamFactory.getXmlXStream(), entityText, MediaType.APPLICATION_XML);
    ArtifactInfoResourceResponse info =
        (ArtifactInfoResourceResponse) rep.getPayload(new ArtifactInfoResourceResponse());

    return info.getData();
  }
View Full Code Here

TOP

Related Classes of org.sonatype.plexus.rest.representation.XStreamRepresentation

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.