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);
}
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));
}
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));
}
}
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);
}
}
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);
}
}
Aggregations