Search in sources :

Example 26 with Log

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

the class ExecutionThread method execute.

public static void execute(Config config, ScheduleTask task, String charset) {
    Log log = getLog(config);
    boolean hasError = false;
    String logName = "schedule task:" + task.getTask();
    // init
    // HttpClient client = new HttpClient();
    // client.setStrictMode(false);
    // HttpState state = client.getState();
    String url;
    if (task.getUrl().getQuery() == null)
        url = task.getUrl().toExternalForm() + "?RequestTimeout=" + (task.getTimeout() / 1000);
    else if (StringUtil.isEmpty(task.getUrl().getQuery()))
        url = task.getUrl().toExternalForm() + "RequestTimeout=" + (task.getTimeout() / 1000);
    else {
        if (StringUtil.indexOfIgnoreCase(task.getUrl().getQuery() + "", "RequestTimeout") != -1)
            url = task.getUrl().toExternalForm();
        else
            url = task.getUrl().toExternalForm() + "&RequestTimeout=" + (task.getTimeout() / 1000);
    }
    // HttpMethod method = new GetMethod(url);
    // HostConfiguration hostConfiguration = client.getHostConfiguration();
    Header[] headers = new Header[] { HTTPEngine.header("User-Agent", "CFSCHEDULE") };
    // method.setRequestHeader("User-Agent","CFSCHEDULE");
    // Userame / Password
    Credentials credentials = task.getCredentials();
    String user = null, pass = null;
    if (credentials != null) {
        user = credentials.getUsername();
        pass = credentials.getPassword();
    // get.addRequestHeader("Authorization","Basic admin:spwwn1p");
    }
    // Proxy
    ProxyData proxy = task.getProxyData();
    if (!ProxyDataImpl.isValid(proxy) && config.isProxyEnableFor(task.getUrl().getHost())) {
        proxy = config.getProxyData();
    }
    HTTPResponse rsp = null;
    // execute
    try {
        rsp = HTTPEngine.get(new URL(url), user, pass, task.getTimeout(), true, charset, null, proxy, headers);
    } catch (Exception e) {
        LogUtil.log(log, Log.LEVEL_ERROR, logName, e);
        hasError = true;
    }
    // write file
    Resource file = task.getResource();
    if (!hasError && file != null && task.isPublish()) {
        String n = file.getName();
        if (n.indexOf("{id}") != -1) {
            n = StringUtil.replace(n, "{id}", CreateUUID.invoke(), false);
            file = file.getParentResource().getRealResource(n);
        }
        if (isText(rsp) && task.isResolveURL()) {
            String str;
            try {
                InputStream stream = rsp.getContentAsStream();
                str = stream == null ? "" : IOUtil.toString(stream, (Charset) null);
                if (str == null)
                    str = "";
            } catch (IOException e) {
                str = e.getMessage();
            }
            try {
                str = new URLResolver().transform(str, task.getUrl(), false);
            } catch (PageException e) {
                LogUtil.log(log, Log.LEVEL_ERROR, logName, e);
                hasError = true;
            }
            try {
                IOUtil.write(file, str, charset, false);
            } catch (IOException e) {
                LogUtil.log(log, Log.LEVEL_ERROR, logName, e);
                hasError = true;
            }
        } else {
            try {
                IOUtil.copy(rsp.getContentAsStream(), file, true);
            } catch (IOException e) {
                LogUtil.log(log, Log.LEVEL_ERROR, logName, e);
                hasError = true;
            }
        }
        HTTPEngine.closeEL(rsp);
    }
    if (!hasError)
        log.log(Log.LEVEL_INFO, logName, "executed");
}
Also used : PageException(lucee.runtime.exp.PageException) Log(lucee.commons.io.log.Log) InputStream(java.io.InputStream) HTTPResponse(lucee.commons.net.http.HTTPResponse) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) PageException(lucee.runtime.exp.PageException) ProxyData(lucee.runtime.net.proxy.ProxyData) Header(lucee.commons.net.http.Header) URLResolver(lucee.runtime.util.URLResolver) Credentials(lucee.commons.security.Credentials)

Example 27 with Log

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

the class XMLConfigWebFactory method toAMFEngine.

