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;
}
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");
}
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;
}
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;
}
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);
}
}
Aggregations