use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class CentralTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
tmpName = "generated/tmp/test/" + getName();
local = IO.getFile(tmpName + "/local");
reporter.setTrace(true);
Config config = new Config();
IO.delete(local);
local.mkdirs();
repo = MavenRemoteRepository.create(REPO_URL, reporter, local, new HttpClient());
storage = new MavenRepository(local, "central", this.repo, null, null, null, null);
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class MavenBndRepoTest method config.
void config(Map<String, String> override) throws Exception {
Map<String, String> config = new HashMap<>();
config.put("local", tmpName + "/local");
config.put("index", tmpName + "/index");
config.put("releaseUrl", fnx.getBaseURI() + "/repo/");
if (override != null)
config.putAll(override);
reporter = new Processor();
reporter.addBasicPlugin(new ProgressPlugin() {
@Override
public Task startTask(final String name, int size) {
System.out.println("Starting " + name);
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 + " " + e);
}
@Override
public boolean isCanceled() {
return false;
}
};
}
});
HttpClient client = new HttpClient();
client.setRegistry(reporter);
Executor executor = Executors.newCachedThreadPool();
reporter.addBasicPlugin(client);
reporter.setTrace(true);
repo = new MavenBndRepository();
repo.setReporter(reporter);
repo.setRegistry(reporter);
repo.setProperties(config);
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientProxyTest method assertSocks5Proxy.
@SuppressWarnings("resource")
void assertSocks5Proxy(String password, boolean authenticationCalled) throws MalformedURLException, Exception {
Processor p = new Processor();
p.setProperty("-connectionsettings", "" + false);
HttpClient hc = new HttpClient();
ConnectionSettings cs = new ConnectionSettings(p, hc);
if (socks5Proxy != null) {
ProxyDTO proxy = new ProxyDTO();
proxy.active = true;
proxy.host = "localhost";
proxy.port = socksProxyPort;
proxy.protocol = Type.SOCKS;
if (password != null) {
proxy.username = "proxyuser";
proxy.password = password;
}
hc.addProxyHandler(ConnectionSettings.createProxyHandler(proxy));
}
ServerDTO server = new ServerDTO();
server.id = httpTestServer.getBaseURI().toString();
server.verify = false;
server.trust = Strings.join(httpTestServer.getTrustedCertificateFiles(IO.getFile("generated")));
cs.add(server);
URL url = new URL(httpTestServer.getBaseURI() + "/get-tag/ABCDEFGH");
TaggedData tag = hc.connectTagged(url);
assertNotNull(tag);
assertEquals("ABCDEFGH", tag.getTag());
String s = IO.collect(tag.getInputStream());
assertNotNull(s);
assertTrue(s.trim().startsWith("{"));
// assertTrue(this.authenticationCalled.get() == authenticationCalled);
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientTest method testCachingMultipleFetch.
public void testCachingMultipleFetch() throws Exception {
try (HttpClient hc = new HttpClient()) {
hc.setCache(tmp);
Promise<TaggedData> a = hc.build().useCache().age(1, TimeUnit.DAYS).asTag().async(httpServer.getBaseURI("mftch"));
Thread.sleep(100);
Promise<TaggedData> b = hc.build().useCache().age(1, TimeUnit.DAYS).asTag().async(httpServer.getBaseURI("mftch"));
TaggedData ta = a.getValue();
assertEquals("FOO", ta.getTag());
assertEquals(200, ta.getResponseCode());
assertEquals(true, ta.hasPayload());
assertEquals(true, ta.isOk());
assertEquals(State.UPDATED, ta.getState());
TaggedData tb = b.getValue();
assertEquals("FOO", tb.getTag());
assertEquals(304, tb.getResponseCode());
assertEquals(false, tb.hasPayload());
assertEquals(State.UNMODIFIED, tb.getState());
System.out.println(a.getValue());
System.out.println(b.getValue());
}
}
use of aQute.bnd.http.HttpClient in project bnd by bndtools.
the class HttpClientCacheTest method testGetNewThenUnmodifiedThenModified.
public void testGetNewThenUnmodifiedThenModified() throws URISyntaxException, Exception {
try (HttpClient client = new HttpClient()) {
client.setCache(cache);
// Set a tag, but it must always fetch the file
etag = "1234";
File go1 = client.build().useCache().go(new URI(httpServer.getBaseURI() + "/testetag"));
assertTrue(go1.isFile());
assertEquals("1234", IO.collect(go1));
// Set time very old so we can see if the file is updated
go1.setLastModified(1000);
File go2 = client.build().useCache().go(new URI(httpServer.getBaseURI() + "/testetag"));
assertEquals(go1, go2);
assertEquals("1234", IO.collect(go1));
assertEquals(1000, go2.lastModified());
// New tag (i.e. file is updated on server) but we use the stale
// period to NOT fetch a new one
etag = "5678";
go1.setLastModified(System.currentTimeMillis());
File go3 = client.build().useCache(10000).go(new URI(httpServer.getBaseURI() + "/testetag"));
assertEquals(go1, go3);
assertEquals("1234", IO.collect(go3));
// We have a stale copy, see if we fetch a new copy
File go4 = client.build().useCache().go(new URI(httpServer.getBaseURI() + "/testetag"));
assertEquals(go1, go4);
assertEquals("5678", IO.collect(go3));
}
}
Aggregations