示例#1
0
  protected Object deserialize(Object root) throws ResourceException {

    Object result = null;

    if (root != null) {

      if (String.class.isAssignableFrom(root.getClass())) {
        try {
          result = getRequest().getEntity().getText();
        } 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);

          throw new ResourceException(
              Status.CLIENT_ERROR_BAD_REQUEST, "Invalid XML, unable to parse using XStream", e);
        }
      }
    }
    return result;
  }
  private boolean isEnabled() throws Exception {
    String responseText = RequestFacade.doGetForText("service/local/lvo_config");

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

    LvoConfigResponse resp = (LvoConfigResponse) representation.getPayload(new LvoConfigResponse());

    return resp.getData().isEnabled();
  }
示例#3
0
  public RepositoryRouteResource getResourceFromText(String responseString) {
    assertThat(responseString, not(IsEmptyString.isEmptyOrNullString()));
    XStreamRepresentation representation =
        new XStreamRepresentation(xstream, responseString, mediaType);

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

    return resourceResponse.getData();
  }
  public LdapConnectionInfoDTO getResourceFromResponse(Response response) throws IOException {
    String responseString = response.getEntity().getText();
    LOG.debug(" getResourceFromResponse: " + responseString);

    XStreamRepresentation representation =
        new XStreamRepresentation(xstream, responseString, mediaType);
    LdapConnectionInfoResponse resourceResponse =
        (LdapConnectionInfoResponse) representation.getPayload(new LdapConnectionInfoResponse());

    return resourceResponse.getData();
  }
  public RepositoryTargetResource getResourceFromResponse(String responseText) throws IOException {
    LOG.debug(" getResourceFromResponse: " + responseText);

    XStreamRepresentation representation =
        new XStreamRepresentation(xstream, responseText, mediaType);

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

    return resourceResponse.getData();
  }
  private List<PlexusComponentListResource> getResult(
      String role, XStream xstream, MediaType mediaType) throws IOException {
    String responseString = this.sendMessage(role, xstream, mediaType).getEntity().getText();

    XStreamRepresentation representation =
        new XStreamRepresentation(xstream, responseString, mediaType);

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

    return resourceResponse.getData();
  }
示例#7
0
  @SuppressWarnings("unchecked")
  public static List<RepositoryRouteListResource> getList() throws IOException {
    String serviceURI = "service/local/repo_routes";

    String entityText = RequestFacade.doGetForText(serviceURI);
    XStreamRepresentation representation =
        new XStreamRepresentation(
            XStreamFactory.getXmlXStream(), entityText, MediaType.APPLICATION_XML);

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

    return resourceResponse.getData();
  }
  public RepositoryBaseResource getTemplate(String id) throws IOException {
    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();
  }
  public static RepositoryTargetResource get(String targetId) throws IOException {
    String responseText =
        RequestFacade.doGetRequest("service/local/repo_targets/" + targetId).getEntity().getText();
    LOG.debug("responseText: \n" + responseText);

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

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

    return resourceResponse.getData();
  }
示例#10
0
  private UserAccount readAccount(Response response) throws IOException {
    if (response.getStatus().isSuccess()) {
      String responseText = response.getEntity().getText();

      LOGGER.debug("Response Text: \n" + responseText);

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

      UserAccountRequestResponseWrapper responseDTO =
          (UserAccountRequestResponseWrapper)
              representation.getPayload(new UserAccountRequestResponseWrapper());

      return responseDTO.getData();
    } else {
      LOGGER.warn("HTTP Error: '" + response.getStatus().getCode() + "'");

      LOGGER.warn(response.getEntity().getText());

      return null;
    }
  }
  private List<ClientPermission> getPermissions() throws IOException {
    Response response =
        RequestFacade.sendMessage(RequestFacade.SERVICE_LOCAL + "authentication/login", Method.GET);

    String responseText = response.getEntity().getText();

    if (response.getStatus().isError()) {
      Assert.fail(response.getStatus() + "\n" + responseText);
    }

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

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

    AuthenticationLoginResource resource = resourceResponse.getData();

    return resource.getClientPermissions().getPermissions();
  }
  private void test(String query, String expected) throws IOException {

    String serviceURIpart = "service/local/lucene/search?q=" + URLEncoder.encode(query, "UTF-8");
    log.info("Testing query {}: {}", query, serviceURIpart);
    String errorPayload = RequestFacade.doGetForText(serviceURIpart, respondsWithStatusCode(400));
    log.info("Received 'Bad Request' error: " + errorPayload);
    MediaType type = MediaType.APPLICATION_XML;
    XStreamRepresentation representation =
        new XStreamRepresentation(getXMLXStream(), errorPayload, type);

    ErrorResponse payload = (ErrorResponse) representation.getPayload(new ErrorResponse());

    List errors = payload.getErrors();
    assertThat((Collection<?>) errors, hasSize(1));
    ErrorMessage error = (ErrorMessage) errors.get(0);
    String msg = error.getMsg();

    msg = msg.replaceAll("Cannot parse '([^']*)':.*", "$1");

    log.info("msg: " + msg);

    assertThat(msg, equalTo(expected));
  }