/** * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference) */ @Override public Object addingService(ServiceReference sr) { Bundle contributor = sr.getBundle(); Server server = (Server) contributor.getBundleContext().getService(sr); String name = (String) sr.getProperty(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME); if (name == null) { throw new IllegalArgumentException("The property " + OSGiServerConstants.MANAGED_JETTY_SERVER_NAME + " is mandatory"); } if (LOG.isDebugEnabled()) LOG.debug("Adding Server {}", name); ServerInstanceWrapper wrapper = new ServerInstanceWrapper(name); Dictionary<String,Object> props = new Hashtable<>(); for (String key : sr.getPropertyKeys()) { props.put(key, sr.getProperty(key)); } try { wrapper.start(server, props); LOG.info("Started Server {}", name); return wrapper; } catch (Exception e) { LOG.warn(e); return sr.getBundle().getBundleContext().getService(sr); } }
/** * */ @Override public void start(BundleContext context) throws Exception { //set up some classes that will look for bundles with tlds that must be converted //to urls and treated as if they are on the Jetty container's classpath so that //jasper can deal with them ServerInstanceWrapper.addContainerTldBundleDiscoverer(new ContainerTldBundleDiscoverer()); }
/** * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object) */ @Override public void removedService(ServiceReference reference, Object service) { if (service instanceof ServerInstanceWrapper) { try { ServerInstanceWrapper wrapper = (ServerInstanceWrapper)service; wrapper.stop(); LOG.info("Stopped Server {}",wrapper.getManagedServerName()); } catch (Exception e) { LOG.warn(e); } } } }
try List<URL> sharedURLs = getManagedJettySharedLibFolderUrls(props); List<URL> jettyConfigurations = jettyConfigurationUrls != null ? Util.fileNamesAsURLs(jettyConfigurationUrls, Util.DEFAULT_DELIMS) : null; _server = configure(server, jettyConfigurations, props); init();
protected void doProcessBinding (Node node, App app) throws Exception { ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(_server.getParentClassLoaderForWebapps()); try { super.processBinding(node,app); } finally { Thread.currentThread().setContextClassLoader(old); } } }
OSGiClassLoader classLoader = new OSGiClassLoader(getServerInstanceWrapper().getParentClassLoaderForWebapps(), _bundle); String jettyHome = (String)getServerInstanceWrapper().getServer().getAttribute(OSGiServerConstants.JETTY_HOME); if (jettyHome == null) jettyHome = System.getProperty(OSGiServerConstants.JETTY_HOME); HashMap properties = new HashMap(); properties.put("Server", getServerInstanceWrapper().getServer());
@Override protected void doStart() throws Exception { //Track bundles that are ContextHandlers that should be deployed _tracker = new ContextBundleTracker(FrameworkUtil.getBundle(this.getClass()).getBundleContext(), getServerInstanceWrapper().getManagedServerName()); _tracker.open(); //register as an osgi service for deploying contexts defined in a bundle, advertising the name of the jetty Server instance we are related to Dictionary<String,String> properties = new Hashtable<String,String>(); properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); _serviceRegForBundles = FrameworkUtil.getBundle(this.getClass()).getBundleContext().registerService(BundleProvider.class.getName(), this, properties); super.doStart(); }
String jettyHome = (String)getServerInstanceWrapper().getServer().getAttribute(OSGiServerConstants.JETTY_HOME); if (jettyHome == null) jettyHome = System.getProperty(OSGiServerConstants.JETTY_HOME);
Util.setProperty(properties, OSGiServerConstants.JETTY_HOME, home); Util.setProperty(properties, OSGiServerConstants.JETTY_BASE, base); Server server = ServerInstanceWrapper.configure(null, configURLs, properties);
Thread.currentThread().setContextClassLoader(getServerInstanceWrapper().getParentClassLoaderForWebapps()); try
/** * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() */ @Override protected void doStart() throws Exception { _webappTracker = new WebAppTracker(FrameworkUtil.getBundle(this.getClass()).getBundleContext(), getServerInstanceWrapper().getManagedServerName()); _webappTracker.open(); //register as an osgi service for deploying bundles, advertising the name of the jetty Server instance we are related to Dictionary<String,String> properties = new Hashtable<>(); properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); _serviceRegForBundles = FrameworkUtil.getBundle(this.getClass()).getBundleContext().registerService(BundleProvider.class.getName(), this, properties); super.doStart(); }
public String[] getConfigurationClasses() { if (_configurationClasses != null) return _configurationClasses; Configuration.ClassList defaults = Configuration.ClassList.serverDefault(_serverWrapper.getServer()); //add before JettyWebXmlConfiguration if (annotationsAvailable() && !defaults.contains("org.eclipse.jetty.osgi.annotations.AnnotationConfiguration")) defaults.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.osgi.annotations.AnnotationConfiguration"); //add in EnvConfiguration and PlusConfiguration just after FragmentConfiguration if (jndiAvailable()) { if (!defaults.contains("org.eclipse.jetty.plus.webapp.EnvConfiguration")) defaults.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration"); if (!defaults.contains("org.eclipse.jetty.plus.webapp.PlusConfiguration")) defaults.addAfter("org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration"); } String[] asArray = new String[defaults.size()]; return defaults.toArray(asArray); }
Thread.currentThread().setContextClassLoader(getServerInstanceWrapper().getParentClassLoaderForWebapps()); try
@Override protected void doStart() throws Exception { BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); //Start a tracker to find webapps that are osgi services that are targeted to my server name _tracker = new ContextTracker (bundleContext, Util.createFilter(bundleContext, ContextHandler.class.getName(), getServerInstanceWrapper().getManagedServerName())); _tracker.open(); //register as an osgi service for deploying contexts defined in a bundle, advertising the name of the jetty Server instance we are related to Dictionary<String,String> properties = new Hashtable<>(); properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); //register as an osgi service for deploying contexts, advertising the name of the jetty Server instance we are related to _serviceRegForServices = FrameworkUtil.getBundle(this.getClass()).getBundleContext().registerService(ServiceProvider.class.getName(), this, properties); super.doStart(); }
@Override public void processBinding(Node node, App app) throws Exception { EventSender.getInstance().send(EventSender.UNDEPLOYING_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(_server.getParentClassLoaderForWebapps()); try { super.processBinding(node,app); } finally { Thread.currentThread().setContextClassLoader(old); } EventSender.getInstance().send(EventSender.UNDEPLOYED_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); ((AbstractOSGiApp)app).deregisterAsOSGiService(); } }
/** * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() */ @Override protected void doStart() throws Exception { BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); //Start a tracker to find webapps that are osgi services that are targeted to my server name webappTracker = new WebAppTracker (bundleContext, Util.createFilter(bundleContext, WebAppContext.class.getName(), getServerInstanceWrapper().getManagedServerName())); webappTracker.open(); //register as an osgi service for deploying bundles, advertising the name of the jetty Server instance we are related to Dictionary<String,String> properties = new Hashtable<>(); properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, getServerInstanceWrapper().getManagedServerName()); //register as an osgi service for deploying contexts (discovered as osgi services), advertising the name of the jetty Server instance we are related to _serviceRegForServices = FrameworkUtil.getBundle(this.getClass()).getBundleContext().registerService(ServiceProvider.class.getName(), this, properties); super.doStart(); }
Thread.currentThread().setContextClassLoader(getServerInstanceWrapper().getParentClassLoaderForWebapps()); String contextPath = null; try
OSGiWebappClassLoader webAppLoader = new OSGiWebappClassLoader(_serverWrapper.getParentClassLoaderForWebapps(), _webApp, _bundle);