use of org.osgi.service.http.HttpContext in project camel by apache.
the class OsgiServletRegisterer method register.
public void register() throws Exception {
ObjectHelper.notEmpty(alias, "alias", this);
ObjectHelper.notEmpty(servletName, "servletName", this);
HttpContext actualHttpContext = (httpContext == null) ? httpService.createDefaultHttpContext() : httpContext;
final Dictionary<String, String> initParams = new Hashtable<String, String>();
initParams.put("matchOnUriPrefix", matchOnUriPrefix ? "true" : "false");
initParams.put("servlet-name", servletName);
httpService.registerServlet(alias, servlet, initParams, actualHttpContext);
alreadyRegistered = true;
}
use of org.osgi.service.http.HttpContext in project felix by apache.
the class HttpJettyTest method testCorrectPathInfoInHttpContextOk.
@Test
public void testCorrectPathInfoInHttpContextOk() throws Exception {
CountDownLatch initLatch = new CountDownLatch(1);
CountDownLatch destroyLatch = new CountDownLatch(1);
HttpContext context = new HttpContext() {
@Override
public String getMimeType(String name) {
return null;
}
@Override
public URL getResource(String name) {
return null;
}
@Override
public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
assertEquals("", request.getContextPath());
assertEquals("/foo", request.getServletPath());
assertEquals("/bar", request.getPathInfo());
assertEquals("/foo/bar", request.getRequestURI());
assertEquals("qux=quu", request.getQueryString());
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
};
TestServlet servlet = new TestServlet(initLatch, destroyLatch);
register("/foo", servlet, context);
URL testURL = createURL("/foo/bar?qux=quu");
assertTrue(initLatch.await(5, TimeUnit.SECONDS));
assertResponseCode(SC_OK, testURL);
unregister("/foo");
assertTrue(destroyLatch.await(5, TimeUnit.SECONDS));
assertResponseCode(SC_NOT_FOUND, testURL);
}
use of org.osgi.service.http.HttpContext in project fabric8 by jboss-fuse.
the class MavenProxyRegistrationHandler method init.
@Activate
void init(Map<String, ?> configuration) throws Exception {
configurer.get().configure(configuration, this);
if (uploadRepository == null) {
uploadRepository = runtimeProperties.get().getProperty("runtime.data") + "/maven/upload";
}
int timeout = -1;
if (configAdmin.getOptional() != null) {
ConfigurationAdmin ca = configAdmin.get();
Configuration c = ca.getConfiguration("io.fabric8.agent", null);
if (c != null && c.getProperties() != null) {
String t = (String) c.getProperties().get("org.ops4j.pax.url.mvn.socket.readTimeout");
if (t == null) {
t = (String) c.getProperties().get("org.ops4j.pax.url.mvn.timeout");
}
if (t != null) {
try {
timeout = Integer.parseInt(t);
} catch (NumberFormatException ignored) {
}
}
}
}
this.mavenDownloadProxyServlet = new MavenDownloadProxyServlet(mavenResolver.get(), runtimeProperties.get(), projectDeployer.get(), threadMaximumPoolSize, timeout);
this.mavenDownloadProxyServlet.start();
this.mavenUploadProxyServlet = new MavenUploadProxyServlet(mavenResolver.get(), runtimeProperties.get(), projectDeployer.get(), new File(uploadRepository), timeout);
this.mavenUploadProxyServlet.start();
try {
HttpContext base = httpService.get().createDefaultHttpContext();
HttpContext secure = new MavenSecureHttpContext(base, realm, role);
httpService.get().registerServlet("/maven/download", mavenDownloadProxyServlet, createParams("maven-download"), base);
httpService.get().registerServlet("/maven/upload", mavenUploadProxyServlet, createParams("maven-upload"), secure);
} catch (Throwable t) {
LOGGER.warn("Failed to register fabric maven proxy servlets, due to:" + t.getMessage());
}
activateComponent();
}
use of org.osgi.service.http.HttpContext in project smarthome by eclipse.
the class HttpContextFactoryServiceImplTest method httpContextShouldCallgetResourceOnBundle.
@Test
public void httpContextShouldCallgetResourceOnBundle() {
HttpContext context = httpContextFactoryService.createDefaultHttpContext(bundle);
context.getResource(RESOURCE);
verify(bundle).getResource(RESOURCE);
}
use of org.osgi.service.http.HttpContext in project smarthome by eclipse.
the class HttpContextFactoryServiceImplTest method httpContextShouldCallgetResourceOnBundleWithoutLeadingSlash.
@Test
public void httpContextShouldCallgetResourceOnBundleWithoutLeadingSlash() {
HttpContext context = httpContextFactoryService.createDefaultHttpContext(bundle);
context.getResource("/" + RESOURCE);
verify(bundle).getResource(RESOURCE);
}
Aggregations