use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class OSGiRepositoryTest method testSimple.
public void testSimple() throws Exception {
try (OSGiRepository r = new OSGiRepository()) {
Map<String, String> map = new HashMap<>();
map.put("locations", fnx.getBaseURI("/repo/minir5.xml").toString());
map.put("cache", cache.getPath());
map.put("max.stale", "10000");
r.setProperties(map);
Processor p = new Processor();
HttpClient httpClient = new HttpClient();
httpClient.setCache(cache);
httpClient.setRegistry(p);
p.addBasicPlugin(httpClient);
p.setBase(ws);
p.addBasicPlugin(Workspace.createStandaloneWorkspace(p, ws.toURI()));
r.setRegistry(p);
final AtomicInteger tasks = new AtomicInteger();
p.addBasicPlugin(new ProgressPlugin() {
@Override
public Task startTask(final String name, int size) {
System.out.println("Starting " + name);
tasks.incrementAndGet();
return new Task() {
@Override
public void worked(int units) {
System.out.println("Worked " + name + " " + units);
}
@Override
public void done(String message, Throwable e) {
System.out.println("Done " + name + " " + message);
}
@Override
public boolean isCanceled() {
return false;
}
};
}
});
assertEquals(0, tasks.get());
File file = r.get("dummybundle", new Version("0"), null);
assertNotNull(file);
// 2 = index + file
assertEquals(2, tasks.get());
File file2 = r.get("dummybundle", new Version("0"), null);
assertNotNull(file2);
// second one should not have downloaded
assertEquals(2, tasks.get());
r.refresh();
File file3 = r.get("dummybundle", new Version("0"), null);
assertNotNull(file3);
// second one should not have downloaded
assertEquals(2, tasks.get());
}
}
use of aQute.bnd.http.HttpClient 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.http.HttpClient 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());
}
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class IndexedReposWithComms method testBasicWorkspace.
public void testBasicWorkspace() throws Exception {
HttpTestServer ht = http();
try {
createSecureSocks5();
Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/basic"));
assertNotNull(ws);
List<URLConnector> connectors = ws.getPlugins(URLConnector.class);
assertNotNull(connectors);
assertEquals(1, connectors.size());
assertTrue(connectors.get(0) instanceof HttpClient);
HttpClient hc = (HttpClient) connectors.get(0);
InputStream connect = hc.connect(new URL(ht.getBaseURI() + "/basic-auth/user/good"));
assertNotNull(connect);
aQute.lib.io.IO.copy(connect, System.out);
connect.close();
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
} finally {
ht.close();
}
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientTest method testRedirectTooMany.
public void testRedirectTooMany() throws Exception {
try (HttpClient hc = new HttpClient()) {
TaggedData tag = hc.build().maxRedirects(3).get(TaggedData.class).go(httpServer.getBaseURI("redirect/200/200"));
assertEquals(3, tag.getResponseCode() / 100);
}
}
Aggregations