/** * Adding our own methods. */ private void destroyEngine(HelloDispatcher engine) { engine.stop(); }
public void doRun() throws Exception { int count = 0; while(true) { System.out.println("Run "+count+": "+messageService.getRandomMessage()); Thread.sleep(2000); count++; } }
/** * Called when the OSGi framework starts our bundle */ public void start(BundleContext bc) throws Exception { bundleContext = bc; //preparing special HTTP Context with HTTP Connector Hashtable<String, String> props = new Hashtable<String, String>(); props.put( ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "httpConnector" ); HashMap<String,String> contextMappingParams = new HashMap<String,String>(); contextMappingParams.put(ExtenderConstants.PROPERTY_HTTP_VIRTUAL_HOSTS, "localhost"); contextMappingParams.put(ExtenderConstants.PROPERTY_HTTP_CONNECTORS, "alternateConnector"); contextMappingReg = bundleContext.registerService( HttpContextMapping.class, new WhiteboardHttpContextMapping("httpConnector", "whiteboard", contextMappingParams), props ); //Registering Servlet props.put(ExtenderConstants.PROPERTY_ALIAS, "/connector"); servletReg = bundleContext.registerService(Servlet.class, new HelloServlet(), props); }
servletReg = bundleContext.registerService(Servlet.class, new HelloServlet(), props); logoServletReg = bundleContext.registerService(Servlet.class, new HelloImage(), props); props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "forbidden"); httpContextReg = bundleContext.registerService(HttpContext.class, new WhiteboardContext(), props); props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "forbidden"); forbiddenServletReg = bundleContext.registerService(Servlet.class, new HelloServlet(), props);
destroyEngine(engine); engine = new HelloDispatcher(); engine.setCamelContext(camelContext); engine.setGreeting(dict.get(HelloConstants.HELLO_GREETING).toString()); engine.setName(dict.get(HelloConstants.HELLO_NAME).toString()); log.debug("Engine was null, check configuration."); engine.start();
public HttpService addingService(ServiceReference<HttpService> reference) { final HttpService httpService = (HttpService) bundleContext .getService(reference); if (httpService != null) { // create a default context to share between registrations final HttpContext httpContext = httpService.createDefaultHttpContext(); final Dictionary<String, Object> initParams = new Hashtable<String, Object>(); try { httpService.registerServlet("/hello", new HelloServlet(), initParams, httpContext); httpService.registerServlet("/hello/logo", new HelloImage(), initParams, httpContext); httpService.registerResources("/images", "/images", httpContext); } catch (ServletException e) { e.printStackTrace(); } catch (NamespaceException e) { e.printStackTrace(); } } return httpService; }
public void start(BundleContext context) throws Exception { ServiceReference<WebContainer> serviceReference = context .getServiceReference(WebContainer.class); while (serviceReference == null) { serviceReference = context.getServiceReference(WebContainer.class); } WebContainer service = (WebContainer) context .getService(serviceReference); HttpContext httpContext = service.getDefaultSharedHttpContext(); Dictionary<String, String> props; // register a custom http context for sharing props = new Hashtable<String, String>(); props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "shared"); httpContextReg = context.registerService(HttpContext.class, httpContext, props); // and an servlet that cannot be accessed due to the above context props = new Hashtable<String, String>(); props.put( ExtenderConstants.PROPERTY_ALIAS, "/extfilter" ); props.put("servlet-name", "FilteredServlet"); props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "shared"); registerService = context.registerService( Servlet.class, new HelloServlet(), props ); }
@Override public void deleted(String pid) { if (dispatchEngines.containsKey(pid)) { HelloDispatcher engine = dispatchEngines.get(pid); if (engine != null) { destroyEngine(engine); } dispatchEngines.remove(pid); } log.info("deleted " + pid); }
public void start() { try { rb = buildHelloRouter(); log.info("Route " + rb + " starting..."); cc.start(); cc.addRoutes(rb); } catch (Exception ex) { log.error("Could not process Hello " + ex); } }
@Override public void configure() throws Exception { from("timer://helloTimer?fixedRate=true&period=10000"). routeId("Hello " + name). log(greeting + " " + name); } };
public void init() { log.info("Starting " + this.getName()); Dictionary servProps = new Properties(); servProps.put(Constants.SERVICE_PID, configurationPid); registration = bundleContext.registerService(ManagedServiceFactory.class.getName(), this, servProps); tracker = new ServiceTracker(bundleContext, ConfigurationAdmin.class.getName(), null); tracker.open(); log.info("Started " + this.getName()); }
public void start(BundleContext context) { System.out.println("Starting the bundle"); camelContext = new DefaultCamelContext(); try { camelContext.addRoutes(new MyRouteBuilder()); camelContext.start(); } catch (Exception ex) { System.out.println("Exception occured! " + ex.getMessage()); } }