Package org.osgi.service.http

Examples of org.osgi.service.http.HttpService


                                                                       this );
  }

  @Override
  public HttpService addingService( ServiceReference<HttpService> reference ) {
    HttpService httpService = bundleContext.getService( reference );
    try {
      httpService.registerServlet( path,
                                   new EntryPointLookupServlet( context ),
                                   null,
                                   null );
    } catch( Exception shouldNotHappen ) {
      throw new IllegalStateException( shouldNotHappen );
View Full Code Here


    public void testServletThroughSystemContext() throws Exception {

        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());

        HttpService httpService = ServiceLocator.getRequiredService(HttpService.class);
        String reqspec = "/gravia/servlet?test=module";

        // Verify that the alias is not yet available
        assertNotAvailable(reqspec);

        // Register the test servlet and make a call
        String servletAlias = getRuntimeAwareAlias("/servlet");
        httpService.registerServlet(servletAlias, new HttpServiceServlet(module), null, null);
        Assert.assertEquals("http-service:1.0.0", performCall(reqspec));

        // Unregister the servlet alias
        httpService.unregister(servletAlias);
        assertNotAvailable(reqspec);

        // Verify that the alias is not available any more
        assertNotAvailable(reqspec);
    }
View Full Code Here

        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());

        ModuleContext context = module.getModuleContext();
        ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
        HttpService httpService = context.getService(sref);

        String reqspec = "/gravia/servlet?test=module";
        try {
            // Verify that the alias is not yet available
            assertNotAvailable(reqspec);

            // Register the test servlet and make a call
            String servletAlias = getRuntimeAwareAlias("/servlet");
            httpService.registerServlet(servletAlias, new HttpServiceServlet(module), null, null);
            Assert.assertEquals("http-service:1.0.0", performCall(reqspec));

            // Unregister the servlet alias
            httpService.unregister(servletAlias);
            assertNotAvailable(reqspec);

            // Verify that the alias is not available any more
            assertNotAvailable(reqspec);
        } finally {
View Full Code Here

            super(context, HttpService.class.getName(), null);
        }

        public Object addingService(ServiceReference serviceReference) {

            HttpService httpService = (HttpService) context.getService(serviceReference);
            try {
                OSGiAxisServlet axisServlet = new OSGiAxisServlet(context);
                ServiceReference configCtxRef =
                        context.getServiceReference(ConfigurationContext.class.getName());
                ConfigurationContext configCtx =
                        (ConfigurationContext) context.getService(configCtxRef);
                String propServiceContextRoot = context.getProperty(AXIS2_OSGi_ROOT_CONTEXT);
                String serviceContextRoot = "services";
                if (propServiceContextRoot != null && propServiceContextRoot.length() != 0) {
                    if (propServiceContextRoot.startsWith("/")) {
                        serviceContextRoot = propServiceContextRoot.substring(1);
                    } else {
                        serviceContextRoot = propServiceContextRoot;
                    }
                }
                configCtx.setServicePath(serviceContextRoot);
                String contextRoot = "/" + serviceContextRoot;
                log.info("Registering SOAP message listener servlet to context : " + contextRoot);
                httpService.registerServlet(contextRoot, axisServlet, null, null);
            } catch (ServletException e) {
                String msg = "Error while registering servlets";
                log.error(msg, e);
            } catch (NamespaceException e) {
                String msg = "Namespace missmatch when registering servlets";
View Full Code Here

    protected void registerServlet(BundleContext bundleContext) throws Exception {
        httpServiceRef = bundleContext.getServiceReference(HttpService.class.getName());
       
        if (httpServiceRef != null && !registerService) {
            LOG.info("Register the servlet service");
            final HttpService httpService = (HttpService)bundleContext.getService(httpServiceRef);
            if (httpService != null) {
                // create a default context to share between registrations
                final HttpContext httpContext = httpService.createDefaultHttpContext();
                // register the hello world servlet
                final Dictionary<String, String> initParams = new Hashtable<String, String>();
                initParams.put("matchOnUriPrefix", "false");
                initParams.put("servlet-name", "CamelServlet");
                httpService.registerServlet("/camel/services", // alias
                    new CamelHttpTransportServlet(), // register servlet
                    initParams, // init params
                    httpContext // http context
                );
                registerService = true;
View Full Code Here

        Hashtable<String, String[]> properties3 = new Hashtable<String, String[]>();
        properties3.put(URLConstants.URL_CONTENT_MIMETYPE, new String[]{"text/javascript"});
        context.registerService(ContentHandler.class.getName(), new TextJavascriptHandler(),
                                properties3);

        final HttpService httpService = getHttpService();

        Dictionary<String, String> initparams = new Hashtable<String, String>();
        initparams.put("servlet-name", "TilesServlet");
        initparams.put("definitions-config", "/WEB-INF/tiles/main_defs.xml");
        initparams.put("org.apache.tiles.context.TilesContextFactory",
                       "org.apache.tiles.context.enhanced.EnhancedContextFactory");
        initparams.put("org.apache.tiles.factory.TilesContainerFactory.MUTABLE", "true");
        initparams.put("org.apache.tiles.definition.DefinitionsFactory",
                       "org.wso2.carbon.tiles.CarbonUrlDefinitionsFactory");

        String webContext = "carbon"; // The subcontext for the Carbon Mgt Console

        String serverURL = CarbonUIUtil.getServerURL(serverConfig);
        String indexPageURL = CarbonUIUtil.getIndexPageURL(serverConfig);
        if (indexPageURL == null) {
            indexPageURL = "/carbon/admin/index.jsp";
        }
        RegistryService registryService = getRegistryService();
        Registry registry = registryService.getLocalRepository();

        UIBundleDeployer uiBundleDeployer = new UIBundleDeployer();
        UIResourceRegistry uiResourceRegistry = new UIResourceRegistry();
        uiResourceRegistry.initialize(bundleContext);
        uiResourceRegistry.setDefaultUIResourceProvider(
                uiBundleDeployer.getBundleBasedUIResourcePrvider());
//        BundleResourcePathRegistry resourcePathRegistry = uiBundleDeployer.getBundleResourcePathRegistry();

        HttpContext commonContext =
                new CarbonSecuredHttpContext(context.getBundle(), "/web", uiResourceRegistry, registry);

        //Registering filedownload servlet
        Servlet fileDownloadServlet = new ContextPathServletAdaptor(new FileDownloadServlet(
                context, getConfigurationContextService()), "/filedownload");
        httpService.registerServlet("/filedownload", fileDownloadServlet, null, commonContext);
        fileDownloadServlet.getServletConfig().getServletContext().setAttribute(
                CarbonConstants.SERVER_URL, serverURL);
        fileDownloadServlet.getServletConfig().getServletContext().setAttribute(
                CarbonConstants.INDEX_PAGE_URL, indexPageURL);

        //Registering fileupload servlet
        Servlet fileUploadServlet;
        if (isLocalTransportMode) {
            fileUploadServlet = new ContextPathServletAdaptor(new FileUploadServlet(
                    context, serverConfigContext, webContext), "/fileupload");
        } else {
            fileUploadServlet = new ContextPathServletAdaptor(new FileUploadServlet(
                    context, clientConfigContext, webContext), "/fileupload");
        }

        httpService.registerServlet("/fileupload", fileUploadServlet, null, commonContext);
        fileUploadServlet.getServletConfig().getServletContext().setAttribute(
                CarbonConstants.SERVER_URL, serverURL);
        fileUploadServlet.getServletConfig().getServletContext().setAttribute(
                CarbonConstants.INDEX_PAGE_URL, indexPageURL);

        uiBundleDeployer.deploy(bundleContext, commonContext);
        context.addBundleListener(uiBundleDeployer);

        httpService.registerServlet("/", new org.apache.tiles.web.startup.TilesServlet(),
                                    initparams,
                                    commonContext);
        httpService.registerResources("/" + webContext, "/", commonContext);

        adaptedJspServlet = new ContextPathServletAdaptor(
                new TilesJspServlet(context.getBundle(), uiResourceRegistry), "/" + webContext);
        httpService.registerServlet("/" + webContext + "/*.jsp", adaptedJspServlet, null,
                                    commonContext);

        ServletContext jspServletContext =
                adaptedJspServlet.getServletConfig().getServletContext();
        jspServletContext.setAttribute("registry", registryService);
View Full Code Here

    private void processServletDefinitions(Component component, String action) throws
            CarbonException{
        if (component != null
                && component.getServlets() != null
                && component.getServlets().length > 0) {
            HttpService httpService;
            try {
                httpService = CarbonUIServiceComponent.getHttpService();
            } catch (Exception e) {
                throw new CarbonException("An instance of HttpService is not available");
            }
            org.wso2.carbon.ui.deployment.beans.Servlet[] servletDefinitions = component.getServlets();
            for (int a = 0; a < servletDefinitions.length; a++) {
                org.wso2.carbon.ui.deployment.beans.Servlet servlet = servletDefinitions[a];
                if (CarbonConstants.ADD_UI_COMPONENT.equals(action)) {
                    if (log.isTraceEnabled()) {
                        log.trace("Registering sevlet : " + servlet);
                    }
                    try {
                        Class clazz = Class.forName(servlet.getServletClass());
                        //TODO : allow servlet parameters to be passed
                        Dictionary params = new Hashtable();
                        httpService.registerServlet(servlet.getUrlPatten(),
                                (Servlet) clazz.newInstance(), params,
                                httpContext);
                    } catch (ClassNotFoundException e) {
                        log.error("Servlet class : " + servlet.getServletClass() + " not found.", e);
                    } catch (ServletException e) {
                        log.error("Problem registering Servlet class : " +
                                servlet.getServletClass() + ".", e);
                    } catch (NamespaceException e) {
                        log.error("Problem registering Servlet class : " +
                                servlet.getServletClass() + ".", e);
                    } catch (InstantiationException e) {
                        log.error("Problem registering Servlet class : " +
                                servlet.getServletClass() + ".", e);
                    } catch (IllegalAccessException e) {
                        log.error("Problem registering Servlet class : " +
                                servlet.getServletClass() + ".", e);
                    }
                } else if (CarbonConstants.REMOVE_UI_COMPONENT.equals(action)) {
                    if (log.isTraceEnabled()) {
                        log.trace("Unregistering sevlet : " + servlet);
                    }
                    httpService.unregister(servlet.getUrlPatten());
                }
            }

        }
View Full Code Here

    }

    public void registerServlet(Servlet servlet, String urlPattern, Dictionary params,
                                Dictionary servletAttrs, int event, javax.servlet.Filter associatedFilter) throws CarbonException {

        HttpService httpService;
        try {
            httpService = CarbonUIServiceComponent.getHttpService();
        } catch (Exception e) {
            throw new CarbonException("An instance of HttpService is not available");
        }
        try {
            if (event == ServiceEvent.REGISTERED) {
                Servlet adaptedJspServlet = new ContextPathServletAdaptor(servlet, urlPattern);
                if (associatedFilter == null) {
                    httpService.registerServlet(urlPattern, adaptedJspServlet, params, httpContext);
                } else {
                    httpService.registerServlet(urlPattern,
                            new FilterServletAdaptor(associatedFilter, null, adaptedJspServlet), params, httpContext);
                }
                if (servletAttrs != null) {
                    for (Enumeration enm = servletAttrs.keys(); enm.hasMoreElements();) {
                        String key = (String) enm.nextElement();
                        adaptedJspServlet.getServletConfig().getServletContext().setAttribute(key, servletAttrs.get(key));
                    }
                }
            } else if (event == ServiceEvent.UNREGISTERING) {
                httpService.unregister(urlPattern);
            }

        } catch (Exception e) {
            log.error("Error occurred while registering servlet",e);
        }
View Full Code Here

    doReturn( jerseyContext ).when( connector ).createJerseyContext( any( HttpService.class ), anyString(), eq( false ) );
  }
 
  @Test
  public void testAddHttpService() {
    HttpService httpService = mock( HttpService.class );
    when( bundleContext.getService( httpServiceReference ) ).thenReturn( httpService );
   
    HttpService httpService2 = connector.addHttpService( httpServiceReference );
   
    assertSame( httpService, httpService2 );
  }
View Full Code Here

    verify( jerseyContext ).addResource( resource );
  }
 
  @Test
  public void testUsesResourceCache() {
    HttpService httpService = mockHttpService();
    Object resource = new Object();
    when( bundleContext.getService( resourceServiceReference ) ).thenReturn( resource );
    ArrayList<Object> resourceList = new ArrayList<Object>();
    resourceList.add( resource );
    when( jerseyContext.eliminate() ).thenReturn( resourceList );
View Full Code Here

TOP

Related Classes of org.osgi.service.http.HttpService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.