use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpClientTest method testRedirectURL.
public void testRedirectURL() throws Exception {
try (HttpClient hc = new HttpClient()) {
HttpsVerification httpsVerification = new HttpsVerification(httpsServer.getCertificateChain(), false, hc.getReporter());
hc.addURLConnectionHandler(httpsVerification);
URI uri = httpsServer.getBaseURI("get");
URL go = httpServer.getBaseURI("xlocation").toURL();
TaggedData tag = hc.build().maxRedirects(3).get(TaggedData.class).headers("XLocation", uri.toString()).go(go);
assertNotNull(tag);
assertEquals(200, tag.getResponseCode());
}
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpClientTest method testNotModifiedEtag.
public void testNotModifiedEtag() throws Exception {
try (HttpClient hc = new HttpClient()) {
TaggedData data = hc.build().get(TaggedData.class).ifNoneMatch("1234").go(httpServer.getBaseURI("etag/1234/0"));
assertNotNull(data);
assertEquals("1234", data.getTag());
assertEquals(HttpURLConnection.HTTP_NOT_MODIFIED, data.getResponseCode());
}
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpClientTest method testCancel.
public void testCancel() throws Exception {
final long deadline = System.currentTimeMillis() + 1000L;
try (HttpClient hc = new HttpClient()) {
Processor p = new Processor();
p.addBasicPlugin(new ProgressPlugin() {
@Override
public Task startTask(String name, int size) {
return new Task() {
@Override
public void worked(int units) {
System.out.println("Worked " + units);
}
@Override
public void done(String message, Throwable e) {
System.out.println("Done " + message + " " + e);
}
@Override
public boolean isCanceled() {
System.out.println("Cancel check ");
return System.currentTimeMillis() > deadline;
}
};
}
});
hc.setRegistry(p);
TaggedData tag = hc.build().asTag().go(httpServer.getBaseURI("timeout/50"));
assertNotNull(tag);
assertEquals(200, tag.getResponseCode());
try {
String s = IO.collect(tag.getInputStream());
fail();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpClientTest method testTimeout.
public void testTimeout() throws Exception {
try (HttpClient hc = new HttpClient()) {
try {
TaggedData tag = hc.build().asTag().timeout(1000).go(httpServer.getBaseURI("timeout/10"));
assertNotNull(tag);
assertEquals(200, tag.getResponseCode());
IO.collect(tag.getInputStream());
fail();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of aQute.bnd.service.url.TaggedData in project bnd by bndtools.
the class HttpClientTest method testRedirect.
public void testRedirect() throws Exception {
try (HttpClient hc = new HttpClient()) {
TaggedData tag = hc.build().get(TaggedData.class).go(httpServer.getBaseURI("redirect/3/200"));
assertNotNull(tag);
assertEquals(200, tag.getResponseCode());
}
}
Aggregations