Search in sources :

Example 1 with HttpContext

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;
}
Also used : Hashtable(java.util.Hashtable) HttpContext(org.osgi.service.http.HttpContext)

Example 2 with HttpContext

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpContext(org.osgi.service.http.HttpContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) CountDownLatch(java.util.concurrent.CountDownLatch) ServletException(javax.servlet.ServletException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) URL(java.net.URL) Test(org.junit.Test)

Example 3 with HttpContext

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();
}
Also used : Configuration(org.osgi.service.cm.Configuration) HttpContext(org.osgi.service.http.HttpContext) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) File(java.io.File) Activate(org.apache.felix.scr.annotations.Activate)

Example 4 with HttpContext

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);
}
Also used : HttpContext(org.osgi.service.http.HttpContext) Test(org.junit.Test)

Example 5 with HttpContext

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);
}
Also used : HttpContext(org.osgi.service.http.HttpContext) Test(org.junit.Test)

Aggregations

HttpContext (org.osgi.service.http.HttpContext)18 Test (org.junit.Test)9 File (java.io.File)4 URL (java.net.URL)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ServletException (javax.servlet.ServletException)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 MalformedURLException (java.net.MalformedURLException)3 Hashtable (java.util.Hashtable)3 IOException (java.io.IOException)2 ServletContext (javax.servlet.ServletContext)2 Activate (org.apache.felix.scr.annotations.Activate)2 NamespaceException (org.osgi.service.http.NamespaceException)2 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)2 ZkPath (io.fabric8.zookeeper.ZkPath)1 ConnectException (java.net.ConnectException)1 Path (java.nio.file.Path)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Dictionary (java.util.Dictionary)1