Example usage for org.apache.commons.httpclient.params HttpMethodParams USE_EXPECT_CONTINUE

List of usage examples for org.apache.commons.httpclient.params HttpMethodParams USE_EXPECT_CONTINUE

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpMethodParams USE_EXPECT_CONTINUE.

Prototype

String USE_EXPECT_CONTINUE

To view the source code for org.apache.commons.httpclient.params HttpMethodParams USE_EXPECT_CONTINUE.

Click Source Link

Usage

From source file:org.sonatype.nexus.integrationtests.nexus167.Nexus167ReleaseToSnapshotIT.java

@Test
public void deployUsingRest() throws HttpException, Exception {

    Gav gav = new Gav(this.getTestId(), "uploadWithGav", "1.0.0", null, "xml", 0, new Date().getTime(),
            "Simple Test Artifact", false, null, false, null);

    // file to deploy
    File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension());

    // the Restlet Client does not support multipart forms: http://restlet.tigris.org/issues/show_bug.cgi?id=71

    // url to upload to
    String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content";

    // the method we are calling
    PostMethod filePost = new PostMethod(uploadURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_SNAPSHOT_REPO, gav, fileToDeploy);

    if (status != HttpStatus.SC_BAD_REQUEST) {
        Assert.fail("Upload attempt should have returned a 400, it returned:  " + status);
    }/*from w  w w. j  a  va2 s. c o  m*/

    boolean fileWasUploaded = true;
    try {
        // download it
        downloadArtifact(gav, "./target/downloaded-jars");
    } catch (FileNotFoundException e) {
        fileWasUploaded = false;
    }

    Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded);
}

From source file:org.sonatype.nexus.integrationtests.nexus168.Nexus168SnapshotToReleaseIT.java

@Test
public void deployUsingRest() throws Exception {

    Gav gav = new Gav(this.getTestId(), "uploadWithGav", "1.0.0-SNAPSHOT", null, "xml", 0, new Date().getTime(),
            "Simple Test Artifact", false, null, false, null);

    // file to deploy
    File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension());

    // the Restlet Client does not support multipart forms: http://restlet.tigris.org/issues/show_bug.cgi?id=71

    // url to upload to
    String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content";

    // the method we are calling
    PostMethod filePost = new PostMethod(uploadURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_RELEASE_REPO, gav, fileToDeploy);

    if (status != HttpStatus.SC_BAD_REQUEST) {
        Assert.fail("Snapshot repositories do not allow manual file upload: " + status);
    }/*  www  .  j a v a  2  s . co  m*/

    boolean fileWasUploaded = true;
    try {
        // download it
        downloadArtifact(gav, "./target/downloaded-jars");
    } catch (FileNotFoundException e) {
        fileWasUploaded = false;
    }

    Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded);
}

From source file:org.sonatype.nexus.integrationtests.nexus176.Nexus176DeployToInvalidRepoIT.java

@Test
public void wagonDeployTest() throws Exception {

    Gav gav = new Gav(this.getTestId(), "simpleArtifact", "1.0.0", null, "xml", 0, new Date().getTime(),
            "Simple Test Artifact", false, null, false, null);

    // file to deploy
    File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension());

    // url to upload to
    String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content";

    // the method we are calling
    PostMethod filePost = new PostMethod(uploadURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_RELEASE_REPO, gav, fileToDeploy);

    if (status != HttpStatus.SC_NOT_FOUND) {
        Assert.fail("Upload attempt should have returned a 400, it returned:  " + status);
    }//from  w ww  .j  a  va 2 s . co m

    boolean fileWasUploaded = true;
    try {
        // download it
        downloadArtifact(gav, "./target/downloaded-jars");
    } catch (FileNotFoundException e) {
        fileWasUploaded = false;
    }

    Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded);

}

From source file:org.sonatype.nexus.integrationtests.nexus176.Nexus176DeployToInvalidRepoIT.java

@Test
public void deploywithGavUsingRest() throws Exception {

    Gav gav = new Gav(this.getTestId(), "uploadWithGav", "1.0.0", null, "xml", 0, new Date().getTime(),
            "Simple Test Artifact", false, null, false, null);

    // file to deploy
    File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension());

    // the Restlet Client does not support multipart forms: http://restlet.tigris.org/issues/show_bug.cgi?id=71

    // url to upload to
    String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content";

    // the method we are calling
    PostMethod filePost = new PostMethod(uploadURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_RELEASE_REPO, gav, fileToDeploy);

    if (status != HttpStatus.SC_NOT_FOUND) {
        Assert.fail("Upload attempt should have returned a 400, it returned:  " + status);
    }/*from www. ja  v a2  s. c  om*/

    boolean fileWasUploaded = true;
    try {
        // download it
        downloadArtifact(gav, "./target/downloaded-jars");
    } catch (FileNotFoundException e) {
        fileWasUploaded = false;
    }

    Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded);

}

From source file:org.sonatype.nexus.integrationtests.nexus176.Nexus176DeployToInvalidRepoIT.java

