Search in sources :

Example 56 with ApplicationException

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

the class XMLConfigAdmin method _updateWebContexts.

private static void _updateWebContexts(Config config, InputStream is, String realpath, boolean closeStream, List<Resource> filesDeployed, boolean store) throws PageException, IOException, SAXException, BundleException {
    if (!(config instanceof ConfigServer))
        throw new ApplicationException("invalid context, you can only call this method from server context");
    ConfigServer cs = (ConfigServer) config;
    Resource wcd = cs.getConfigDir().getRealResource("web-context-deployment");
    Resource trg = wcd.getRealResource(realpath);
    if (trg.exists())
        trg.remove(true);
    Resource p = trg.getParentResource();
    if (!p.isDirectory())
        p.createDirectory(true);
    IOUtil.copy(is, trg.getOutputStream(false), closeStream, true);
    filesDeployed.add(trg);
    if (store)
        _storeAndReload((ConfigImpl) config);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) Resource(lucee.commons.io.res.Resource)

Example 57 with ApplicationException

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

the class XMLConfigAdmin method updateAPIKey.

public void updateAPIKey(String key) throws SecurityException, ApplicationException {
    checkWriteAccess();
    key = key.trim();
    if (!Decision.isGUId(key))
        throw new ApplicationException("passed API Key [" + key + "] is not valid");
    Element root = doc.getDocumentElement();
    root.setAttribute("api-key", key);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) Element(org.w3c.dom.Element)

Example 58 with ApplicationException

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

the class XMLConfigAdmin method updateClusterClass.

public void updateClusterClass(ClassDefinition cd) throws PageException {
    if (cd.getClassName() == null)
        cd = new ClassDefinitionImpl(ClusterNotSupported.class.getName(), null, null, null);
    Class clazz = null;
    try {
        clazz = cd.getClazz();
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
    if (!Reflector.isInstaneOf(clazz, Cluster.class) && !Reflector.isInstaneOf(clazz, ClusterRemote.class))
        throw new ApplicationException("class [" + clazz.getName() + "] does not implement interface [" + Cluster.class.getName() + "] or [" + ClusterRemote.class.getName() + "]");
    Element scope = _getRootElement("scope");
    setClass(scope, null, "cluster-", cd);
    ScopeContext.clearClusterScope();
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) ClusterNotSupported(lucee.runtime.type.scope.ClusterNotSupported) ApplicationException(lucee.runtime.exp.ApplicationException) Element(org.w3c.dom.Element) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) ConverterException(lucee.runtime.converter.ConverterException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CFXTagException(lucee.runtime.cfx.CFXTagException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClassException(lucee.commons.lang.ClassException) DOMException(org.w3c.dom.DOMException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) HTTPException(lucee.runtime.exp.HTTPException)

Example 59 with ApplicationException

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

the class XMLConfigAdmin method validateStorage.

private String validateStorage(String storage) throws ApplicationException {
    storage = storage.trim().toLowerCase();
    // empty
    if (StringUtil.isEmpty(storage, true))
        return "";
    // standard storages
    if ("cookie".equals(storage) || "memory".equals(storage) || "file".equals(storage))
        return storage;
    // aliases
    if ("ram".equals(storage))
        return "memory";
    if ("registry".equals(storage))
        return "file";
    // datasource
    DataSource ds = config.getDataSource(storage, null);
    if (ds != null) {
        if (ds.isStorage())
            return storage;
        throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session/client storage");
    }
    // cache
    CacheConnection cc = CacheUtil.getCacheConnection(ThreadLocalPageContext.get(config), storage, null);
    if (cc != null) {
        if (cc.isStorage())
            return storage;
        throw new ApplicationException("cache [" + storage + "] is not enabled to be used as session/client storage");
    }
    String sdx = StringUtil.soundex(storage);
    // check if a datasource has a similar name
    DataSource[] sources = config.getDataSources();
    for (int i = 0; i < sources.length; i++) {
        if (StringUtil.soundex(sources[i].getName()).equals(sdx))
            throw new ApplicationException("no matching storage for [" + storage + "] found, did you mean [" + sources[i].getName() + "]");
    }
    // check if a cache has a similar name
    Iterator<String> it = config.getCacheConnections().keySet().iterator();
    String name;
    while (it.hasNext()) {
        name = it.next();
        if (StringUtil.soundex(name).equals(sdx))
            throw new ApplicationException("no matching storage for [" + storage + "] found, did you mean [" + name + "]");
    }
    throw new ApplicationException("no matching storage for [" + storage + "] found");
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) CacheConnection(lucee.runtime.cache.CacheConnection) DataSource(lucee.runtime.db.DataSource)

Example 60 with ApplicationException

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

the class XMLConfigAdmin method updateCachedWithin.

public void updateCachedWithin(int type, Object value) throws SecurityException, ApplicationException {
    checkWriteAccess();
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING);
    if (!hasAccess)
        throw new SecurityException("no access to update cachedwithin setting");
    String t = AppListenerUtil.toCachedWithinType(type, "");
    if (t == null)
        throw new ApplicationException("invalid cachedwithin type defintion");
    String v = Caster.toString(value, null);
    Element app = _getRootElement("application");
    if (v != null)
        app.setAttribute("cached-within-" + t, v);
    else
        app.removeAttribute("cached-within-" + t);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) Element(org.w3c.dom.Element) SecurityException(lucee.runtime.exp.SecurityException)

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