Search in sources :

Example 76 with ApplicationException

use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.

the class ConfigImpl method getORMEngine.

@Override
public ORMEngine getORMEngine(PageContext pc) throws PageException {
    String name = pc.getApplicationContext().getName();
    ORMEngine engine = ormengines.get(name);
    if (engine == null) {
        // try {
        Throwable t = null;
        try {
            engine = (ORMEngine) ClassUtil.loadInstance(cdORMEngine.getClazz());
            engine.init(pc);
        } catch (ClassException ce) {
            t = ce;
        } catch (BundleException be) {
            t = be;
        } catch (NoClassDefFoundError ncfe) {
            t = ncfe;
        }
        if (t != null) {
            ApplicationException ae = new ApplicationException("cannot initialize ORM Engine [" + cdORMEngine + "], make sure you have added all the required jar files");
            ae.setStackTrace(t.getStackTrace());
            ae.setDetail(t.getMessage());
        }
        ormengines.put(name, engine);
    /*}
			catch (PageException pe) {
				throw pe;
			}*/
    }
    return engine;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) ORMEngine(lucee.runtime.orm.ORMEngine) ClassException(lucee.commons.lang.ClassException) BundleException(org.osgi.framework.BundleException)

Example 77 with ApplicationException

use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.

the class ConfigServerImpl method checkAccess.

