use of org.commonjava.indy.client.core.helper.HttpResources in project indy by Commonjava.
the class DownloadContentHasLengthHeaderTest method proxyRemoteArtifact.
@Test
public void proxyRemoteArtifact() throws Exception {
byte[] data = ("This is a test: " + System.nanoTime()).getBytes();
final InputStream stream = new ByteArrayInputStream(data);
final String path = "org/foo/foo-project/1/foo-1.txt";
server.expect(server.formatUrl(STORE, path), 200, stream);
client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding test proxy", RemoteRepository.class);
try (HttpResources httpResources = client.module(IndyRawHttpModule.class).getHttp().getRaw(client.content().contentPath(remote, STORE, path))) {
HttpResponse response = httpResources.getResponse();
String contentLength = response.getFirstHeader("Content-Length").getValue();
assertThat("Wrong content-length for download: " + contentLength + " (should have been: " + data.length + ")", contentLength, equalTo(Integer.toString(data.length)));
}
final PathInfo result = client.content().getInfo(remote, STORE, path);
assertThat("no result", result, notNullValue());
assertThat("doesn't exist", result.exists(), equalTo(true));
}
use of org.commonjava.indy.client.core.helper.HttpResources in project indy by Commonjava.
the class IndyClientHttp method getRaw.
public HttpResources getRaw(final String path, final Map<String, String> headers) throws IndyClientException {
connect();
CloseableHttpResponse response = null;
try {
final HttpGet req = newRawGet(buildUrl(baseUrl, path));
final CloseableHttpClient client = newClient();
response = client.execute(req, newContext());
return new HttpResources(req, response, client);
} catch (final IOException e) {
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
// DO NOT CLOSE!!!! We're handing off control of the response to the caller!
// closeQuietly( response );
}
}
use of org.commonjava.indy.client.core.helper.HttpResources in project indy by Commonjava.
the class IndyClientHttp method getRaw.
public HttpResources getRaw(final HttpGet req) throws IndyClientException {
connect();
CloseableHttpResponse response = null;
try {
final CloseableHttpClient client = newClient();
response = client.execute(req, newContext());
return new HttpResources(req, response, client);
} catch (final IOException e) {
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
// DO NOT CLOSE!!!! We're handing off control of the response to the caller!
// closeQuietly( response );
}
}
use of org.commonjava.indy.client.core.helper.HttpResources in project indy by Commonjava.
the class SettingsGeneratedForRemoteRepoTest method generateSettingsXml.
@Test
public void generateSettingsXml() throws Exception {
final IndyClientHttp http = getHttp();
// all mavdav requests are siblings of the default base-url suffix '/api/'
final String url = getDotMavenUrl("settings/remote/settings-central.xml");
System.out.println("Requesting: " + url);
final HttpResources resources = http.getRaw(new HttpGet(url));
InputStream stream = null;
Settings settings = null;
try {
stream = resources.getResponseStream();
settings = new SettingsXpp3Reader().read(stream);
} finally {
closeQuietly(stream);
closeQuietly(resources);
}
assertThat(settings.getLocalRepository(), equalTo("${user.home}/.m2/repo-remote-central"));
assertThat(settings.getMirrors(), notNullValue());
assertThat(settings.getMirrors().size(), equalTo(1));
final Mirror mirror = settings.getMirrors().get(0);
assertThat(mirror.getUrl(), equalTo(http.toIndyUrl("remote/central")));
}
use of org.commonjava.indy.client.core.helper.HttpResources 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