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 HttpClientServerTest method assertOk.
@SuppressWarnings("resource")
private void assertOk(String password, boolean verify) throws Exception {
File log = new File(tmp, "log");
Processor p = new Processor();
p.setProperty("-connection-log", log.toURI().getPath());
HttpClient hc = new HttpClient();
hc.setLog(log);
ConnectionSettings cs = new ConnectionSettings(p, hc);
ServerDTO server = new ServerDTO();
server.id = httpServer.getBaseURI().toString();
server.verify = verify;
if (password != null) {
server.username = "user";
server.password = password;
}
server.trust = Strings.join(httpServer.getTrustedCertificateFiles(IO.getFile("generated")));
cs.add(server);
System.out.println(httpServer.getBaseURI());
URL url = password == null ? new URL(httpServer.getBaseURI() + "/get") : new URL(httpServer.getBaseURI() + "/basic-auth/user/good");
TaggedData tag = hc.connectTagged(url);
assertNotNull(tag);
String s = IO.collect(tag.getInputStream());
assertNotNull(s);
assertTrue(s.trim().startsWith("{"));
IO.copy(log, System.out);
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpClientTest method testModifiedSince.
public void testModifiedSince() throws Exception {
try (HttpClient hc = new HttpClient()) {
TaggedData data = hc.build().get(TaggedData.class).ifModifiedSince(10000).go(httpServer.getBaseURI("etag/1234/20000"));
assertNotNull(data);
assertEquals("1234", data.getTag());
assertEquals(200, data.getResponseCode());
}
try (HttpClient hc = new HttpClient()) {
TaggedData data = hc.build().get(TaggedData.class).ifModifiedSince(20000).go(httpServer.getBaseURI("etag/1234/10000"));
assertNotNull(data);
assertEquals("1234", data.getTag());
assertEquals(304, data.getResponseCode());
}
}
Aggregations