Search in sources :

Example 1 with Mapping

use of lucee.runtime.rest.Mapping in project Lucee by lucee.

the class RestDeleteApplication method call.

public static String call(PageContext pc, String dirPath, String strWebAdminPassword) throws PageException {
    Password webAdminPassword = CacheUtil.getPassword(pc, strWebAdminPassword, false);
    Resource dir = RestDeleteApplication.toResource(pc, dirPath);
    ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
    try {
        XMLConfigAdmin admin = XMLConfigAdmin.newInstance((ConfigWebImpl) pc.getConfig(), webAdminPassword);
        Mapping[] mappings = config.getRestMappings();
        Mapping mapping;
        for (int i = 0; i < mappings.length; i++) {
            mapping = mappings[i];
            if (RestUtil.isMatch(pc, mapping, dir)) {
                admin.removeRestMapping(mapping.getVirtual());
                admin.storeAndReload();
            }
        }
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
    return null;
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Resource(lucee.commons.io.res.Resource) Mapping(lucee.runtime.rest.Mapping) XMLConfigAdmin(lucee.runtime.config.XMLConfigAdmin) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Password(lucee.runtime.config.Password)

Example 2 with Mapping

use of lucee.runtime.rest.Mapping in project Lucee by lucee.

the class RestInitApplication method _call.

public static String _call(PageContext pc, String dirPath, String serviceMapping, Boolean defaultMapping, String webAdminPassword) throws PageException {
    if (StringUtil.isEmpty(serviceMapping, true)) {
        serviceMapping = pc.getApplicationContext().getName();
    }
    Resource dir = RestDeleteApplication.toResource(pc, dirPath);
    ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
    Mapping[] mappings = config.getRestMappings();
    Mapping mapping;
    // id is mapping name
    String virtual = serviceMapping.trim();
    if (!virtual.startsWith("/"))
        virtual = "/" + virtual;
    if (!virtual.endsWith("/"))
        virtual += "/";
    boolean hasResetted = false;
    for (int i = 0; i < mappings.length; i++) {
        mapping = mappings[i];
        if (mapping.getVirtualWithSlash().equals(virtual)) {
            // directory has changed
            if (!RestUtil.isMatch(pc, mapping, dir) || (defaultMapping != null && mapping.isDefault() != defaultMapping.booleanValue())) {
                update(pc, dir, virtual, CacheUtil.getPassword(pc, webAdminPassword, false), defaultMapping == null ? mapping.isDefault() : defaultMapping.booleanValue());
            }
            mapping.reset(pc);
            hasResetted = true;
        }
    }
    if (!hasResetted) {
        update(pc, dir, virtual, CacheUtil.getPassword(pc, webAdminPassword, false), defaultMapping == null ? false : defaultMapping.booleanValue());
    }
    return null;
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Resource(lucee.commons.io.res.Resource) Mapping(lucee.runtime.rest.Mapping)

Aggregations

Resource (lucee.commons.io.res.Resource)2 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)2 Mapping (lucee.runtime.rest.Mapping)2 Password (lucee.runtime.config.Password)1 XMLConfigAdmin (lucee.runtime.config.XMLConfigAdmin)1 FunctionException (lucee.runtime.exp.FunctionException)1 PageException (lucee.runtime.exp.PageException)1