use of org.osgi.service.http.runtime.dto.RequestInfoDTO in project aries by apache.
the class HttpTestCase method testSessionBean.
public void testSessionBean() throws Exception {
Bundle tb5Bundle = installBundle("tb6.jar");
try {
String path = "/foo";
RequestInfoDTO requestInfoDTO = waitFor(path);
assertEquals("foo", requestInfoDTO.servletDTO.name);
HttpClientBuilder clientBuilder = hcbf.newBuilder();
CloseableHttpClient httpclient = clientBuilder.build();
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
URI uri = new URIBuilder(getEndpoint()).setPath(path).setParameter("name", "test").build();
HttpGet httpget = new HttpGet(uri);
try (CloseableHttpResponse response = httpclient.execute(httpget, httpContext)) {
HttpEntity entity = response.getEntity();
assertEquals("test", read(entity));
}
for (int i = 0; i < 10; i++) {
uri = new URIBuilder(getEndpoint()).setPath(path).build();
httpget = new HttpGet(uri);
try (CloseableHttpResponse response = httpclient.execute(httpget, httpContext)) {
HttpEntity entity = response.getEntity();
assertEquals("test", read(entity));
}
}
uri = new URIBuilder(getEndpoint()).setPath(path).build();
httpget = new HttpGet(uri);
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
HttpEntity entity = response.getEntity();
assertEquals("", read(entity));
}
} finally {
tb5Bundle.uninstall();
}
}
use of org.osgi.service.http.runtime.dto.RequestInfoDTO in project aries by apache.
the class HttpTestCase method waitFor.
private RequestInfoDTO waitFor(String path, int intervals) throws InterruptedException {
for (int j = intervals; j > 0; j--) {
RequestInfoDTO requestInfoDTO = hsr.calculateRequestInfoDTO(path);
if ((requestInfoDTO.servletDTO != null) || (requestInfoDTO.resourceDTO != null)) {
return requestInfoDTO;
}
Thread.sleep(50);
}
assertTrue(String.format("%s not found in time", path), false);
return null;
}
Aggregations