use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class MavenFileRepository method fetch.
@Override
public TaggedData fetch(String path, File dest) throws Exception {
File source = getFile(path);
if (source.isFile()) {
IO.mkdirs(dest.getParentFile());
IO.copy(source, dest);
return new TaggedData(toURI(path), 200, dest);
} else {
return new TaggedData(toURI(path), 404, dest);
}
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class MavenRemoteRepository method delete.
public boolean delete(String path) throws Exception {
URL url = new URL(base + path);
TaggedData go = client.build().put().delete().get(TaggedData.class).go(url);
if (go == null)
return false;
if (go.getResponseCode() == HttpURLConnection.HTTP_OK || go.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
client.build().delete().async(new URL(base + path + ".sha1"));
client.build().delete().async(new URL(base + path + ".md5"));
return true;
}
throw new HttpRequestException(go);
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class MavenBackingRepository method getMetadata.
ProgramMetadata getMetadata(Program program) throws Exception {
File metafile = IO.getFile(local, program.metadata(id));
ProgramMetadata metadata = programs.get(program);
TaggedData tag = fetch(program.metadata(), metafile);
switch(tag.getState()) {
case NOT_FOUND:
return null;
case OTHER:
throw new IOException("Failed " + tag.getResponseCode());
case UNMODIFIED:
if (metadata != null)
return metadata;
case UPDATED:
default:
metadata = MetadataParser.parseProgramMetadata(metafile);
programs.put(program, metadata);
return metadata;
}
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpConnectorTest method testConnectKnownTag.
public static void testConnectKnownTag() throws Exception {
DefaultURLConnector connector = new DefaultURLConnector();
TaggedData data = connector.connectTagged(new URL(getUrl(true) + "bundles/dummybundle.jar"), EXPECTED_ETAG);
assertNull("Data should be null since ETag not modified.", data);
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpClient method doConnect.
private TaggedData doConnect(Object put, Type ref, final URLConnection con, final HttpURLConnection hcon, HttpRequest<?> request, ProgressPlugin.Task task) throws IOException, Exception {
if (put != null) {
task.worked(1);
doOutput(put, con, request);
} else
logger.debug("{} {}", request.verb, request.url);
if (request.timeout > 0) {
con.setConnectTimeout((int) request.timeout * 10);
con.setReadTimeout((int) (5000 > request.timeout ? request.timeout : 5000));
} else {
con.setConnectTimeout(120000);
con.setReadTimeout(60000);
}
try {
if (hcon == null) {
// not http
try {
con.connect();
InputStream in = con.getInputStream();
return new TaggedData(con, in, request.useCacheFile);
} catch (FileNotFoundException e) {
task.done("file not found", e);
return new TaggedData(con.getURL().toURI(), 404, request.useCacheFile);
}
}
int code = hcon.getResponseCode();
if (code == -1)
System.out.println("WTF?");
if (code == HttpURLConnection.HTTP_MOVED_TEMP || code == HttpURLConnection.HTTP_MOVED_PERM || code == HttpURLConnection.HTTP_SEE_OTHER) {
if (request.redirects-- > 0) {
String location = hcon.getHeaderField("Location");
request.url = new URL(location);
task.done("redirected", null);
return send0(request);
}
}
if (isUpdateInfo(con, request, code)) {
File file = (File) request.upload;
String etag = con.getHeaderField("ETag");
try (Info info = cache.get(file, con.getURL().toURI())) {
info.update(etag);
}
}
if ((code / 100) != 2) {
task.done("finished", null);
return new TaggedData(con, null, request.useCacheFile);
}
// Do not enclose in resource try! InputStream is potentially
// used
// later
InputStream xin = con.getInputStream();
InputStream in = handleContentEncoding(hcon, xin);
in = createProgressWrappedStream(in, con.toString(), con.getContentLength(), task, request.timeout);
return new TaggedData(con, in, request.useCacheFile);
} catch (SocketTimeoutException ste) {
task.done(ste.toString(), null);
return new TaggedData(request.url.toURI(), HttpURLConnection.HTTP_GATEWAY_TIMEOUT, request.useCacheFile);
}
}
Aggregations