use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class OSGiIndex method isStale.
/**
* Check any of the URL indexes are stale.
*
* @return
* @throws Exception
*/
boolean isStale() throws Exception {
final Deferred<List<Void>> freshness = new Deferred<>();
List<Promise<Void>> promises = new ArrayList<>(getURIs().size());
for (final URI uri : getURIs()) {
if (freshness.getPromise().isDone()) {
// early exit if staleness already detected
break;
}
try {
Promise<TaggedData> async = client.build().useCache().asTag().async(uri);
promises.add(async.then(new Success<TaggedData, Void>() {
@Override
public Promise<Void> call(Promise<TaggedData> resolved) throws Exception {
switch(resolved.getValue().getState()) {
case OTHER:
// in the offline case
// ignore might be best here
logger.debug("Could not verify {}", uri);
break;
case UNMODIFIED:
break;
case NOT_FOUND:
case UPDATED:
default:
logger.debug("Found {} to be stale", uri);
freshness.fail(new Exception("stale"));
}
return null;
}
}, new Failure() {
@Override
public void fail(Promise<?> resolved) throws Exception {
logger.debug("Could not verify {}: {}", uri, resolved.getFailure());
freshness.fail(resolved.getFailure());
}
}));
} catch (Exception e) {
logger.debug("Checking stale status: {}: {}", uri, e);
}
}
// Resolve when all uris checked
Promise<List<Void>> all = Promises.all(promises);
freshness.resolveWith(all);
// Block until freshness is resolved
return freshness.getPromise().getFailure() != null;
}
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);
}
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class MavenRepository method fetch.
private State fetch(List<MavenBackingRepository> mbrs, String remotePath, File file) throws Exception {
State error = State.NOT_FOUND;
for (MavenBackingRepository mbr : mbrs) {
TaggedData fetch = mbr.fetch(remotePath, file);
switch(fetch.getState()) {
case NOT_FOUND:
break;
case OTHER:
error = State.OTHER;
logger.error("Fetching artifact gives error {}", remotePath);
break;
case UNMODIFIED:
case UPDATED:
return fetch.getState();
}
}
return error;
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpConnectorTest method testConnectTagModified.
public static void testConnectTagModified() throws Exception {
DefaultURLConnector connector = new DefaultURLConnector();
TaggedData data = connector.connectTagged(new URL(getUrl(true) + "bundles/dummybundle.jar"), "00000000");
assertNotNull("Data should be non-null because ETag was different", data);
data.getInputStream().close();
assertEquals("ETag is incorrect", EXPECTED_ETAG, data.getTag());
}
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);
}
}
Aggregations