org.osgi.service.http.NamespaceException Java Examples
The following examples show how to use
org.osgi.service.http.NamespaceException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServiceImpl.java From fuchsia with Apache License 2.0 | 6 votes |
public void registerServlet(String context, Servlet servlet, Dictionary dictionary, HttpContext httpContext) throws ServletException, NamespaceException { ContextHandlerCollection contexts = new ContextHandlerCollection(); server.setHandler(contexts); ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS); ServletHolder servletHolder = new ServletHolder(servlet); root.addServlet(servletHolder, context); if (!server.getServer().getState().equals(server.STARTED)) { try { server.start(); } catch (Exception e) { e.printStackTrace(); } } }
Example #2
Source File: DispatcherServletInitializer.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
public void start () throws ServletException, NamespaceException { final BundleContext bundleContext = FrameworkUtil.getBundle ( DispatcherServletInitializer.class ).getBundleContext (); this.context = Dispatcher.createContext ( bundleContext ); this.errorHandler = new ErrorHandlerTracker (); Dictionary<String, String> initparams = new Hashtable<> (); final MultipartConfigElement multipart = Servlets.createMultiPartConfiguration ( PROP_PREFIX_MP ); final DispatcherServlet servlet = new DispatcherServlet (); servlet.setErrorHandler ( this.errorHandler ); this.webContainer.registerServlet ( servlet, "dispatcher", new String[] { "/" }, initparams, 1, false, multipart, this.context ); this.proxyFilter = new FilterTracker ( bundleContext ); this.webContainer.registerFilter ( this.proxyFilter, new String[] { "/*" }, null, null, this.context ); initparams = new Hashtable<> (); initparams.put ( "filter-mapping-dispatcher", "request" ); this.webContainer.registerFilter ( new BundleFilter (), new String[] { "/bundle/*" }, null, initparams, this.context ); this.jspTracker = new BundleTracker<> ( bundleContext, Bundle.INSTALLED | Bundle.ACTIVE, new JspBundleCustomizer ( this.webContainer, this.context ) ); this.jspTracker.open (); }
Example #3
Source File: JspBundleCustomizer.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
@Override public JspBundle addingBundle ( final Bundle bundle, final BundleEvent event ) { final Enumeration<String> result = bundle.getEntryPaths ( "/WEB-INF" ); if ( result != null && result.hasMoreElements () ) { try { return new JspBundle ( bundle, this.service, this.context ); } catch ( ServletException | NamespaceException e ) { logger.warn ( "Failed to register JSP bundle: " + bundle.getSymbolicName (), e ); return null; } } return null; }
Example #4
Source File: ProxyServletService.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Activate protected void activate(Map<String, Object> config) { try { Servlet servlet = getImpl(); logger.debug("Starting up '{}' servlet at /{}", servlet.getServletInfo(), PROXY_ALIAS); Hashtable<String, String> props = propsFromConfig(config); httpService.registerServlet("/" + PROXY_ALIAS, servlet, props, createHttpContext()); } catch (NamespaceException | ServletException e) { logger.error("Error during servlet startup: {}", e.getMessage()); } }
Example #5
Source File: PaperUIApp.java From smarthome with Eclipse Public License 2.0 | 5 votes |
protected void activate(BundleContext bundleContext) { try { Bundle paperuiBundle = bundleContext.getBundle(); httpService.registerResources(WEBAPP_ALIAS, "web", httpContextFactoryService.createDefaultHttpContext(paperuiBundle)); logger.info("Started Paper UI at " + WEBAPP_ALIAS); } catch (NamespaceException e) { logger.error("Error during servlet startup", e); } }
Example #6
Source File: WebAppServlet.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Activate protected void activate(Map<String, Object> configProps, BundleContext bundleContext) { HttpContext httpContext = createHttpContext(bundleContext.getBundle()); super.activate(WEBAPP_ALIAS + "/" + SERVLET_NAME, httpContext); try { httpService.registerResources(WEBAPP_ALIAS, "web", httpContext); } catch (NamespaceException e) { logger.error("Could not register static resources under {}", WEBAPP_ALIAS, e); } config.applyConfig(configProps); }
Example #7
Source File: WebAppServlet.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Activate protected void activate(Map<String, Object> configProps, BundleContext bundleContext) { config.applyConfig(configProps); HttpContext httpContext = createHttpContext(bundleContext.getBundle()); super.activate(WEBAPP_ALIAS + "/" + SERVLET_NAME, httpContext); try { httpService.registerResources(WEBAPP_ALIAS, "web", httpContext); } catch (NamespaceException e) { logger.error("Could not register static resources under {}", WEBAPP_ALIAS, e); } }
Example #8
Source File: ProxyServletService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Activate protected void activate(Map<String, Object> config) { try { Servlet servlet = getImpl(); logger.debug("Starting up '{}' servlet at /{}", servlet.getServletInfo(), PROXY_ALIAS); Hashtable<String, String> props = propsFromConfig(config); httpService.registerServlet("/" + PROXY_ALIAS, servlet, props, createHttpContext()); } catch (NamespaceException | ServletException e) { logger.error("Error during servlet startup: {}", e.getMessage()); } }
Example #9
Source File: Activator.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public Object addingService(ServiceReference reference) { @SuppressWarnings("unchecked") HttpService httpService = (HttpService) context.getService(reference); if (httpService != null) { try { httpService.registerResources(ALIAS, "/res", this); } catch (NamespaceException e) { logger.warn("Failed registering resource {}", ALIAS, e); } } return httpService; }
Example #10
Source File: JspBundle.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
public JspBundle ( final Bundle bundle, final HttpService service, final HttpContext context ) throws ServletException, NamespaceException { this.service = service; this.alias = String.format ( "/bundle/%s/WEB-INF", bundle.getBundleId () ); this.servlet = new JspServlet ( bundle, "/WEB-INF", this.alias ); logger.info ( "Registering JSP servlet - resources: /WEB-INF, alias: {}, bundle: {}", this.alias, bundle.getSymbolicName () ); final Dictionary<String, String> initparams = new Hashtable<> ( 2 ); initparams.put ( "compilerSourceVM", "1.8" ); initparams.put ( "compilerTargetVM", "1.8" ); this.service.registerServlet ( this.alias, this.servlet, initparams, context ); }
Example #11
Source File: JspServletInitializer.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
public void start () throws ServletException, NamespaceException { this.webctx = Dispatcher.createContext ( this.bundle.getBundleContext () ); this.servlet = new BundleServletWrapper ( createServlet (), this.bundle ); this.httpService.registerServlet ( this.alias, this.servlet, null, this.webctx ); this.jspServlet = new JspServlet ( this.bundle, "/WEB-INF/views", String.format ( "/bundle/%d/WEB-INF/views", this.bundle.getBundleId () ) ); this.httpService.registerServlet ( this.jspServlet, new String[] { "*.jsp" }, null, this.webctx ); }
Example #12
Source File: JaxRSServerContainer.java From JaxRSProviders with Apache License 2.0 | 5 votes |
@Override protected Map<String, Object> exportRemoteService(RSARemoteServiceRegistration reg) { // Create Servlet Servlet servlet = createServlet(reg); if (servlet == null) throw new NullPointerException( "Servlet is null. It cannot be null to export Jax RS servlet. See subclass implementation of JaxRSServerContainer.createServlet()"); // Create servletProps @SuppressWarnings("rawtypes") Dictionary servletProperties = createServletProperties(reg); // Create HttpContext HttpContext servletContext = createServletContext(reg); // Get servlet alias String servletAlias = getServletAlias(reg); // Get HttpService instance HttpService httpService = getHttpService(); if (httpService == null) throw new NullPointerException("HttpService cannot cannot be null"); synchronized (this.registrations) { try { httpService.registerServlet(servletAlias, servlet, servletProperties, servletContext); } catch (ServletException | NamespaceException e) { throw new RuntimeException("Cannot register servlet with alias=" + servletAlias, e); } this.registrations.put(servletAlias, reg); } return createExtraExportProperties(servletAlias, reg); }
Example #13
Source File: HABotDashboardTile.java From org.openhab.ui.habot with Eclipse Public License 1.0 | 5 votes |
@Activate protected void activate(Map<String, Object> configProps, BundleContext context) { try { Object useGzipCompression = configProps.get("useGzipCompression"); HttpContext httpContext = new HABotHttpContext(httpService.createDefaultHttpContext(), RESOURCES_BASE, (useGzipCompression != null && Boolean.parseBoolean(useGzipCompression.toString()))); httpService.registerResources(HABOT_ALIAS, RESOURCES_BASE, httpContext); logger.info("Started HABot at " + HABOT_ALIAS); } catch (NamespaceException e) { logger.error("Error during HABot startup: {}", e.getMessage()); } }
Example #14
Source File: HttpServiceImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void registerResources(String alias, String realPath, HttpContext httpContext) throws NamespaceException { if (closed) { throw new IllegalStateException("Service has been unget"); } if (realPath.length() > 0 && realPath.charAt(realPath.length() - 1) == '/') { throw new IllegalArgumentException( "The name parameter must not end with slash: " + realPath); } if (httpContext == null) { if (defaultBundleContext == null) { defaultBundleContext = createDefaultHttpContext(); } httpContext = defaultBundleContext; } // HACK CSM now caching "last updated" time register(alias, new ResourceRegistration(alias, realPath, httpContext, contextManager, System .currentTimeMillis())); }
Example #15
Source File: HttpServiceImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void register(String alias, Registration registration) throws NamespaceException { final int length = alias.length(); if (length == 0 || alias.charAt(0) != '/') { throw new IllegalArgumentException( "The alias parameter must begin with slash: " + alias); } if (length > 1 && alias.charAt(length - 1) == '/') { throw new IllegalArgumentException( "The alias parameter must not end with slash: " + alias); } if (registrations.get(alias) != null) { throw new NamespaceException("The alias is already in use: " + alias); } bundleRegistrations.addElement(alias); registrations.put(alias, registration); registration.setOwner(bundle); if (log.doDebug()) { log.debug("Alias \"" + alias + "\" was registered by bundle " + bundle.getBundleId()); } }
Example #16
Source File: HttpServiceImpl.java From fuchsia with Apache License 2.0 | 4 votes |
public void registerResources(String s, String s2, HttpContext httpContext) throws NamespaceException { throw new UnsupportedOperationException("Resource registering is not allowed in the mock implementation of httpservice"); }
Example #17
Source File: JAXWSExporterWithHttpServiceTest.java From fuchsia with Apache License 2.0 | 4 votes |
@Test public void worksInCaseHttpServiceWasInjected() throws BinderException, ServletException, NamespaceException { Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put(ID, "TestJAXWSDeclaration"); metadata.put("fuchsia.export.cxf.class.name", ServiceForExportation.class.getName()); metadata.put("fuchsia.export.cxf.url.context", "/" + ServiceForExportation.class.getSimpleName()); ExportDeclaration declaration = spy(ExportDeclarationBuilder.fromMetadata(metadata).build()); declaration.bind(serviceReferenceFromExporter); exporter.registration(serviceReferenceFromExporter); exporter.addDeclaration(declaration); verify(httpServiceMock, times(1)).registerServlet(eq(org.ow2.chameleon.fuchsia.exporter.jaxws.internal.Constants.CXF_SERVLET), any(CXFNonSpringServlet.class), any(Dictionary.class), any(org.osgi.service.http.HttpContext.class)); }
Example #18
Source File: JSONRPCImporterTest.java From fuchsia with Apache License 2.0 | 4 votes |
@Test public void remoteInvocationCustomProxy() throws ServletException, NamespaceException, BinderException { ImportDeclaration declaration = getValidDeclarations().get(0); JsonRpcServer jsonRpcServer = new JsonRpcServer(serviceToBeExported, ServiceForExportation.class); Servlet gs = new RPCServlet(jsonRpcServer); Dictionary<String, Object> emptyDictionary = new Hashtable<String, Object>(); http.registerServlet("/ping", gs, emptyDictionary, null); fuchsiaDeclarationBinder.useDeclaration(declaration); verifyRemoteInvocation(serviceToBeExported, proxyRegistered); }
Example #19
Source File: JSONRPCImporterTest.java From fuchsia with Apache License 2.0 | 4 votes |
@Test public void useDeclaration() throws ServletException, NamespaceException, BinderException { ImportDeclaration declaration = spy(getValidDeclarations().get(0)); JsonRpcServer jsonRpcServer = new JsonRpcServer(serviceToBeExported, ServiceForExportation.class); Servlet gs = new RPCServlet(jsonRpcServer); Dictionary<String, Object> dic = new Hashtable<String, Object>(); http.registerServlet("/ping", gs, dic, null); fuchsiaDeclarationBinder.useDeclaration(declaration); verify(declaration, times(1)).handle(fuchsiaDeclarationBinderServiceReference); Map<String, ComponentInstance> registrations = field("registrations").ofType(Map.class).in(fuchsiaDeclarationBinder).get(); Map<String, JsonRpcHttpClient> clients = field("clients").ofType(Map.class).in(fuchsiaDeclarationBinder).get(); Assert.assertEquals(1, registrations.size()); Assert.assertEquals(1, clients.size()); }
Example #20
Source File: Core.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * Private method used by Core.start() method to start the HttpService. */ private void startHttpService() { // The service cannot be started without a valid bundle context since we // are no longer using Declarative Services. if (bundleContext != null) { // Grab the service reference and the service httpServiceRef = bundleContext.getServiceReference(HttpService.class); // If it is good to go, start up the webserver if (httpServiceRef != null) { // Local Declaration Dictionary<String, String> servletParams = new Hashtable<>(); // Get the service httpService = bundleContext.getService(httpServiceRef); // Set the parameters servletParams.put("javax.ws.rs.Application", Core.class.getName()); // Register the service try { // Get the bundle Bundle bundle = null; bundle = bundleContext.getBundle(); // Make sure we got a valid bundle if (bundle == null) { logger.info("ICE Core Bundle was null! No web service started."); return; } // Find the root location and the jaas_config file URL resourceURL = bundle.getEntry(""); URL configFileURL = bundle.getEntry("jaas_config.txt"); // Resolve the URLs to be absolute resourceURL = FileLocator.resolve(resourceURL); configFileURL = FileLocator.resolve(configFileURL); HttpContext httpContext = new BasicAuthSecuredContext(resourceURL, configFileURL, "ICE Core Server Configuration"); httpService.registerServlet("/ice", new ServletContainer(this), servletParams, httpContext); } catch (ServletException | NamespaceException | IOException e) { logger.error(getClass().getName() + " Exception!", e); } logger.info("ICE Core Server loaded and web service started!"); } else { logger.info("ICE Core Server loaded, but without webservice."); } } else { logger.info("HTTP Service Unavailable."); } return; }
Example #21
Source File: ServletRegistrationComponentTest.java From roboconf-platform with Apache License 2.0 | 4 votes |
@Override public void registerResources( String alias, String name, HttpContext context ) throws NamespaceException { // nothing }
Example #22
Source File: ServletRegistrationComponentTest.java From roboconf-platform with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings( "rawtypes" ) public void registerServlet( String alias, Servlet servlet, Dictionary initparams, HttpContext context ) throws ServletException, NamespaceException { this.pathToServlet.put( alias, servlet ); }
Example #23
Source File: ServletRegistrationComponentTest.java From roboconf-platform with Apache License 2.0 | 4 votes |
@Override public void registerResources( String alias, String name, HttpContext context ) throws NamespaceException { // nothing }
Example #24
Source File: ServletRegistrationComponentTest.java From roboconf-platform with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings( "rawtypes" ) public void registerServlet( String alias, Servlet servlet, Dictionary initparams, HttpContext context ) throws ServletException, NamespaceException { this.pathToServlet.put( alias, servlet ); }
Example #25
Source File: HttpServiceImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void registerServlet(String alias, Servlet servlet, @SuppressWarnings("rawtypes") Dictionary parameters, HttpContext httpContext) throws NamespaceException, ServletException { if (closed) { throw new IllegalStateException("Service has been unget"); } if (servlet == null) { throw new IllegalArgumentException("Servlet parameter is null"); } if (httpContext == null) { if (defaultBundleContext == null) { defaultBundleContext = createDefaultHttpContext(); } httpContext = defaultBundleContext; } Registration registration = null; try { @SuppressWarnings("unchecked") final Dictionary<String, String> paramsss = parameters; registration = new ServletRegistration(alias, servlet, paramsss, httpContext, contextManager, registrations); register(alias, registration); } catch (final NamespaceException ne) { if (registration != null) { registration.destroy(); } throw ne; } catch (final RuntimeException re) { if (registration != null) { registration.destroy(); } throw re; } }
Example #26
Source File: MagicHttpResource.java From smarthome with Eclipse Public License 2.0 | 4 votes |
@Activate protected void activate(Map<String, Object> configProps, BundleContext bundleContext) throws NamespaceException { httpService.registerResources(WEBAPP_ALIAS, WEBAPP_NAME, new MagicHttpContext(bundleContext.getBundle())); }
Example #27
Source File: JSONRPCImporterTest.java From fuchsia with Apache License 2.0 | 3 votes |
@Test public void useDeclarationDefaultProxy() throws ServletException, NamespaceException, BinderException { Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put(Constants.ID, "my-id"); metadata.put(Constants.URL, "http://localhost:" + HTTP_PORT + "/ping"); //metadata.put(Constants.SERVICE_CLASS,ServiceForExportation.class.getName()); final ImportDeclaration declaration = spy(ImportDeclarationBuilder.fromMetadata(metadata).build()); declaration.bind(fuchsiaDeclarationBinderServiceReference); JsonRpcServer jsonRpcServer = new JsonRpcServer(serviceToBeExported, ServiceForExportation.class); Servlet gs = new RPCServlet(jsonRpcServer); Dictionary<String, Object> dic = new Hashtable<String, Object>(); http.registerServlet("/ping", gs, dic, null); fuchsiaDeclarationBinder.useDeclaration(declaration); verify(declaration, times(1)).handle(fuchsiaDeclarationBinderServiceReference); Map<String, ComponentInstance> registrations = field("componentInstances").ofType(Map.class).in(fuchsiaDeclarationBinder).get(); Assert.assertEquals(1, registrations.size()); }
Example #28
Source File: JSONRPCImporterTest.java From fuchsia with Apache License 2.0 | 3 votes |
@Test public void denyDeclarationCustomProxy() throws ServletException, NamespaceException, BinderException { ImportDeclaration declaration = spy(getValidDeclarations().get(0)); JsonRpcServer jsonRpcServer = new JsonRpcServer(serviceToBeExported, ServiceForExportation.class); Servlet gs = new RPCServlet(jsonRpcServer); Dictionary<String, Object> dic = new Hashtable<String, Object>(); http.registerServlet("/ping", gs, dic, null); fuchsiaDeclarationBinder.useDeclaration(declaration); verify(declaration, times(1)).handle(fuchsiaDeclarationBinderServiceReference); Map<String, ComponentInstance> registrations = field("registrations").ofType(Map.class).in(fuchsiaDeclarationBinder).get(); Map<String, JsonRpcHttpClient> clients = field("clients").ofType(Map.class).in(fuchsiaDeclarationBinder).get(); Assert.assertEquals(1, registrations.size()); Assert.assertEquals(1, clients.size()); fuchsiaDeclarationBinder.denyDeclaration(declaration); verify(declaration, times(1)).unhandle(fuchsiaDeclarationBinderServiceReference); Assert.assertEquals(0, registrations.size()); Assert.assertEquals(0, clients.size()); }
Example #29
Source File: JSONRPCImporterTest.java From fuchsia with Apache License 2.0 | 3 votes |
@Test public void denyDeclarationDefaultProxy() throws ServletException, NamespaceException, BinderException { Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put(Constants.ID, "my-id"); metadata.put(Constants.URL, "http://localhost:" + HTTP_PORT + "/ping"); //metadata.put(Constants.SERVICE_CLASS,ServiceForExportation.class.getName()); ImportDeclaration declaration = spy(ImportDeclarationBuilder.fromMetadata(metadata).build()); declaration.bind(fuchsiaDeclarationBinderServiceReference); JsonRpcServer jsonRpcServer = new JsonRpcServer(serviceToBeExported, ServiceForExportation.class); Servlet gs = new RPCServlet(jsonRpcServer); Dictionary<String, Object> dic = new Hashtable<String, Object>(); http.registerServlet("/ping", gs, dic, null); fuchsiaDeclarationBinder.useDeclaration(declaration); verify(declaration, times(1)).handle(fuchsiaDeclarationBinderServiceReference); Map<String, ComponentInstance> componentInstances = field("componentInstances").ofType(Map.class).in(fuchsiaDeclarationBinder).get(); Assert.assertEquals(1, componentInstances.size()); fuchsiaDeclarationBinder.denyDeclaration(declaration); verify(declaration, times(1)).unhandle(fuchsiaDeclarationBinderServiceReference); Assert.assertEquals(0, componentInstances.size()); }
Example #30
Source File: JSONRPCImporterTest.java From fuchsia with Apache License 2.0 | 3 votes |
@Test public void gracefulStop() throws BinderException, ServletException, NamespaceException, MissingHandlerException, UnacceptableConfiguration, ConfigurationException { ImportDeclaration declaration = getValidDeclarations().get(0); Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put(Constants.ID, "my-id"); metadata.put(Constants.URL, "http://localhost:" + HTTP_PORT + "/ping"); ImportDeclaration declarationForDefaultProxy = spy(ImportDeclarationBuilder.fromMetadata(metadata).build()); declarationForDefaultProxy.bind(fuchsiaDeclarationBinderServiceReference); JsonRpcServer jsonRpcServer = new JsonRpcServer(serviceToBeExported, ServiceForExportation.class); Servlet gs = new RPCServlet(jsonRpcServer); Dictionary<String, Object> emptyDictionary = new Hashtable<String, Object>(); http.registerServlet("/ping", gs, emptyDictionary, null); fuchsiaDeclarationBinder.useDeclaration(declaration); fuchsiaDeclarationBinder.useDeclaration(declarationForDefaultProxy); verifyRemoteInvocation(serviceToBeExported, proxyRegistered); Map<String, ComponentInstance> registrations = field("registrations").ofType(Map.class).in(fuchsiaDeclarationBinder).get(); Map<String, ComponentInstance> componentInstances = field("componentInstances").ofType(Map.class).in(fuchsiaDeclarationBinder).get(); Assert.assertEquals(1, registrations.size()); Assert.assertEquals(1, componentInstances.size()); method("stop").in(fuchsiaDeclarationBinder).invoke(); Assert.assertEquals(0, registrations.size()); Assert.assertEquals(0, componentInstances.size()); }