@Test
public void wagonSnapshotDeployTest() throws Exception {

    Gav gav = new Gav(this.getTestId(), "simpleArtifact", "1.0.0-SNAPSHOT", null, "xml", 0,
            new Date().getTime(), "Simple Test Artifact", false, null, false, null);

    // file to deploy
    File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension());

    // url to upload to
    String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content";

    // the method we are calling
    PostMethod filePost = new PostMethod(uploadURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_RELEASE_REPO, gav, fileToDeploy);

    if (status != HttpStatus.SC_NOT_FOUND) {
        Assert.fail("Upload attempt should have returned a 400, it returned:  " + status);
    }//from  w w w  .  j a v a  2s  .  c  o  m

    boolean fileWasUploaded = true;
    try {
        // download it
        downloadArtifact(gav, "./target/downloaded-jars");
    } catch (FileNotFoundException e) {
        fileWasUploaded = false;
    }

    Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded);

}

From source file:org.sonatype.nexus.integrationtests.nexus176.Nexus176DeployToInvalidRepoIT.java

@Test
public void deploySnapshotWithGavUsingRest() throws Exception {

    Gav gav = new Gav(this.getTestId(), "uploadWithGav", "1.0.0-SNAPSHOT", null, "xml", 0, new Date().getTime(),
            "Simple Test Artifact", false, null, false, null);

    // file to deploy
    File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension());

    // the Restlet Client does not support multipart forms: http://restlet.tigris.org/issues/show_bug.cgi?id=71

    // url to upload to
    String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content";

    // the method we are calling
    PostMethod filePost = new PostMethod(uploadURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_RELEASE_REPO, gav, fileToDeploy);

    if (status != HttpStatus.SC_NOT_FOUND) {
        Assert.fail("Upload attempt should have returned a 400, it returned:  " + status);
    }/*w w  w .  j  av a  2s.c  o  m*/

    boolean fileWasUploaded = true;
    try {
        // download it
        downloadArtifact(gav, "./target/downloaded-jars");
    } catch (FileNotFoundException e) {
        fileWasUploaded = false;
    }

    Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded);

}

From source file:org.sonatype.nexus.test.utils.DeployUtils.java

public int deployUsingGavWithRest(final String restServiceURL, final String repositoryId, final Gav gav,
        final File fileToDeploy) throws IOException {
    // the method we are calling
    final PostMethod filePost = new PostMethod(restServiceURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    final String extension = gav.getExtension() != null ? gav.getExtension() : "";
    final String classifier = gav.getClassifier() != null ? gav.getClassifier() : "";

    final Part[] parts = { new StringPart("r", repositoryId), new StringPart("g", gav.getGroupId()),
            new StringPart("a", gav.getArtifactId()), new StringPart("v", gav.getVersion()),
            new StringPart("p", extension), new StringPart("c", classifier),
            new FilePart(fileToDeploy.getName(), fileToDeploy) };

    filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

    return nexusRestClient.executeHTTPClientMethod(filePost).getStatusCode();

}

From source file:org.sonatype.nexus.test.utils.DeployUtils.java

public HttpMethod deployUsingPomWithRestReturnResult(final String restServiceURL, final String repositoryId,
        final File fileToDeploy, final File pomFile, final String classifier, final String extension)
        throws IOException {
    // the method we are calling
    final PostMethod filePost = new PostMethod(restServiceURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    final String fixedClassifier = (classifier == null) ? "" : classifier;
    final String fixedExtension = (extension == null) ? "" : extension;

    final Part[] parts = { new StringPart("r", repositoryId), new StringPart("e", fixedExtension),
            new StringPart("c", fixedClassifier), new StringPart("hasPom", "true"),
            new FilePart(pomFile.getName(), pomFile), new FilePart(fileToDeploy.getName(), fileToDeploy) };

    filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

    LOG.debug("URL:  " + restServiceURL);
    LOG.debug("Method: Post");
    LOG.debug("params: ");
    LOG.debug("\tr: " + repositoryId);
    LOG.debug("\thasPom: true");
    LOG.debug("\tpom: " + pomFile);
    LOG.debug("\tfileToDeploy: " + fileToDeploy);

    return nexusRestClient.executeHTTPClientMethod(filePost);
}

From source file:org.sonatype.nexus.test.utils.DeployUtils.java

public HttpMethod deployPomWithRest(final String repositoryId, final File pomFile) throws IOException {
    // the method we are calling
    final PostMethod filePost = new PostMethod(
            nexusRestClient.toNexusURL("service/local/artifact/maven/content").toExternalForm());
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    final Part[] parts = { new StringPart("r", repositoryId), new StringPart("hasPom", "true"),
            new FilePart(pomFile.getName(), pomFile) };

    filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

    LOG.debug("URL:  " + filePost.getURI());
    LOG.debug("Method: Post");
    LOG.debug("params: ");
    LOG.debug("\tr: " + repositoryId);
    LOG.debug("\thasPom: true");
    LOG.debug("\tpom: " + pomFile);

    return nexusRestClient.executeHTTPClientMethod(filePost);
}

From source file:org.sonatype.nexus.test.utils.DeployUtils.java

public int deployWithRest(final String restServiceURL, final String repositoryId, final String groupId,
        final String artifactId, final String version, final String classifier, final String extension,
        final File fileToDeploy) throws IOException {
    // the method we are calling
    final PostMethod filePost = new PostMethod(restServiceURL);
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);

    final Part[] parts = { new StringPart("r", repositoryId), new StringPart("g", groupId),
            new StringPart("a", artifactId), new StringPart("v", version),
            new StringPart("p", extension == null ? "" : extension),
            new StringPart("c", classifier == null ? "" : classifier),
            new FilePart(fileToDeploy.getName(), fileToDeploy) };

    filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

    return nexusRestClient.executeHTTPClientMethod(filePost).getStatusCode();

}