private static AMFEngine toAMFEngine(Config config, ClassDefinition<AMFEngine> cd, AMFEngine defaultValue) {
    Log log = config.getLog("application");
    try {
        Class<AMFEngine> clazz = cd.getClazz(null);
        if (clazz != null) {
            Object obj = clazz.newInstance();
            if ((obj instanceof AMFEngine))
                return (AMFEngine) obj;
            log.error("Flex", "object [" + Caster.toClassName(obj) + "] must implement the interface " + AMFEngine.class.getName());
        }
    } catch (Exception e) {
        log.error("Flex", e);
    }
    return defaultValue;
}
Also used : ConsoleExecutionLog(lucee.runtime.engine.ConsoleExecutionLog) Log(lucee.commons.io.log.Log) ExecutionLog(lucee.runtime.engine.ExecutionLog) AMFEngine(lucee.runtime.net.amf.AMFEngine) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) ClassException(lucee.commons.lang.ClassException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 28 with Log

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

the class XMLConfigWebFactory method load.

/**
 * @param cs
 * @param config
 * @param doc
 * @throws ClassNotFoundException
 * @throws IOException
 * @throws FunctionLibException
 * @throws TagLibException
 * @throws PageException
 * @throws BundleException
 */
static synchronized void load(ConfigServerImpl cs, ConfigImpl config, Document doc, boolean isReload, boolean doNew) throws ClassException, PageException, IOException, TagLibException, FunctionLibException, BundleException {
    if (LOG)
        SystemOut.printDate("start reading config");
    ThreadLocalConfig.register(config);
    boolean reload = false;
    // fix stuff from older config files
    if (XMLConfigAdmin.fixLFI(doc)) {
        String xml = XMLCaster.toString(doc);
        // TODO 4.5->5.0
        xml = StringUtil.replace(xml, "<lucee-configuration", "<cfLuceeConfiguration", false);
        xml = StringUtil.replace(xml, "</lucee-configuration", "</cfLuceeConfiguration", false);
        IOUtil.write(config.getConfigFile(), xml, CharsetUtil.UTF8, false);
        try {
            doc = XMLConfigWebFactory.loadDocument(config.getConfigFile());
        } catch (SAXException e) {
        }
    }
    if (LOG)
        SystemOut.printDate("fixed LFI");
    if (XMLConfigAdmin.fixSalt(doc))
        reload = true;
    if (LOG)
        SystemOut.printDate("fixed salt");
    if (XMLConfigAdmin.fixS3(doc))
        reload = true;
    if (LOG)
        SystemOut.printDate("fixed S3");
    if (XMLConfigAdmin.fixPSQ(doc))
        reload = true;
    if (LOG)
        SystemOut.printDate("fixed PSQ");
    if (XMLConfigAdmin.fixLogging(cs, config, doc))
        reload = true;
    if (LOG)
        SystemOut.printDate("fixed logging");
    if (XMLConfigAdmin.fixExtension(config, doc))
        reload = true;
    if (LOG)
        SystemOut.printDate("fixed Extension");
    if (XMLConfigAdmin.fixComponentMappings(config, doc))
        reload = true;
    if (LOG)
        SystemOut.printDate("fixed component mappings");
    // delete to big felix.log (there is also code in the loader to do this, but if the loader is not updated ...)
    if (config instanceof ConfigServerImpl) {
        ConfigServerImpl _cs = (ConfigServerImpl) config;
        File root = _cs.getCFMLEngine().getCFMLEngineFactory().getResourceRoot();
        File log = new File(root, "context/logs/felix.log");
        if (log.isFile() && log.length() > GB1) {
            SystemOut.printDate("delete felix log: " + log);
            if (log.delete())
                ResourceUtil.touch(log);
        }
    }
    if (LOG)
        SystemOut.printDate("fixed to big felix.log");
    if (reload) {
        XMLCaster.writeTo(doc, config.getConfigFile());
        try {
            doc = XMLConfigWebFactory.loadDocument(config.getConfigFile());
        } catch (SAXException e) {
        }
        if (LOG)
            SystemOut.printDate("reload xml");
    }
    config.setLastModified();
    if (config instanceof ConfigWeb)
        ConfigWebUtil.deployWebContext(cs, (ConfigWeb) config, false);
    if (config instanceof ConfigWeb)
        ConfigWebUtil.deployWeb(cs, (ConfigWeb) config, false);
    if (LOG)
        SystemOut.printDate("deploy web context");
    loadConfig(cs, config, doc);
    int mode = config.getMode();
    Log log = config.getLog("application");
    if (LOG)
        SystemOut.printDate("loaded config");
    loadConstants(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded constants");
    loadLoggers(cs, config, doc, isReload);
    log = config.getLog("application");
    // loadServerLibDesc(cs, config, doc,log);
    if (LOG)
        SystemOut.printDate("loaded loggers");
    loadTempDirectory(cs, config, doc, isReload);
    if (LOG)
        SystemOut.printDate("loaded temp dir");
    loadId(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded id");
    loadVersion(config, doc);
    if (LOG)
        SystemOut.printDate("loaded version");
    loadSecurity(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded security");
    ConfigWebUtil.loadLib(cs, config);
    if (LOG)
        SystemOut.printDate("loaded lib");
    loadSystem(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded system");
    loadResourceProvider(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded resource providers");
    // load this before execute any code, what for example loadxtension does (json)
    loadFilesystem(cs, config, doc, doNew);
    if (LOG)
        SystemOut.printDate("loaded filesystem");
    loadExtensionBundles(cs, config, doc, log);
    if (LOG)
        SystemOut.printDate("loaded extension bundles");
    loadORM(cs, config, doc, log);
    if (LOG)
        SystemOut.printDate("loaded orm");
    loadCacheHandler(cs, config, doc, log);
    if (LOG)
        SystemOut.printDate("loaded cache handlers");
    loadCharset(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded charset");
    loadApplication(cs, config, doc, mode);
    if (LOG)
        SystemOut.printDate("loaded application");
    // it is important this runs after
    loadMappings(cs, config, doc, mode);
    if (LOG)
        SystemOut.printDate("loaded mappings");
    // loadApplication
    loadRest(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded rest");
    loadExtensions(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded extensions");
    loadPagePool(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded page pool");
    loadDataSources(cs, config, doc, log);
    if (LOG)
        SystemOut.printDate("loaded datasources");
    loadCache(cs, config, doc, log);
    if (LOG)
        SystemOut.printDate("loaded cache");
    loadCustomTagsMappings(cs, config, doc, mode);
    if (LOG)
        SystemOut.printDate("loaded custom tag mappings");
    // loadFilesystem(cs, config, doc, doNew); // load tlds
    // load tlds
    loadTag(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded tags");
    loadRegional(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded regional");
    loadCompiler(cs, config, doc, mode);
    if (LOG)
        SystemOut.printDate("loaded compiler");
    loadScope(cs, config, doc, mode);
    if (LOG)
        SystemOut.printDate("loaded scope");
    loadMail(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded mail");
    loadSearch(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded search");
    loadScheduler(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded scheduled tasks");
    loadDebug(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded debug");
    loadError(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded error");
    loadCFX(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded cfx");
    loadComponent(cs, config, doc, mode);
    if (LOG)
        SystemOut.printDate("loaded component");
    loadUpdate(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded update");
    // define compile type
    loadJava(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded java");
    loadSetting(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded setting");
    loadProxy(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded proxy");
    loadRemoteClient(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded remote clients");
    loadVideo(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded video");
    loadFlex(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded flex");
    settings(config);
    if (LOG)
        SystemOut.printDate("loaded settings2");
    loadListener(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded listeners");
    loadDumpWriter(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded dump writers");
    loadGatewayEL(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded gateways");
    loadExeLog(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded exe log");
    loadQueue(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded queue");
    loadMonitors(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded monitors");
    loadLogin(cs, config, doc);
    if (LOG)
        SystemOut.printDate("loaded login");
    config.setLoadTime(System.currentTimeMillis());
    if (config instanceof ConfigWebImpl) {
        TagUtil.addTagMetaData((ConfigWebImpl) config);
        if (LOG)
            SystemOut.printDate("added tag meta data");
    }
// ThreadLocalConfig.release();
}
Also used : ConsoleExecutionLog(lucee.runtime.engine.ConsoleExecutionLog) Log(lucee.commons.io.log.Log) ExecutionLog(lucee.runtime.engine.ExecutionLog) File(java.io.File) lucee.aprint(lucee.aprint) SAXException(org.xml.sax.SAXException)

Example 29 with Log

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

the class RHExtension method toQuery.

public static Query toQuery(Config config, RHExtension[] children) throws PageException {
    Log log = config.getLog("deploy");
    Query qry = createQuery();
    for (int i = 0; i < children.length; i++) {
        try {
            // ,i+1
            children[i].populate(qry);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            log.error("extension", t);
        }
    }
    return qry;
}
Also used : Query(lucee.runtime.type.Query) Log(lucee.commons.io.log.Log)

Example 30 with Log

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

the class RHExtension method readManifestConfig.

private void readManifestConfig(Element el, String label, String _img) throws ApplicationException {
    boolean isWeb = config instanceof ConfigWeb;
    type = isWeb ? "web" : "server";
    Log logger = ((ConfigImpl) config).getLog("deploy");
    Info info = ConfigWebUtil.getEngine(config).getInfo();
    readName(label, el.getAttribute("name"));
    label = name;
    readVersion(label, el.getAttribute("version"));
    label += " : " + version;
    readId(label, el.getAttribute("id"));
    readReleaseType(label, el.getAttribute("release-type"), isWeb);
    description = el.getAttribute("description");
    trial = Caster.toBooleanValue(el.getAttribute("trial"), false);
    if (_img == null)
        _img = el.getAttribute("image");
    image = _img;
    String cat = el.getAttribute("category");
    if (StringUtil.isEmpty(cat, true))
        cat = el.getAttribute("categories");
    readCategories(label, cat);
    readCoreVersion(label, el.getAttribute("lucee-core-version"), info);
    readLoaderVersion(label, el.getAttribute("lucee-loader-version"));
    startBundles = Caster.toBooleanValue(el.getAttribute("start-bundles"), true);
    readAMF(label, el.getAttribute("amf"), logger);
    readResource(label, el.getAttribute("resource"), logger);
    readSearch(label, el.getAttribute("search"), logger);
    readORM(label, el.getAttribute("orm"), logger);
    readMonitor(label, el.getAttribute("monitor"), logger);
    readCache(label, el.getAttribute("cache"), logger);
    readCacheHandler(label, el.getAttribute("cache-handler"), logger);
    readJDBC(label, el.getAttribute("jdbc"), logger);
    readMapping(label, el.getAttribute("mapping"), logger);
    readEventGatewayInstances(label, el.getAttribute("event-gateway-instance"), logger);
}
Also used : Log(lucee.commons.io.log.Log) Info(lucee.Info) BundleInfo(lucee.runtime.osgi.BundleInfo) ConfigWeb(lucee.runtime.config.ConfigWeb) ConfigImpl(lucee.runtime.config.ConfigImpl)

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