コード例 #1
0
ファイル: SimpleClientDemo.java プロジェクト: benxar/s-ramp
  /**
   * Main.
   *
   * @param args
   */
  public static void main(String[] args) throws Exception {
    System.out.println("\n*** Running S-RAMP Simple Client Demo ***\n");

    // Figure out the endpoint of the S-RAMP repository's Atom API
    String endpoint = System.getProperty("sramp.endpoint");
    if (endpoint == null || endpoint.trim().length() == 0) {
      endpoint = DEFAULT_ENDPOINT;
    }
    System.out.println("S-RAMP Endpoint: " + endpoint);

    // Upload some artifacts to the S-RAMP repository
    System.out.println("Uploading some XML schemas...");
    SrampAtomApiClient client = new SrampAtomApiClient(endpoint);
    for (String file : FILES) {
      // Get an InputStream over the file content
      InputStream is = SimpleClientDemo.class.getResourceAsStream(file);

      try {
        // We need to know the artifact type
        ArtifactType type = ArtifactType.XsdDocument;
        if (file.endsWith(".wsdl")) {
          type = ArtifactType.WsdlDocument;
        }

        // Upload that content to S-RAMP
        System.out.print("\tUploading artifact " + file + "...");
        BaseArtifactType artifact = client.uploadArtifact(type, is, file);
        System.out.println("done.");

        // Update the artifact meta-data (set the version and add a custom property)
        artifact.setVersion("1.1");
        SrampModelUtils.setCustomProperty(artifact, "demo", "simple-client");

        // Tell the server about the updated meta-data
        System.out.print("\tUpdating meta-data for artifact " + file + "...");
        client.updateArtifactMetaData(artifact);
        System.out.println("done.");
      } finally {
        is.close();
      }
    }

    // Now query the S-RAMP repository (for the Schemas only)
    System.out.print("Querying the S-RAMP repository for Schemas...");
    QueryResultSet rset = client.query("/s-ramp/xsd/XsdDocument");
    System.out.println("success: " + rset.size() + " Schemas found:");
    for (ArtifactSummary entry : rset) {
      System.out.println("\t * " + entry.getName() + " (" + entry.getUuid() + ")");
    }

    System.out.println("\n*** Demo Completed Successfully ***\n\n");
    Thread.sleep(3000);
  }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.jboss.arquillian.container.sramp.SrampService#deployArchive(java.
   * lang.String, java.lang.String, java.io.InputStream)
   */
  public BaseArtifactType deployArchive(
      String archiveId, String archiveName, String artifactTypeArg, InputStream content) {

    assert content != null;

    ZipToSrampArchive expander = null;
    SrampArchive archive = null;
    BaseArtifactType artifact = null;
    File tempResourceFile = null;
    try {
      // internal integrity check
      artifactCounter = client.query("/s-ramp").getTotalResults();

      // First, stash the content in a temp file - we may need it multiple
      // times.
      tempResourceFile = stashResourceContent(content);
      content = FileUtils.openInputStream(tempResourceFile);

      ArtifactType artifactType = ArtifactType.valueOf(artifactTypeArg);
      if (artifactType.isExtendedType()) {
        artifactType = ArtifactType.ExtendedDocument(artifactType.getExtendedType());
      }

      artifact = client.uploadArtifact(artifactType, content, archiveName);
      IOUtils.closeQuietly(content);

      // for all uploaded files add custom property
      SrampModelUtils.setCustomProperty(artifact, "arquillian-archive-id", archiveId);
      client.updateArtifactMetaData(artifact);

      content = FileUtils.openInputStream(tempResourceFile);

      // Now also add "expanded" content to the s-ramp repository
      expander = ZipToSrampArchiveRegistry.createExpander(artifactType, content);

      if (expander != null) {
        expander.setContextParam(DefaultMetaDataFactory.PARENT_UUID, artifact.getUuid());
        archive = expander.createSrampArchive();
        client.uploadBatch(archive);
      }
    } catch (Exception e) {
      log.error("Upload failure:", e);
      IOUtils.closeQuietly(content);
    } finally {
      SrampArchive.closeQuietly(archive);
      ZipToSrampArchive.closeQuietly(expander);
      FileUtils.deleteQuietly(tempResourceFile);
    }

    return artifact;
  }
コード例 #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.jboss.arquillian.container.sramp.SrampService#undeployArchives()
   */
  public void undeployArchives(String archiveId) throws SrampClientException, SrampAtomException {

    log.debug("Deleting expanded artifacts");

    // Delete expanded artifacts
    QueryResultSet rset =
        client
            .buildQuery("/s-ramp[expandedFromDocument[@arquillian-archive-id = ?]]")
            .parameter(archiveId)
            .query();

    for (ArtifactSummary artifactSummary : rset) {
      log.debug("Deleting: " + artifactSummary.getName());
      client.deleteArtifact(artifactSummary.getUuid(), artifactSummary.getType());
    }

    // Delete (un)deployment information
    rset =
        client
            .buildQuery("/s-ramp[describesDeployment[@arquillian-archive-id = ?]]")
            .parameter(archiveId)
            .query();
    for (ArtifactSummary artifactSummary : rset) {
      log.debug("Deleting: " + artifactSummary.getName());
      client.deleteArtifact(artifactSummary.getUuid(), artifactSummary.getType());
    }

    // Delete main archive
    // Related are deleted along with the primary
    rset = client.buildQuery("/s-ramp[@arquillian-archive-id = ?]").parameter(archiveId).query();

    ArtifactSummary archiveArtifact = rset.get(0);

    log.debug("Deleting: " + archiveArtifact.getName());

    client.deleteArtifact(archiveArtifact.getUuid(), archiveArtifact.getType());

    // Internal consistency check whether the number of artifacts before
    // deploy and after deploy match
    long artifactCounterTemp = client.query("/s-ramp").getTotalResults();

    if (artifactCounter != artifactCounterTemp) {
      log.warn("Artifact counts does not match!");
      log.warn(
          "Artifacts before deploy: "
              + artifactCounter
              + ". Artifacts after undeploy: "
              + artifactCounterTemp);
      artifactCounter = artifactCounterTemp;
    }
  }