Package org.osgi.service.http

Examples of org.osgi.service.http.HttpService


            }
            return httpService;
        }

        public void removedService(ServiceReference reference, Object service) {
            final HttpService httpService = (HttpService) service;
            httpService.unregister("/jstl-examples"); //$NON-NLS-1$
            httpService.unregister("/jstl-examples/*.jsp"); //$NON-NLS-1$
            super.removedService(reference, service);
        }
View Full Code Here


        //processing servlet definitions
        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 (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);
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) {
            throw new CarbonException("Error occurred while registering servlet", e);
        }
View Full Code Here

    }

    public synchronized void unregisterAll()
    {
      AbstractMapping[] mappings = null;
      HttpService service;
      synchronized (this) {
      service = this.httpService;
      if (service != null) {
          Collection<AbstractMapping> values = this.mapping.values();
          mappings = values.toArray(new AbstractMapping[values.size()]);
View Full Code Here

    }

    private synchronized void registerAll()
    {
      AbstractMapping[] mappings = null;
      HttpService service;
      synchronized (this) {
      service = this.httpService;
      if (service != null) {
          Collection<AbstractMapping> values = this.mapping.values();
          mappings = values.toArray(new AbstractMapping[values.size()]);
View Full Code Here

        }
    }

    private void registerMapping(AbstractMapping mapping)
    {
        HttpService httpService = this.httpService;
        if (httpService != null)
        {
            mapping.register(httpService);
        }
    }
View Full Code Here

        }
    }

    private void unregisterMapping(AbstractMapping mapping)
    {
        HttpService httpService = this.httpService;
        if (httpService != null)
        {
            mapping.unregister(httpService);
        }
    }
View Full Code Here

    protected void registerServlet(BundleContext bundleContext) throws Exception {
        httpServiceRef = bundleContext.getServiceReference(HttpService.class.getName());
       
        if (httpServiceRef != null && !registerService) {
            LOG.info("Regist 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
                    (Servlet)new CamelHttpTransportServlet(), // register servlet
                    initParams, // init params
                    httpContext // http context
                );
                registerService = true;
View Full Code Here

        bundleContext.registerService(HttpService.class.getName(), httpService, null);

        try
        {
            ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
            HttpService service = (HttpService) bundleContext.getService(sr);

            service.registerResources("/a/b", "/car", service.createDefaultHttpContext());
            try
            {
                service.registerResources("/a/b", "/car", service.createDefaultHttpContext());
                fail("Should not be able to register with same alias");
            }
            catch (NamespaceException ignore)
            {
            }

            service.unregister("/a/b");
        }
        finally
        {
            httpService.stop();
        }
View Full Code Here

        bundleContext.registerService(HttpService.class.getName(), httpService, null);

        try
        {
            ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
            HttpService service = (HttpService) bundleContext.getService(sr);

            service.registerResources("/a/b", "/org/papoose/tck", new HttpContext()
            {
                public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
                {
                    return true;
                }

                public URL getResource(String name)
                {
                    return HttpServiceImplTest.class.getResource(name);
                }

                public String getMimeType(String name)
                {
                    return null;
                }
            });

            URL url = new URL("http://localhost:8080/a/b/http/HttpServiceImplTest.class");

            DataInputStream reader = new DataInputStream(url.openStream());

            assertEquals((byte) 0xca, reader.readByte());
            assertEquals((byte) 0xfe, reader.readByte());

            assertEquals((byte) 0xba, reader.readByte());
            assertEquals((byte) 0xbe, reader.readByte());

            service.unregister("/a/b");
        }
        finally
        {
            httpService.stop();
            server.stop();
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.