public void checkAccess(String key, long timeNonce) throws PageException {
    if (previousNonces.containsKey(timeNonce)) {
        long now = System.currentTimeMillis();
        long diff = timeNonce > now ? timeNonce - now : now - timeNonce;
        if (diff > 10)
            throw new ApplicationException("nonce was already used, same nonce can only be used once");
    }
    long now = System.currentTimeMillis() + getTimeServerOffset();
    if (timeNonce > (now + FIVE_SECONDS) || timeNonce < (now - FIVE_SECONDS))
        throw new ApplicationException("nonce is outdated (timserver offset:" + getTimeServerOffset() + ")");
    previousNonces.put(timeNonce, "");
    String[] keys = getAuthenticationKeys();
    // check if one of the keys matching
    String hash;
    for (int i = 0; i < keys.length; i++) {
        try {
            hash = Hash.hash(keys[i], Caster.toString(timeNonce), Hash.ALGORITHM_SHA_256, Hash.ENCODING_HEX);
            if (hash.equals(key))
                return;
        } catch (NoSuchAlgorithmException e) {
            throw Caster.toPageException(e);
        }
    }
    throw new ApplicationException("No access, no matching authentication key found");
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 78 with ApplicationException

use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.

the class ConfigWebImpl method getSearchEngine.

@Override
public SearchEngine getSearchEngine(PageContext pc) throws PageException {
    if (searchEngine == null) {
        try {
            Object o = ClassUtil.loadInstance(getSearchEngineClassDefinition().getClazz());
            if (o instanceof SearchEngine)
                searchEngine = (SearchEngine) o;
            else
                throw new ApplicationException("class [" + o.getClass().getName() + "] does not implement the interface SearchEngine");
            searchEngine.init(this, ConfigWebUtil.getFile(getConfigDir(), ConfigWebUtil.translateOldPath(getSearchEngineDirectory()), "search", getConfigDir(), FileUtil.TYPE_DIR, this));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    return searchEngine;
}
Also used : SearchEngine(lucee.runtime.search.SearchEngine) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException) BundleException(org.osgi.framework.BundleException) SecurityException(lucee.runtime.exp.SecurityException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 79 with ApplicationException

use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.

the class ScopeContext method getClientScope.

public Client getClientScope(PageContext pc) throws PageException {
    ApplicationContext appContext = pc.getApplicationContext();
    // get Context
    Map<String, Scope> context = getSubMap(cfClientContexts, appContext.getName());
    // get Client
    boolean isMemory = false;
    String storage = appContext.getClientstorage();
    if (StringUtil.isEmpty(storage, true)) {
        storage = ConfigImpl.DEFAULT_STORAGE_CLIENT;
    } else if ("ram".equalsIgnoreCase(storage)) {
        storage = "memory";
        isMemory = true;
    } else if ("registry".equalsIgnoreCase(storage)) {
        storage = "file";
    } else {
        storage = storage.toLowerCase();
        if ("memory".equals(storage))
            isMemory = true;
    }
    Client existing = (Client) context.get(pc.getCFID());
    Client client = appContext.getClientCluster() ? null : existing;
    // client=doMemory?(Client) context.get(pc.getCFID()):null;
    if (client == null || client.isExpired() || !client.getStorage().equalsIgnoreCase(storage)) {
        if ("file".equals(storage)) {
            client = ClientFile.getInstance(appContext.getName(), pc, getLog());
        } else if ("cookie".equals(storage))
            client = ClientCookie.getInstance(appContext.getName(), pc, getLog());
        else if ("memory".equals(storage)) {
            if (existing != null)
                client = existing;
            client = ClientMemory.getInstance(pc, getLog());
        } else {
            DataSource ds = pc.getDataSource(storage, null);
            if (ds != null) {
                if (INVIDUAL_STORAGE_KEYS) {
                    try {
                        client = (Client) IKStorageScopeSupport.getInstance(Scope.SCOPE_CLIENT, new IKHandlerDatasource(), appContext.getName(), storage, pc, existing, getLog());
                    } catch (PageException pe) {
                        // code above could fail when an old scope is loaded, remember client scope can be easy be
                        // 180 days old
                        client = ClientDatasource.getInstance(storage, pc, getLog());
                    }
                } else
                    client = ClientDatasource.getInstance(storage, pc, getLog());
            } else {
                if (INVIDUAL_STORAGE_KEYS) {
                    try {
                        client = (Client) IKStorageScopeSupport.getInstance(Scope.SCOPE_CLIENT, new IKHandlerCache(), appContext.getName(), storage, pc, existing, getLog());
                    } catch (PageException pe) {
                        // code above could fail when an old scope is loaded, remember client scope can be easy be
                        // 180 days old
                        client = ClientCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
                    }
                } else
                    client = ClientCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
            }
            if (client == null) {
                // datasource not enabled for storage
                if (ds != null)
                    throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session/client storage, you have to enable it in the Lucee administrator.");
                CacheConnection cc = CacheUtil.getCacheConnection(pc, storage, null);
                if (cc != null)
                    throw new ApplicationException("cache [" + storage + "] is not enabled to be used  as a session/client storage, you have to enable it in the Lucee administrator.");
                throw new ApplicationException("there is no cache or datasource with name [" + storage + "] defined.");
            }
        }
        client.setStorage(storage);
        context.put(pc.getCFID(), client);
    } else
        getLog().log(Log.LEVEL_INFO, "scope-context", "use existing client scope for " + appContext.getName() + "/" + pc.getCFID() + " from storage " + storage);
    client.touchBeforeRequest(pc);
    return client;
}
Also used : PageException(lucee.runtime.exp.PageException) ApplicationContext(lucee.runtime.listener.ApplicationContext) ApplicationException(lucee.runtime.exp.ApplicationException) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) CacheConnection(lucee.runtime.cache.CacheConnection) IKHandlerCache(lucee.runtime.type.scope.storage.IKHandlerCache) DataSource(lucee.runtime.db.DataSource) IKHandlerDatasource(lucee.runtime.type.scope.storage.IKHandlerDatasource)

Example 80 with ApplicationException

use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.

the class IKHandlerDatasource method loadData.

@Override
public IKStorageValue loadData(PageContext pc, String appName, String name, String strType, int type, Log log) throws PageException {
    ConfigImpl config = (ConfigImpl) ThreadLocalPageContext.getConfig(pc);
    DatasourceConnectionPool pool = config.getDatasourceConnectionPool();
    DatasourceConnection dc = pool.getDatasourceConnection(config, pc.getDataSource(name), null, null);
    SQLExecutor executor = SQLExecutionFactory.getInstance(dc);
    Query query;
    try {
        if (!dc.getDatasource().isStorage())
            throw new ApplicationException("storage usage for this datasource is disabled, you can enable this in the Lucee administrator.");
        query = executor.select(config, pc.getCFID(), pc.getApplicationContext().getName(), dc, type, log, true);
    } catch (SQLException se) {
        throw Caster.toPageException(se);
    } finally {
        if (dc != null)
            pool.releaseDatasourceConnection(dc);
    }
    if (query != null && config.debug()) {
        boolean debugUsage = DebuggerUtil.debugQueryUsage(pc, query);
        pc.getDebugger().addQuery(debugUsage ? query : null, name, "", query.getSql(), query.getRecordcount(), ((PageContextImpl) pc).getCurrentPageSource(null), query.getExecutionTime());
    }
    boolean _isNew = query.getRecordcount() == 0;
    if (_isNew) {
        ScopeContext.info(log, "create new " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID() + " in datasource [" + name + "]");
        return null;
    }
    String str = Caster.toString(query.getAt(KeyConstants._data, 1));
    if (str.startsWith("struct:"))
        return null;
    try {
        IKStorageValue data = (IKStorageValue) JavaConverter.deserialize(str);
        ScopeContext.info(log, "load existing data from [" + name + "." + PREFIX + "_" + strType + "_data] to create " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
        return data;
    } catch (Exception e) {
        ScopeContext.error(log, e);
        return null;
    // throw Caster.toPageException(e);
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) DatasourceConnectionPool(lucee.runtime.db.DatasourceConnectionPool) DatasourceConnection(lucee.runtime.db.DatasourceConnection) Query(lucee.runtime.type.Query) SQLExecutor(lucee.runtime.type.scope.storage.db.SQLExecutor) SQLException(java.sql.SQLException) ConfigImpl(lucee.runtime.config.ConfigImpl) SQLException(java.sql.SQLException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException)

Aggregations

ApplicationException (lucee.runtime.exp.ApplicationException)173 IOException (java.io.IOException)41 Resource (lucee.commons.io.res.Resource)36 PageException (lucee.runtime.exp.PageException)30 Struct (lucee.runtime.type.Struct)25 SecurityException (lucee.runtime.exp.SecurityException)17 BundleException (org.osgi.framework.BundleException)16 StructImpl (lucee.runtime.type.StructImpl)15 MalformedURLException (java.net.MalformedURLException)13 Element (org.w3c.dom.Element)13 Array (lucee.runtime.type.Array)12 Key (lucee.runtime.type.Collection.Key)12 Iterator (java.util.Iterator)11 InputStream (java.io.InputStream)10 Query (lucee.runtime.type.Query)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ExpressionException (lucee.runtime.exp.ExpressionException)9 Entry (java.util.Map.Entry)8 PageContextImpl (lucee.runtime.PageContextImpl)8 ClassDefinition (lucee.runtime.db.ClassDefinition)8