use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class RemoteRepoTimeoutDisablesThenReEnabledTest method run.
@Test
@Category(TimingDependent.class)
public void run() throws Exception {
final String repo1 = "repo1";
final String path = "org/foo/bar/maven-metadata.xml";
server.expect(server.formatUrl("repo1/"), 200, "OK");
server.expect("GET", server.formatUrl(repo1, path), (req, resp) -> {
try {
Thread.sleep(5000);
} catch (final InterruptedException e) {
}
resp.setStatus(404);
});
RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
remote1.setTimeoutSeconds(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));
}
Thread.sleep(1000);
RemoteRepository result = client.stores().load(remote, repo1, RemoteRepository.class);
assertThat(result.isDisabled(), equalTo(true));
Thread.sleep(4000);
result = client.stores().load(remote, repo1, RemoteRepository.class);
assertThat(result.isDisabled(), equalTo(false));
}
use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class ReadonlyHostedRepoDeleteTest method addReadonlyHostedAndDelete.
@Test
public void addReadonlyHostedAndDelete() throws Exception {
final HostedRepository repo = new HostedRepository(newName());
repo.setReadonly(true);
final HostedRepository result = client.stores().create(repo, name.getMethodName(), HostedRepository.class);
assertThat(result.getName(), equalTo(repo.getName()));
assertThat(result.equals(repo), equalTo(true));
try {
client.stores().delete(StoreType.hosted, repo.getName(), name.getMethodName());
} catch (IndyClientException e) {
assertThat(e.getStatusCode(), equalTo(ApplicationStatus.METHOD_NOT_ALLOWED.code()));
}
assertThat(client.stores().exists(StoreType.hosted, repo.getName()), equalTo(true));
result.setReadonly(false);
client.stores().update(result, name.getMethodName());
client.stores().delete(StoreType.hosted, repo.getName(), name.getMethodName());
assertThat(client.stores().exists(StoreType.hosted, repo.getName()), equalTo(false));
}
use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class HostedByArcDisableTest method testUploadZipAndCreate.
@Test
public void testUploadZipAndCreate() throws Exception {
IndyHostedByArchiveClientModule module = client.module(IndyHostedByArchiveClientModule.class);
final String hostedRepoName = "hosted-zip-ignore";
try {
module.createRepo(getZipFile(), hostedRepoName, "maven-repository");
} catch (IndyClientException e) {
logger.info(e.getMessage());
assertThat(e.getStatusCode(), equalTo(ApplicationStatus.METHOD_NOT_ALLOWED.code()));
}
}
use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class DelayedDownload method run.
@Override
public void run() {
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("Starting: {}", Thread.currentThread().getName());
if (initialDelay > 0) {
logger.info("Delaying: {}", initialDelay);
try {
Thread.sleep(initialDelay);
} catch (final InterruptedException e) {
return;
}
}
startTime = System.nanoTime();
content = new ByteArrayOutputStream();
logger.info("Trying: {}", Thread.currentThread().getName());
try (InputStream in = client.content().get(key, path)) {
if (in == null) {
missing = true;
} else {
CountingInputStream cin = new CountingInputStream(in);
IOUtils.copy(cin, content);
logger.debug("Read: {} bytes", cin.getByteCount());
}
} catch (IndyClientException | IOException e) {
e.printStackTrace();
}
endTime = System.nanoTime();
latch.countDown();
logger.info("Stopping: {}", Thread.currentThread().getName());
}
use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class IndySslValidationApiTest method run.
@Test
public void run() {
RemoteRepository storedTestRepo = null;
RemoteRepository storedTestSslRepo = null;
RemoteRepository storedTestAllowedRepo = null;
try {
HashMap<String, ArtifactStoreValidateData> remoteRepositoriesValidated = client.module(IndySslValidationClientModule.class).revalidateAllStores();
LOGGER.info("=> All Validated Remote Repositories Response: " + remoteRepositoriesValidated);
LOGGER.info("=> RESULT: " + remoteRepositoriesValidated.get(String.valueOf("maven:remote:central")));
assertNotNull(remoteRepositoriesValidated);
assertTrue(!remoteRepositoriesValidated.isEmpty());
} catch (IndyClientException e) {
LOGGER.warn("=> Exception in revalidating all store API call");
}
// REPO TESTING URL - http://repo.maven.apache.org/maven2 - NOT VALID NOT ALLOWED SSL REPO
try {
// first there is need for config variables to be set to false (remote.ssl.required , _internal.store.validation.enabled )
if (configuration.isSSLRequired() == true) {
configuration.setSslRequired(false);
}
if (featureConfig.getStoreValidation() == true) {
featureConfig.setStoreValidation(false);
}
RemoteRepository testRepo = new RemoteRepository("maven", "test", "http://repo.maven.apache.org/maven2");
LOGGER.info("=> Storing Remote RemoteRepository: " + testRepo.getUrl());
client.stores().create(testRepo, "Testing Remote RemoteRepository", RemoteRepository.class);
storedTestRepo = client.stores().load(remote, testRepo.getName(), RemoteRepository.class);
// now there is need for config varables to be set to true (remote.ssl.required , _internal.store.validation.enabled )
if (configuration.isSSLRequired() == false) {
configuration.setSslRequired(true);
}
if (featureConfig.getStoreValidation() == false) {
featureConfig.setStoreValidation(true);
}
LOGGER.info("=> Validating Remote RemoteRepository: " + testRepo.getUrl());
ArtifactStoreValidateData remoteRepoAPIResult = client.module(IndySslValidationClientModule.class).revalidateStore(storedTestRepo);
LOGGER.info("=> API Returned Result [Validate Remote Repo]: " + remoteRepoAPIResult);
assertNotNull(remoteRepoAPIResult);
assertFalse(remoteRepoAPIResult.isValid());
assertThat(remoteRepoAPIResult.getRepositoryUrl(), is(remoteRepoAPIResult.getErrors().get("NOT_ALLOWED_SSL")));
} catch (IndyClientException e) {
LOGGER.warn("=> Exception in revalidating store " + storedTestRepo.getUrl() + " API call");
}
// REPO TESTING URL - https://repo.maven.apache.org/maven2 - VALID SSL REPO
try {
RemoteRepository testRepoSsl = new RemoteRepository("maven", "test-ssl", "https://repo.maven.apache" + ".org/maven2");
LOGGER.info("=> Storing Remote RemoteRepository: " + testRepoSsl.getUrl());
client.stores().create(testRepoSsl, "Testing SSL Remote RemoteRepository", RemoteRepository.class);
storedTestSslRepo = client.stores().load(remote, testRepoSsl.getName(), RemoteRepository.class);
LOGGER.info("=> Validating Remote RemoteRepository: " + testRepoSsl.getUrl());
ArtifactStoreValidateData remoteSslRepoAPIResult = client.module(IndySslValidationClientModule.class).revalidateStore(storedTestSslRepo);
LOGGER.info("=> API Returned Result [Validate Remote Repo]: " + remoteSslRepoAPIResult);
assertNotNull(remoteSslRepoAPIResult);
assertTrue(remoteSslRepoAPIResult.isValid());
assertThat(String.valueOf(200), is(remoteSslRepoAPIResult.getErrors().get("HTTP_HEAD_STATUS")));
assertThat(String.valueOf(200), is(remoteSslRepoAPIResult.getErrors().get("HTTP_GET_STATUS")));
} catch (IndyClientException ice) {
LOGGER.warn("=> Exception in revalidating store " + storedTestSslRepo + " API call");
}
// REPO TESTING URL - https://repo.maven.apache.org/maven2 - NOT VALID , ALLOWED , NOT AVAILABLE NON-SSL REPO
try {
RemoteRepository testRepoAllowed = new RemoteRepository("maven", "test-ssl", "http://127.0.0.1/maven2");
// first there is need for config variables to be set to false (remote.ssl.required , _internal.store.validation.enabled )
if (configuration.isSSLRequired() == true) {
configuration.setSslRequired(false);
}
if (featureConfig.getStoreValidation() == true) {
featureConfig.setStoreValidation(false);
}
LOGGER.info("=> Storing Remote RemoteRepository: " + testRepoAllowed.getUrl());
client.stores().create(testRepoAllowed, "Testing SSL Remote RemoteRepository", RemoteRepository.class);
storedTestAllowedRepo = client.stores().load(remote, testRepoAllowed.getName(), RemoteRepository.class);
// now there is need for config varables to be set to true (remote.ssl.required , _internal.store.validation.enabled )
if (configuration.isSSLRequired() == false) {
configuration.setSslRequired(true);
}
if (featureConfig.getStoreValidation() == false) {
featureConfig.setStoreValidation(true);
}
LOGGER.info("=> Validating Remote RemoteRepository: " + testRepoAllowed.getUrl());
ArtifactStoreValidateData remoteAllowedRepoAPIResult = client.module(IndySslValidationClientModule.class).revalidateStore(storedTestSslRepo);
LOGGER.info("=> API Returned Result [Validate Remote Repo]: " + remoteAllowedRepoAPIResult);
assertNotNull(remoteAllowedRepoAPIResult);
assertFalse(remoteAllowedRepoAPIResult.isValid());
assertTrue(remoteAllowedRepoAPIResult.getErrors().keySet().contains("Exception"));
} catch (IndyClientException ice) {
LOGGER.warn("=> Exception in revalidating store " + storedTestAllowedRepo.getUrl() + " API call");
}
// GET ALL VALIDATED REMOTE REPOSITORIES
try {
HashMap<String, ArtifactStoreValidateData> remoteSslRepositoriesValidated = client.module(IndySslValidationClientModule.class).revalidateAllStores();
LOGGER.info("=> All Validated Remote Repositories Response: " + remoteSslRepositoriesValidated);
assertNotNull(remoteSslRepositoriesValidated);
assertTrue(!remoteSslRepositoriesValidated.isEmpty());
} catch (IndyClientException ice) {
LOGGER.warn("=> Exception in revalidating SECOND all store API call");
}
}
Aggregations