@Override
 protected void onSetUp() throws Exception {
   System.out.println("onSetUp");
   super.onSetUp();
   //
   System.setProperty("red5.deployment.type", "junit");
   if (pss == null) {
     pss = (PlaylistSubscriberStream) applicationContext.getBean("playlistSubscriberStream");
     //
     pss.setBandwidthController(
         (IBWControlService) applicationContext.getBean(IBWControlService.KEY));
     //
     Context ctx = new Context();
     ctx.setApplicationContext(applicationContext);
     Scope scope = new DummyScope();
     scope.setName("");
     scope.setContext(ctx);
     pss.setScope(scope);
     //
     ISchedulingService schedulingService =
         (ISchedulingService) applicationContext.getBean(ISchedulingService.BEAN_NAME);
     IConsumerService consumerService =
         (IConsumerService) applicationContext.getBean(IConsumerService.KEY);
     IProviderService providerService =
         (IProviderService) applicationContext.getBean(IProviderService.BEAN_NAME);
     // create and get the engine
     PlayEngine engine = pss.createEngine(schedulingService, consumerService, providerService);
     // mock the message output
     engine.setMessageOut(new DummyMessageOut());
   }
 }
Пример #2
0
  /*
   * Registers a subcontext with red5
   */
  public void registerSubContext(String webAppKey) {
    // get the sub contexts - servlet context
    ServletContext ctx = servletContext.getContext(webAppKey);
    if (ctx == null) {
      ctx = servletContext;
    }
    ContextLoader loader = new ContextLoader();
    ConfigurableWebApplicationContext appCtx =
        (ConfigurableWebApplicationContext) loader.initWebApplicationContext(ctx);
    appCtx.setParent(applicationContext);
    appCtx.refresh();

    ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx);

    ConfigurableBeanFactory appFactory = appCtx.getBeanFactory();

    logger.debug("About to grab Webcontext bean for " + webAppKey);
    Context webContext = (Context) appCtx.getBean("web.context");
    webContext.setCoreBeanFactory(parentFactory);
    webContext.setClientRegistry(clientRegistry);
    webContext.setServiceInvoker(globalInvoker);
    webContext.setScopeResolver(globalResolver);
    webContext.setMappingStrategy(globalStrategy);

    WebScope scope = (WebScope) appFactory.getBean("web.scope");
    scope.setServer(server);
    scope.setParent(global);
    scope.register();
    scope.start();

    // register the context so we dont try to reinitialize it
    registeredContexts.add(ctx);
  }
