Exemplo n.º 1
0
 @Override
 public void unregisterContribution(
     Object contribution, String extensionPoint, ComponentInstance contributor) {
   if (contribution instanceof FlavorDescriptor) {
     FlavorDescriptor flavor = (FlavorDescriptor) contribution;
     flavorReg.removeContribution(flavor);
   } else if (contribution instanceof Resource) {
     Resource resource = (Resource) contribution;
     unregisterResource(resource);
   } else if (contribution instanceof SimpleStyle) {
     SimpleStyle style = (SimpleStyle) contribution;
     unregisterResource(getResourceFromStyle(style));
   } else if (contribution instanceof PageDescriptor) {
     PageDescriptor page = (PageDescriptor) contribution;
     if (page.hasResources() && !Framework.getRuntime().isShuttingDown()) {
       WebResourceManager wrm = Framework.getService(WebResourceManager.class);
       wrm.unregisterResourceBundle(page.getComputedResourceBundle());
     }
     pageReg.removeContribution(page);
   } else if (contribution instanceof NegotiationDescriptor) {
     NegotiationDescriptor neg = (NegotiationDescriptor) contribution;
     negReg.removeContribution(neg);
   } else {
     log.error(
         String.format(
             "Unknown contribution to the theme " + "styling service, extension point '%s': '%s",
             extensionPoint, contribution));
   }
 }
Exemplo n.º 2
0
 /**
  * Makes sure there is no previous runtime hanging around.
  *
  * <p>This happens for instance if a previous test had errors in its <code>setUp()</code>, because
  * <code>tearDown()</code> has not been called.
  */
 protected void wipeRuntime() throws Exception {
   // Make sure there is no active runtime (this might happen if an
   // exception is raised during a previous setUp -> tearDown is not called
   // afterwards).
   runtime = null;
   if (Framework.getRuntime() != null) {
     Framework.shutdown();
   }
 }
Exemplo n.º 3
0
 protected void deployContrib(URL url) {
   assertEquals(runtime, Framework.getRuntime());
   log.info("Deploying contribution from " + url.toString());
   try {
     runtime.getContext().deploy(url);
   } catch (Exception e) {
     fail("Failed to deploy contrib " + url.toString());
   }
 }
Exemplo n.º 4
0
 @Override
 public int getApplicationStartedOrder() {
   ComponentInstance repositoryComponent =
       (ComponentInstance)
           Framework.getRuntime()
               .getComponentInstance("org.nuxeo.ecm.core.repository.RepositoryServiceComponent");
   if (repositoryComponent == null) {
     return super.getApplicationStartedOrder();
   }
   return ((DefaultComponent) repositoryComponent.getInstance()).getApplicationStartedOrder() - 5;
 }
Exemplo n.º 5
0
  protected void send(DocumentModel doc)
      throws TemplateException, RenderingException, OperationException, MessagingException,
          IOException {
    // TODO should sent one by one to each recipient? and have the template
    // rendered for each recipient? Use: "mailto" var name?
    try {
      Map<String, Object> map = Scripting.initBindings(ctx);
      // do not use document wrapper which is working only in mvel.
      map.put("Document", doc);
      map.put("docUrl", MailTemplateHelper.getDocumentUrl(doc, viewId));
      map.put("subject", subject);
      map.put("to", to);
      map.put("toResolved", MailBox.fetchPersonsFromList(to, isStrict));
      map.put("from", from);
      map.put("fromResolved", MailBox.fetchPersonsFromString(from, isStrict));
      map.put("from", cc);
      map.put("fromResolved", MailBox.fetchPersonsFromList(cc, isStrict));
      map.put("from", bcc);
      map.put("fromResolved", MailBox.fetchPersonsFromList(bcc, isStrict));
      map.put("from", replyto);
      map.put("fromResolved", MailBox.fetchPersonsFromList(replyto, isStrict));
      map.put("viewId", viewId);
      map.put("baseUrl", NotificationServiceHelper.getNotificationService().getServerUrlPrefix());
      map.put("Runtime", Framework.getRuntime());
      Mailer.Message msg = createMessage(doc, getContent(), map);
      msg.setSubject(subject, "UTF-8");

      addMailBoxInfo(msg);

      msg.send();
    } catch (ClientException
        | TemplateException
        | RenderingException
        | OperationException
        | MessagingException
        | IOException e) {
      if (rollbackOnError) {
        throw e;
      } else {
        log.warn(
            String.format(
                "An error occured while trying to execute the %s operation, see complete stack trace below. Continuing chain since 'rollbackOnError' was set to false.",
                ID),
            e);
      }
    }
  }
