Search in sources :

Example 31 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class XMLConfigAdmin method removeRHExtension.

/**
 * removes an installed extension from the system
 *
 * @param config
 * @param rhe extension to remove
 * @param replacementRH the extension that will replace this extension, so do not remove parts defined in this extension.
 * @throws PageException
 */
private void removeRHExtension(Config config, RHExtension rhe, RHExtension replacementRH, boolean deleteExtension) throws PageException {
    ConfigImpl ci = ((ConfigImpl) config);
    Log logger = ci.getLog("deploy");
    try {
        // remove the bundles
        BundleDefinition[] candidatesToRemove = OSGiUtil.toBundleDefinitions(rhe.getBundles());
        if (replacementRH != null) {
            // spare bundles used in the new extension as well
            Map<String, BundleDefinition> notRemove = toMap(OSGiUtil.toBundleDefinitions(replacementRH.getBundles()));
            List<BundleDefinition> tmp = new ArrayList<OSGiUtil.BundleDefinition>();
            String key;
            for (int i = 0; i < candidatesToRemove.length; i++) {
                key = candidatesToRemove[i].getName() + "|" + candidatesToRemove[i].getVersionAsString();
                if (notRemove.containsKey(key))
                    continue;
                tmp.add(candidatesToRemove[i]);
            }
            candidatesToRemove = tmp.toArray(new BundleDefinition[tmp.size()]);
        }
        XMLConfigAdmin.cleanBundles(rhe, ci, candidatesToRemove);
        // FLD
        // MUST check if others use one of this fld
        removeFLDs(rhe.getFlds());
        // TLD
        // MUST check if others use one of this tld
        removeTLDs(rhe.getTlds());
        // Tag
        removeTags(rhe.getTags());
        // Functions
        removeFunctions(rhe.getFunctions());
        // Event Gateway
        removeEventGateways(rhe.getEventGateways());
        // context
        // MUST check if others use one of this
        removeContext(config, false, rhe.getContexts());
        // web contextS
        // MUST check if others use one of this
        removeWebContexts(config, false, rhe.getWebContexts());
        // applications
        // MUST check if others use one of this
        removeApplications(config, rhe.getWebContexts());
        // plugins
        // MUST check if others use one of this
        removePlugins(config, rhe.getWebContexts());
        // remove cache handler
        if (!ArrayUtil.isEmpty(rhe.getCacheHandlers())) {
            Iterator<Map<String, String>> itl = rhe.getCacheHandlers().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String _id = map.get("id");
                if (!StringUtil.isEmpty(_id) && cd != null && cd.hasClass()) {
                    _removeCacheHandler(_id);
                // reload=true;
                }
                logger.info("extension", "remove cache handler [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove cache
        if (!ArrayUtil.isEmpty(rhe.getCaches())) {
            Iterator<Map<String, String>> itl = rhe.getCaches().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.isBundle()) {
                    _removeCache(cd);
                // reload=true;
                }
                logger.info("extension", "remove cache handler [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove Search
        if (!ArrayUtil.isEmpty(rhe.getSearchs())) {
            Iterator<Map<String, String>> itl = rhe.getSearchs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _removeSearchEngine();
                // reload=true;
                }
                logger.info("extension", "remove search engine [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove resource
        if (!ArrayUtil.isEmpty(rhe.getResources())) {
            Iterator<Map<String, String>> itl = rhe.getResources().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String scheme = map.get("scheme");
                if (cd != null && cd.hasClass()) {
                    _removeResourceProvider(scheme);
                }
                logger.info("extension", "remove resource [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove AMF
        if (!ArrayUtil.isEmpty(rhe.getAMFs())) {
            Iterator<Map<String, String>> itl = rhe.getAMFs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _removeAMFEngine();
                // reload=true;
                }
                logger.info("extension", "remove search engine [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove orm
        if (!ArrayUtil.isEmpty(rhe.getOrms())) {
            Iterator<Map<String, String>> itl = rhe.getOrms().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _removeORMEngine();
                // reload=true;
                }
                logger.info("extension", "remove orm engine [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove monitor
        if (!ArrayUtil.isEmpty(rhe.getMonitors())) {
            Iterator<Map<String, String>> itl = rhe.getMonitors().iterator();
            Map<String, String> map;
            String name;
            while (itl.hasNext()) {
                map = itl.next();
                // ClassDefinition cd = RHExtension.toClassDefinition(config,map);
                // if(cd.hasClass()) {
                _removeMonitor(map.get("type"), name = map.get("name"));
                // reload=true;
                // }
                logger.info("extension", "remove monitor [" + name + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove jdbc
        if (!ArrayUtil.isEmpty(rhe.getJdbcs())) {
            Iterator<Map<String, String>> itl = rhe.getJdbcs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.isBundle()) {
                    _removeJDBCDriver(cd);
                }
                logger.info("extension", "remove JDBC Driver [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove mapping
        if (!ArrayUtil.isEmpty(rhe.getMappings())) {
            Iterator<Map<String, String>> itl = rhe.getMappings().iterator();
            Map<String, String> map;
            String virtual;
            while (itl.hasNext()) {
                map = itl.next();
                virtual = map.get("virtual");
                _removeMapping(virtual);
                logger.info("extension", "remove Mapping [" + virtual + "]");
            }
        }
        // remove event-gateway-instance
        if (!ArrayUtil.isEmpty(rhe.getEventGatewayInstances())) {
            Iterator<Map<String, Object>> itl = rhe.getEventGatewayInstances().iterator();
            Map<String, Object> map;
            String id;
            while (itl.hasNext()) {
                map = itl.next();
                id = Caster.toString(map.get("id"), null);
                if (!StringUtil.isEmpty(id)) {
                    _removeGatewayEntry(id);
                    logger.info("extension", "remove event gateway entry [" + id + "]");
                }
            }
        }
        // Loop Files
        ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(rhe.getExtensionFile().getInputStream()));
        String type = ci instanceof ConfigWeb ? "web" : "server";
        try {
            ZipEntry entry;
            String path;
            String fileName;
            Resource tmp;
            while ((entry = zis.getNextEntry()) != null) {
                path = entry.getName();
                fileName = fileName(entry);
                // archives
                if (!entry.isDirectory() && (startsWith(path, type, "archives") || startsWith(path, type, "mappings"))) {
                    String sub = subFolder(entry);
                    logger.log(Log.LEVEL_INFO, "extension", "remove archive " + sub + " registered as a mapping");
                    tmp = SystemUtil.getTempFile(".lar", false);
                    IOUtil.copy(zis, tmp, false);
                    removeArchive(tmp);
                }
                zis.closeEntry();
            }
        } finally {
            IOUtil.closeEL(zis);
        }
        // now we can delete the extension
        if (deleteExtension)
            rhe.getExtensionFile().delete();
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        // failed to uninstall, so we install it again
        try {
            updateRHExtension(config, rhe.getExtensionFile(), true);
        // RHExtension.install(config, rhe.getExtensionFile());
        } catch (Throwable t2) {
            ExceptionUtil.rethrowIfNecessary(t2);
        }
        throw Caster.toPageException(t);
    }
}
Also used : Log(lucee.commons.io.log.Log) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) ClassDefinition(lucee.runtime.db.ClassDefinition) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) OSGiUtil(lucee.runtime.osgi.OSGiUtil) ZipInputStream(java.util.zip.ZipInputStream) CreateObject(lucee.runtime.functions.other.CreateObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 32 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class DeployHandler method deploy.

// private static final ResourceFilter ARCHIVE_EXT = new ExtensionResourceFilter(new String[]{".ra",".ras"});
/**
 * deploys all files found
 * @param config
 */
public static void deploy(Config config) {
    if (!contextIsValid(config))
        return;
    synchronized (config) {
        Resource dir = config.getDeployDirectory();
        if (!dir.exists())
            dir.mkdirs();
        Resource[] children = dir.listResources(ALL_EXT);
        Resource child;
        String ext;
        for (int i = 0; i < children.length; i++) {
            child = children[i];
            try {
                // Lucee archives
                ext = ResourceUtil.getExtension(child, null);
                if ("lar".equalsIgnoreCase(ext)) {
                    // deployArchive(config,child,true);
                    XMLConfigAdmin.updateArchive((ConfigImpl) config, child, true);
                } else // Lucee Extensions
                if ("lex".equalsIgnoreCase(ext))
                    XMLConfigAdmin._updateRHExtension((ConfigImpl) config, child, true);
                else // Lucee core
                if (config instanceof ConfigServer && "lco".equalsIgnoreCase(ext))
                    XMLConfigAdmin.updateCore((ConfigServerImpl) config, child, true);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                Log log = config.getLog("deploy");
                log.error("Extension", t);
            }
        }
    }
}
Also used : Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource)

Example 33 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class WSClient method getInstance.

public static WSClient getInstance(PageContext pc, String wsdlUrl, String username, String password, ProxyData proxyData) throws PageException {
    pc = ThreadLocalPageContext.get(pc);
    if (pc != null) {
        Log l = pc.getConfig().getLog("application");
        ApplicationContext ac = pc.getApplicationContext();
        if (ac != null) {
            if (ApplicationContext.WS_TYPE_JAX_WS == ac.getWSType()) {
                l.info("RPC", "using JAX WS Client");
                return new JaxWSClient(wsdlUrl, username, password, proxyData);
            }
            if (ApplicationContext.WS_TYPE_CXF == ac.getWSType()) {
                l.info("RPC", "using CXF Client");
                return new CXFClient(wsdlUrl, username, password, proxyData);
            }
        }
        l.info("RPC", "using Axis 1 RPC Client");
    }
    return new Axis1Client(wsdlUrl, username, password, proxyData);
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) Log(lucee.commons.io.log.Log)

Example 34 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class ApplicationContextSupport method initLog.

public static Map<Collection.Key, Pair<Log, Struct>> initLog(Struct sct) {
    Map<Collection.Key, Pair<Log, Struct>> rtn = new ConcurrentHashMap<Collection.Key, Pair<Log, Struct>>();
    if (sct == null)
        return rtn;
    Iterator<Entry<Key, Object>> it = sct.entryIterator();
    Entry<Key, Object> e;
    Struct v;
    int k;
    Collection.Key name;
    LoggerAndSourceData las;
    while (it.hasNext()) {
        e = it.next();
        name = e.getKey();
        v = Caster.toStruct(e.getValue(), null);
        if (v == null)
            continue;
        // raw way
        Struct sctApp = Caster.toStruct(v.get("appender", null), null);
        ClassDefinition cdApp = toClassDefinition(sctApp, null, true, false);
        Struct sctLay = Caster.toStruct(v.get("layout", null), null);
        ClassDefinition cdLay = toClassDefinition(sctLay, null, false, true);
        if (cdApp != null && cdApp.hasClass()) {
            // level
            String strLevel = Caster.toString(v.get("level", null), null);
            if (StringUtil.isEmpty(strLevel, true))
                Caster.toString(v.get("loglevel", null), null);
            Level level = Log4jUtil.toLevel(StringUtil.trim(strLevel, ""), Level.ERROR);
            Struct sctAppArgs = Caster.toStruct(sctApp.get("arguments", null), null);
            Struct sctLayArgs = Caster.toStruct(sctLay.get("arguments", null), null);
            boolean readOnly = Caster.toBooleanValue(v.get("readonly", null), false);
            // ignore when no appender/name is defined
            if (!StringUtil.isEmpty(name)) {
                Map<String, String> appArgs = toMap(sctAppArgs);
                if (cdLay != null && cdLay.hasClass()) {
                    Map<String, String> layArgs = toMap(sctLayArgs);
                    las = addLogger(name, level, cdApp, appArgs, cdLay, layArgs, readOnly);
                } else
                    las = addLogger(name, level, cdApp, appArgs, null, null, readOnly);
                rtn.put(name, new Pair<Log, Struct>(las.getLog(), v));
            }
        }
    }
    return rtn;
}
Also used : LoggerAndSourceData(lucee.commons.io.log.LoggerAndSourceData) Log(lucee.commons.io.log.Log) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) Entry(java.util.Map.Entry) Collection(lucee.runtime.type.Collection) Level(org.apache.log4j.Level) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Key(lucee.runtime.type.Collection.Key) Pair(lucee.commons.lang.Pair)

Example 35 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class InstrumentationFactory method getInstrumentation.

public static synchronized Instrumentation getInstrumentation(final Config config) {
    final Log log = config.getLog("application");
    final CFMLEngine engine = ConfigWebUtil.getEngine(config);
    Instrumentation instr = _getInstrumentation(log, config);
    // agent already exist
    if (instr != null)
        return instr;
    AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            ClassLoader ccl = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
            try {
                JavaVendor vendor = JavaVendor.getCurrentVendor();
                Resource toolsJar = null;
                // When running on IBM, the attach api classes are packaged in vm.jar which is a part
                // of the default vm classpath.
                RefBoolean useOurOwn = new RefBooleanImpl(true);
                // if (!vendor.isIBM()) {
                // If we can't find the tools.jar and we're not on IBM we can't load the agent.
                toolsJar = findToolsJar(config, log, useOurOwn);
                if (toolsJar == null) {
                    return null;
                }
                // }
                log.info("Instrumentation", "tools.jar used:" + toolsJar);
                // add the attach native library
                if (useOurOwn.toBooleanValue())
                    addAttachIfNecessary(config, log);
                Class<?> vmClass = loadVMClass(toolsJar, log, vendor);
                log.info("Instrumentation", "loaded VirtualMachine class:" + (vmClass == null ? "null" : vmClass.getName()));
                if (vmClass == null) {
                    return null;
                }
                String agentPath = createAgentJar(log, config).getAbsolutePath();
                if (agentPath == null) {
                    return null;
                }
                log.info("Instrumentation", "try to load agent (path:" + agentPath + ")");
                loadAgent(config, log, agentPath, vmClass);
            // log.info("Instrumentation","agent loaded (path:"+agentPath+")");
            } catch (IOException ioe) {
                log.log(Log.LEVEL_INFO, "Instrumentation", ioe);
            } finally {
                Thread.currentThread().setContextClassLoader(ccl);
            }
            return null;
        }
    });
    // If the load(...) agent call was successful, this variable will no
    // longer be null.
    instr = _getInstrumentation(log, config);
    if (instr == null) {
        try {
            Resource agentJar = createAgentJar(log, config);
            throw new PageRuntimeException(new ApplicationException(Constants.NAME + " was not able to load a Agent dynamically! " + "You need to load one manually by adding the following to your JVM arguments [-javaagent:\"" + (agentJar) + "\"]"));
        } catch (IOException ioe) {
            SystemOut.printDate(ioe);
        }
    }
    return instr;
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) Instrumentation(java.lang.instrument.Instrumentation) IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException) URLClassLoader(java.net.URLClassLoader) CFMLEngine(lucee.loader.engine.CFMLEngine) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Aggregations

Log (lucee.commons.io.log.Log)35 ConfigImpl (lucee.runtime.config.ConfigImpl)14 PageException (lucee.runtime.exp.PageException)10 Resource (lucee.commons.io.res.Resource)8 ApplicationException (lucee.runtime.exp.ApplicationException)8 DatasourceConnection (lucee.runtime.db.DatasourceConnection)7 Struct (lucee.runtime.type.Struct)6 SQLException (java.sql.SQLException)5 ZipInputStream (java.util.zip.ZipInputStream)5 DataSource (lucee.runtime.db.DataSource)5 InputStream (java.io.InputStream)4 ZipEntry (java.util.zip.ZipEntry)4 StructImpl (lucee.runtime.type.StructImpl)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 Attributes (java.util.jar.Attributes)3 DatabaseException (lucee.runtime.exp.DatabaseException)3 Key (lucee.runtime.type.Collection.Key)3