Пример #3
0
  @Override
  public void doStart() throws Exception {
    super.doStart();

    // create a handler
    handler = new AdminHandler();

    // create app context
    adminContext =
        new FileSystemXmlApplicationContext(
            new String[] {"classpath:/admin-security.xml"}, true, context);

    // set the context
    handler.setContext(adminContext);

    // get a ref to the "default" global scope
    GlobalScope global = (GlobalScope) server.getGlobal("default");

    // create a scope resolver
    ScopeResolver scopeResolver = new ScopeResolver();
    scopeResolver.setGlobalScope(global);

    AuthClientRegistry registry = (AuthClientRegistry) adminContext.getBean("authClientRegistry");

    // create a context - this takes the place of the previous web context
    Context ctx = new Context(adminContext, "admin");
    ctx.setClientRegistry(registry);
    ctx.setMappingStrategy(new MappingStrategy());
    ctx.setPersistanceStore(global.getStore());
    ctx.setScopeResolver(scopeResolver);
    ctx.setServiceInvoker(new ServiceInvoker());

    // create a scope for the admin
    //		Scope scope = new Scope.Builder((IScope) global, "scope", "admin", false).build();
    //
    //		scope.setContext(ctx);
    //		scope.setHandler(handler);
    //
    //		//set the scope on the handler
    //		handler.setScope(scope);

    server.addMapping(hostName, "admin", "default");

    //		if (global.addChildScope(scope)) {
    //			log.info("Admin scope was added to global (default) scope");
    //
    //		} else {
    //			log.warn("Admin scope was not added to global (default) scope");
    //		}
  }
  /** {@inheritDoc} */
  public void configureWebApp() throws Exception {
    log.debug("Configuring Jetty webapp");

    // Get context
    WebAppContext context = getWebAppContext();

    // If app is already started...
    if (context.isStarted()) {
      log.debug("Cannot configure webapp after it is started");
      return;
    }

    // Get WEB_INF directory
    Resource webInf = context.getWebInf();
    if (webInf != null && webInf.isDirectory()) {
      // Get properties file with virtualHosts and context path
      Resource config = webInf.addPath("red5-web.properties");
      if (config.exists()) {
        log.debug("Configuring red5-web.properties");
        // Load configuration properties
        Properties props = new Properties();
        props.load(config.getInputStream());

        // Get context path and virtual hosts
        String contextPath = props.getProperty("webapp.contextPath");
        String virtualHosts = props.getProperty("webapp.virtualHosts");

        // Get hostnames
        String[] hostnames = virtualHosts.split(",");
        for (int i = 0; i < hostnames.length; i++) {
          hostnames[i] = hostnames[i].trim();
          if (hostnames[i].equals("*")) {
            // A virtual host "null" must be used so requests for
            // any host will be served.
            hostnames = null;
            break;
          }
        }

        // Set virtual hosts and context path to context
        context.setVirtualHosts(hostnames);
        context.setContextPath(contextPath);
        LoaderBase.setRed5ApplicationContext(contextPath, new JettyApplicationContext(context));
      }
    } else if (webInf == null) {
      // No WEB-INF directory found, register as default application
      log.info(
          "No WEB-INF directory found for "
              + context.getContextPath()
              + ", creating default application.");
      BeanFactoryLocator bfl = ContextSingletonBeanFactoryLocator.getInstance("red5.xml");
      BeanFactoryReference bfr = bfl.useBeanFactory("red5.common");

      // Create WebScope dynamically
      WebScope scope = new WebScope();
      IServer server = (IServer) bfr.getFactory().getBean(IServer.ID);
      scope.setServer(server);
      scope.setGlobalScope(server.getGlobal("default"));

      // Get default Red5 context from context loader that is JettyLoader in this case
      ApplicationContext appCtx = JettyLoader.getApplicationContext();
      ContextLoader loader = (ContextLoader) appCtx.getBean("context.loader");
      appCtx = loader.getContext("default.context");

      // Create context for the WebScope and initialize
      Context scopeContext = new Context();
      scopeContext.setContextPath("/");
      scopeContext.setClientRegistry((IClientRegistry) appCtx.getBean("global.clientRegistry"));
      scopeContext.setMappingStrategy((IMappingStrategy) appCtx.getBean("global.mappingStrategy"));
      scopeContext.setServiceInvoker((IServiceInvoker) appCtx.getBean("global.serviceInvoker"));
      scopeContext.setScopeResolver((IScopeResolver) appCtx.getBean("red5.scopeResolver"));

      // The context needs an ApplicationContext so resources can be
      // resolved
      GenericWebApplicationContext webCtx = new GenericWebApplicationContext();
      webCtx.setDisplayName("Automatic generated WebAppContext");
      webCtx.setParent(appCtx);
      webCtx.setServletContext(ContextHandler.getCurrentContext());
      scopeContext.setApplicationContext(webCtx);

      // Store context in scope
      scope.setContext(scopeContext);

      // Use default ApplicationAdapter as handler
      scope.setHandler(new ApplicationAdapter());

      // Make available as "/<directoryName>" and allow access from all
      // hosts
      scope.setContextPath(context.getContextPath());
      scope.setVirtualHosts("*");

      LoaderBase.setRed5ApplicationContext(
          context.getContextPath(), new JettyApplicationContext(context));

      // Register WebScope in server
      scope.register();
    }
  }