Search in sources :

Example 1 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class AbstractRemoteRepoTimeoutTest method run.

public void run() throws Exception {
    final String repo1 = "repo1";
    final String path = "org/foo/bar/maven-metadata.xml";
    server.expect(server.formatUrl(repo1, path), 200, new DelayInputStream());
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    setRemoteTimeout(remote1);
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    try (InputStream is = client.content().get(remote, repo1, path)) {
    } catch (final IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(HttpStatus.SC_BAD_GATEWAY));
    }
    Thread.sleep(1000);
    RemoteRepository result = client.stores().load(remote, repo1, RemoteRepository.class);
    assertResult(result);
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException)

Example 2 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class ReaonlyHostedStoreFileTest method storeFileNotAllowed.

@Test
public void storeFileNotAllowed() throws Exception {
    final String content = "This is a test: " + System.nanoTime();
    InputStream stream = new ByteArrayInputStream(content.getBytes());
    final String path = "/path/to/foo.class";
    final String repoName = "test-hosted";
    HostedRepository repo = new HostedRepository(repoName);
    repo.setReadonly(true);
    repo = client.stores().create(repo, name.getMethodName(), HostedRepository.class);
    assertThat(client.content().exists(hosted, repoName, path), equalTo(false));
    try {
        client.content().store(hosted, repoName, path, stream);
    } catch (IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(ApplicationStatus.METHOD_NOT_ALLOWED.code()));
    }
    assertThat(client.content().exists(hosted, repoName, path), equalTo(false));
    repo.setReadonly(false);
    client.stores().update(repo, name.getMethodName());
    stream = new ByteArrayInputStream(content.getBytes());
    client.content().store(hosted, repoName, path, stream);
    assertThat(client.content().exists(hosted, repoName, path), equalTo(true));
    final InputStream is = client.content().get(hosted, repoName, path);
    final String result = IOUtils.toString(is);
    is.close();
    assertThat(result, equalTo(content));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IndyClientException(org.commonjava.indy.client.core.IndyClientException) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 3 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class RemoteRepoGetTimeoutTest method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    final String path = "org/foo/bar/maven-metadata.xml";
    server.expect(server.formatUrl(repo1, path), 200, new DelayInputStream());
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    try (InputStream is = client.content().get(remote, repo1, path)) {
    } catch (final IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(HttpStatus.SC_BAD_GATEWAY));
    }
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 4 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class RemoteRepoHeadExistenceCheckTest method run.

@Ignore
@Test
public void run() throws Exception {
    final InputStream stream = new ByteArrayInputStream(("{\"content\": \"This is a test: " + System.nanoTime() + "\"}").getBytes());
    final String path = "org/foo/foo-project/1/foo-1.txt";
    final String nonExistPath = "org/foo/foo-project/1/foo-2.txt";
    server.expect(server.formatUrl(STORE, path), 200, stream);
    server.expect(server.formatUrl(STORE, nonExistPath), 404, "not exist");
    client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding test proxy", RemoteRepository.class);
    final PathInfo result = client.content().getInfo(remote, STORE, path);
    try {
        boolean exists = client.content().exists(remote, STORE, path);
        assertTrue(exists);
        File f = new File(new File(fixture.getBootOptions().getHomeDir()), "var/lib/indy/storage/remote-test/" + path);
        assertTrue(!f.exists());
        // TODO: this breaks because for whatever reason the head can not get content-length and we have to fall over to get().
        // Refer to NCL-2729 and we will have a better fix in future
        exists = client.content().exists(remote, STORE, nonExistPath);
        assertFalse(exists);
    } catch (final IndyClientException e) {
        fail("IndyClientException: " + e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) IndyClientException(org.commonjava.indy.client.core.IndyClientException) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 5 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class IndyFoloAdminClientModule method sealTrackingRecord.

public boolean sealTrackingRecord(String trackingId) throws IndyClientException {
    http.connect();
    HttpPost request = http.newRawPost(UrlUtils.buildUrl(http.getBaseUrl(), "/folo/admin", trackingId, "record"));
    HttpResources resources = null;
    try {
        resources = http.execute(request);
        HttpResponse response = resources.getResponse();
        StatusLine sl = response.getStatusLine();
        if (sl.getStatusCode() != 200) {
            if (sl.getStatusCode() == 404) {
                return false;
            }
            throw new IndyClientException(sl.getStatusCode(), "Error sealing tracking record %s.\n%s", trackingId, new IndyResponseErrorDetails(response));
        }
        return true;
    } finally {
        IOUtils.closeQuietly(resources);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) HttpPost(org.apache.http.client.methods.HttpPost) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpResponse(org.apache.http.HttpResponse) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IndyResponseErrorDetails(org.commonjava.indy.client.core.IndyResponseErrorDetails)

Aggregations

IndyClientException (org.commonjava.indy.client.core.IndyClientException)31 Test (org.junit.Test)21 InputStream (java.io.InputStream)17 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)13 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)12 HostedRepository (org.commonjava.indy.model.core.HostedRepository)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 StoreKey (org.commonjava.indy.model.core.StoreKey)9 IOException (java.io.IOException)6 HttpResources (org.commonjava.indy.client.core.helper.HttpResources)5 HttpResponse (org.apache.http.HttpResponse)3 StatusLine (org.apache.http.StatusLine)3 AbstractIndyFunctionalTest (org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest)3 Logger (org.slf4j.Logger)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 CountingInputStream (org.apache.commons.io.input.CountingInputStream)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2 IndyClientHttp (org.commonjava.indy.client.core.IndyClientHttp)2