Exemplo n.º 6
0
  @Override
  public String load(String bundleName, String scriptName) throws IOException {
    Bundle b = Framework.getRuntime().getBundle(bundleName);
    URL loc = b.getEntry(scriptName + ".lua");
    InputStream is = loc.openStream();
    final StrBuilder builder = new StrBuilder();
    for (String line : IOUtils.readLines(is)) {
      builder.appendln(line);
    }
    return executor.execute(
        new RedisCallable<String>() {

          @Override
          public String call(Jedis jedis) throws Exception {
            return jedis.scriptLoad(builder.toString());
          }
        });
  }
Exemplo n.º 7
0
  @Override
  public void initialize(BinaryManagerDescriptor binaryManagerDescriptor) throws IOException {
    String path = binaryManagerDescriptor.storePath;
    if (path == null || path.trim().length() == 0) {
      path = DEFAULT_PATH;
    }
    path = Framework.expandVars(path);
    path = path.trim();
    File base;
    if (path.startsWith("/")
        || path.startsWith("\\")
        || path.contains("://")
        || path.contains(":\\")) {
      // absolute
      base = new File(path);
    } else {
      // relative
      File home = Environment.getDefault().getData();
      base = new File(home, path);

      // Backward compliance with versions before 5.4 (NXP-5370)
      File oldBase = new File(Framework.getRuntime().getHome().getPath(), path);
      if (oldBase.exists()) {
        log.warn("Old binaries path used (NXP-5370). Please move " + oldBase + " to " + base);
        base = oldBase;
      }
    }

    log.info(
        "Repository '"
            + binaryManagerDescriptor.repositoryName
            + "' using "
            + (this.getClass().equals(LocalBinaryManager.class)
                ? ""
                : (this.getClass().getSimpleName() + " and "))
            + "binary store: "
            + base);
    storageDir = new File(base, DATA);
    tmpDir = new File(base, TMP);
    storageDir.mkdirs();
    tmpDir.mkdirs();
    descriptor = getDescriptor(new File(base, CONFIG_FILE));
    createGarbageCollector();
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  protected Object findServiceByShortCut(String name) {

    if (!name2ServiceClassCache.containsKey(name)) {
      Class klass = null;
      name2ServiceClassLock.lock();
      try {
        for (String serviceClassName : Framework.getRuntime().getComponentManager().getServices()) {
          int p = serviceClassName.lastIndexOf('.');
          String fullClassName = serviceClassName;
          if (p > -1) {
            serviceClassName = serviceClassName.substring(p + 1);
          }
          if (name.equalsIgnoreCase(serviceClassName)) {
            try {
              klass = Thread.currentThread().getContextClassLoader().loadClass(fullClassName);
              if (log.isDebugEnabled()) {
                log.debug("Lookup for " + name + " resolved to service " + fullClassName);
              }
              break;
            } catch (ClassNotFoundException e) {
              log.error("Unable to load class for service " + fullClassName, e);
            }
          }
        }
        // NB : puts null if not found to avoid multiple lookups
        name2ServiceClassCache.put(name, klass);
      } finally {
        name2ServiceClassLock.unlock();
      }
    }
    Class serviceClass = name2ServiceClassCache.get(name);
    Object result = null;
    if (serviceClass != null) {
      result = Framework.getLocalService(serviceClass);
      if (result != null && Contexts.isEventContextActive()) {
        // cache in Event scope
        Contexts.getEventContext().set(name, result);
      }
    }
    return result;
  }
  /**
   * Gets a ResultsProviderFarm that can instantiate the given named PagedDocumentsProvider.
   *
   * @param name
   * @return
   * @throws ClientException If no results provider has been registered under the required name
   */
  private ResultsProviderFarm getProviderFarmFor(String name) throws ClientException {

    ResultsProviderService service =
        (ResultsProviderService) Framework.getRuntime().getComponent(ResultsProviderService.NAME);
    String farmName = service.getFarmNameFor(name);
    if (farmName == null) {
      throw new ClientException("Unknown results provider: " + name);
    }

    Object ob = Contexts.lookupInStatefulContexts(farmName);
    if (ob == null) {
      // seam component has not yet been created
      SeamComponentCallHelper.getSeamComponentByName(farmName);
      ob = Contexts.lookupInStatefulContexts(farmName);
      if (ob == null) {
        throw new ClientException(farmName + " provider farm is not a registered seam component");
      }
    }
    return (ResultsProviderFarm) ob;
  }
  @Test
  public void testContributions() {
    RuntimeService runtime = Framework.getRuntime();
    ComponentManager mgr = runtime.getComponentManager();
    assertTrue(mgr.size() > 0);

    ComponentInstance co = runtime.getComponentInstance("service:my.comp1");
    assertNotNull(co);
    assertEquals(co.getName(), new ComponentName("service:my.comp1"));

    co = runtime.getComponentInstance("service:my.comp2");
    assertNotNull(co);
    assertEquals(co.getName(), new ComponentName("service:my.comp2"));

    mgr.unregister(new ComponentName("service:my.comp2"));
    co = runtime.getComponentInstance("service:my.comp2");
    assertNull(co);
    co = runtime.getComponentInstance("service:my.comp1");
    assertNotNull(co);
  }
Exemplo n.º 11
0
  protected void initOsgiRuntime() throws Exception {
    try {
      if (!restart) {
        Environment.setDefault(null);
        if (System.getProperties().remove("nuxeo.home") != null) {
          log.warn("Removed System property nuxeo.home.");
        }
        workingDir =
            File.createTempFile(
                "nxruntime-" + Thread.currentThread().getName() + "-", null, new File("target"));
        workingDir.delete();
      }
    } catch (IOException e) {
      log.error("Could not init working directory", e);
      throw e;
    }
    osgi = new OSGiAdapter(workingDir);
    BundleFile bf = new SystemBundleFile(workingDir);
    bundleLoader = new StandaloneBundleLoader(osgi, NXRuntimeTestCase.class.getClassLoader());
    SystemBundle systemBundle =
        new SystemBundle(osgi, bf, bundleLoader.getSharedClassLoader().getLoader());
    osgi.setSystemBundle(systemBundle);
    Thread.currentThread().setContextClassLoader(bundleLoader.getSharedClassLoader().getLoader());

    for (WorkingDirectoryConfigurator cfg : wdConfigs) {
      cfg.configure(this, workingDir);
    }

    bundleLoader.setScanForNestedJARs(false); // for now
    bundleLoader.setExtractNestedJARs(false);

    BundleFile bundleFile = lookupBundle("org.nuxeo.runtime");
    runtimeBundle =
        new RootRuntimeBundle(osgi, bundleFile, bundleLoader.getClass().getClassLoader(), true);
    runtimeBundle.start();

    runtime = handleNewRuntime((OSGiRuntimeService) Framework.getRuntime());

    assertNotNull(runtime);
  }
Exemplo n.º 12
0
  @Override
  public void activate(ComponentContext context) throws Exception {
    super.activate(context);
    ctx = context;
    String webDir = Framework.getProperty("org.nuxeo.ecm.web.root");
    File root = null;
    if (webDir != null) {
      root = new File(webDir);
    } else {
      root = new File(Framework.getRuntime().getHome(), "web");
    }
    root = root.getCanonicalFile();
    log.info("Using web root: " + root);
    if (!new File(root, "default").exists()) {
      try {
        root.mkdirs();
        // runtime predeployment is not supporting conditional unziping so we do the predeployment
        // here:
        deployWebDir(context.getRuntimeContext().getBundle(), root);
      } catch (Exception e) { // delete incomplete files
        FileUtils.deleteTree(root);
        throw e;
      }
    }
    // register contrib managers
    registerContributionManager(APPLICATION_XP, new ContributionManager(this));
    registerContributionManager(WEB_OBJ_XP, new ContributionManager(this));

    // load message bundle
    notifier = new FileChangeNotifier();
    notifier.start();
    notifier.addListener(this);

    engine = new DefaultWebEngine(root, notifier);
    deployer = new ConfigurationDeployer(notifier);
    deployer.addConfigurationChangedListener(this);
  }
  @Override
  @SuppressWarnings({"rawtypes", "unchecked"})
  public Object lookup(String name, Class type, boolean create) {

    if (Framework.getRuntime() == null) {
      return null;
    }

    if (type != null && type.isAssignableFrom(CoreSession.class)) {
      // XXX return a CoreSession on the default repository ?
      return null;
    }

    Object result = null;

    // service loopkup
    if (type != null) {
      result = Framework.getLocalService(type);
    }

    // fallback on component lookup
    if (result == null && name != null) {
      if (!name.startsWith("org.jboss")) {
        // remove lookup by component name
        // result = Framework.getRuntime().getComponent(name);
        // lookup service by short name
        if (result == null) {
          result = findServiceByShortCut(name);
        }
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("Nuxeo Lookup => return " + result);
    }
    return result;
  }
Exemplo n.º 14
0
 @Before
 public void init() {
   rc = new DefaultRuntimeContext(Framework.getRuntime());
 }
Exemplo n.º 15
0
 @Override
 public void reloadProperties() throws IOException {
   log.info("Reload runtime properties");
   Framework.getRuntime().reloadProperties();
 }
Exemplo n.º 16
0
 protected void initIfNeeded() {
   if (engine != null || Framework.getRuntime() == null) {
     return;
   }
   engine = Framework.getLocalService(WebEngine.class);
 }
 public static WSSPlugableBackendManager instance() {
   return (WSSPlugableBackendManager)
       Framework.getRuntime().getComponent(WSSPlugableBackendManager.NAME);
 }
Exemplo n.º 18
0
 @Override
 public void registerContribution(
     Object contribution, String extensionPoint, ComponentInstance contributor) {
   if (contribution instanceof FlavorDescriptor) {
     FlavorDescriptor flavor = (FlavorDescriptor) contribution;
     log.info(String.format("Register flavor '%s'", flavor.getName()));
     registerFlavor(flavor, contributor.getContext());
     log.info(String.format("Done registering flavor '%s'", flavor.getName()));
   } else if (contribution instanceof SimpleStyle) {
     SimpleStyle style = (SimpleStyle) contribution;
     log.info(String.format("Register style '%s'", style.getName()));
     String message =
         String.format(
             "Style '%s' on component %s should now be contributed to extension "
                 + "point '%s': a compatibility registration was performed but it may not be "
                 + "accurate. Note that the 'flavor' processor should be used with this resource.",
             style.getName(), contributor.getName(), WR_EX);
     DeprecationLogger.log(message, "7.4");
     Framework.getRuntime().getWarnings().add(message);
     ResourceDescriptor resource = getResourceFromStyle(style);
     registerResource(resource, contributor.getContext());
     log.info(String.format("Done registering style '%s'", style.getName()));
   } else if (contribution instanceof PageDescriptor) {
     PageDescriptor page = (PageDescriptor) contribution;
     log.info(String.format("Register page '%s'", page.getName()));
     if (page.hasResources()) {
       // automatically register a bundle for page resources
       WebResourceManager wrm = Framework.getService(WebResourceManager.class);
       wrm.registerResourceBundle(page.getComputedResourceBundle());
     }
     pageReg.addContribution(page);
     log.info(String.format("Done registering page '%s'", page.getName()));
   } else if (contribution instanceof ResourceDescriptor) {
     ResourceDescriptor resource = (ResourceDescriptor) contribution;
     log.info(String.format("Register resource '%s'", resource.getName()));
     String message =
         String.format(
             "Resource '%s' on component %s should now be contributed to extension "
                 + "point '%s': a compatibility registration was performed but it may not be accurate.",
             resource.getName(), contributor.getName(), WR_EX);
     DeprecationLogger.log(message, "7.4");
     Framework.getRuntime().getWarnings().add(message);
     // ensure path is absolute, consider that resource is in the war, and if not, user will have
     // to declare it
     // directly to the WRM endpoint
     String path = resource.getPath();
     if (path != null && !path.startsWith("/")) {
       resource.setUri("/" + path);
     }
     registerResource(resource, contributor.getContext());
     log.info(String.format("Done registering resource '%s'", resource.getName()));
   } else if (contribution instanceof NegotiationDescriptor) {
     NegotiationDescriptor neg = (NegotiationDescriptor) contribution;
     log.info(String.format("Register negotiation for '%s'", neg.getTarget()));
     negReg.addContribution(neg);
     log.info(String.format("Done registering negotiation for '%s'", neg.getTarget()));
   } else {
     log.error(
         String.format(
             "Unknown contribution to the theme " + "styling service, extension point '%s': '%s",
             extensionPoint, contribution));
   }
 }
Exemplo n.º 19
0
 protected String getRuntimeStatus() {
   StringBuilder msg = new StringBuilder();
   RuntimeService runtime = Framework.getRuntime();
   runtime.getStatusMessage(msg);
   return msg.toString();
 }