Search in sources :

Example 1 with GatewayEntry

use of lucee.runtime.gateway.GatewayEntry in project Lucee by lucee.

the class XMLConfigWebFactory method loadGateway.

private static void loadGateway(ConfigServerImpl configServer, ConfigImpl config, Document doc) {
    boolean hasCS = configServer != null;
    // ConfigWebImpl cw = (ConfigWebImpl) config;
    GatewayEngineImpl engine = hasCS ? ((ConfigWebImpl) config).getGatewayEngine() : null;
    Map<String, GatewayEntry> mapGateways = new HashMap<String, GatewayEntry>();
    // get from server context
    if (hasCS) {
        Map<String, GatewayEntry> entries = configServer.getGatewayEntries();
        if (entries != null && !entries.isEmpty()) {
            Iterator<Entry<String, GatewayEntry>> it = entries.entrySet().iterator();
            Entry<String, GatewayEntry> e;
            while (it.hasNext()) {
                e = it.next();
                mapGateways.put(e.getKey(), ((GatewayEntryImpl) e.getValue()).duplicateReadOnly(engine));
            }
        }
    }
    Element eGateWay = getChildByName(doc.getDocumentElement(), "gateways");
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_GATEWAY);
    GatewayEntry ge;
    // cache connections
    Element[] gateways = getChildren(eGateWay, "gateway");
    // if(hasAccess) {
    String id;
    // caches
    if (hasAccess) {
        for (int i = 0; i < gateways.length; i++) {
            Element eConnection = gateways[i];
            id = getAttr(eConnection, "id").trim().toLowerCase();
            ge = new GatewayEntryImpl(engine, id, getClassDefinition(eConnection, "", config.getIdentification()), eConnection.getAttribute("cfc-path"), eConnection.getAttribute("listener-cfc-path"), getAttr(eConnection, "startup-mode"), toStruct(getAttr(eConnection, "custom")), Caster.toBooleanValue(getAttr(eConnection, "read-only"), false));
            if (!StringUtil.isEmpty(id)) {
                mapGateways.put(id.toLowerCase(), ge);
            } else
                SystemOut.print(config.getErrWriter(), "missing id");
        }
        config.setGatewayEntries(mapGateways);
    } else if (hasCS) {
        ((ConfigWebImpl) config).getGatewayEngine().clear();
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) GatewayEngineImpl(lucee.runtime.gateway.GatewayEngineImpl) Element(org.w3c.dom.Element) lucee.aprint(lucee.aprint) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) Entry(java.util.Map.Entry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) GatewayEntryImpl(lucee.runtime.gateway.GatewayEntryImpl)

Example 2 with GatewayEntry

use of lucee.runtime.gateway.GatewayEntry in project Lucee by lucee.

the class Admin method doGetGatewayEntries.

private void doGetGatewayEntries() throws PageException {
    Map entries = ((ConfigWebImpl) config).getGatewayEngine().getEntries();
    Iterator it = entries.entrySet().iterator();
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "class", "bundleName", "bundleVersion", "id", "custom", "cfcPath", "listenerCfcPath", "startupMode", "state", "readOnly" }, 0, "entries");
    Map.Entry entry;
    GatewayEntry ge;
    // Gateway g;
    int row = 0;
    while (it.hasNext()) {
        row++;
        entry = (Entry) it.next();
        ge = (GatewayEntry) entry.getValue();
        // g=ge.getGateway();
        qry.addRow();
        qry.setAtEL("class", row, ge.getClassDefinition().getClassName());
        qry.setAtEL("bundleName", row, ge.getClassDefinition().getName());
        qry.setAtEL("bundleVersion", row, ge.getClassDefinition().getVersionAsString());
        qry.setAtEL("id", row, ge.getId());
        qry.setAtEL("listenerCfcPath", row, ge.getListenerCfcPath());
        qry.setAtEL("cfcPath", row, ge.getCfcPath());
        qry.setAtEL("startupMode", row, GatewayEntryImpl.toStartup(ge.getStartupMode(), "automatic"));
        qry.setAtEL("custom", row, ge.getCustom());
        qry.setAtEL("readOnly", row, Caster.toBoolean(ge.isReadOnly()));
        qry.setAtEL("state", row, GatewayEngineImpl.toStringState(GatewayUtil.getState(ge), "failed"));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : Entry(java.util.Map.Entry) QueryImpl(lucee.runtime.type.QueryImpl) Iterator(java.util.Iterator) GatewayEntry(lucee.runtime.gateway.GatewayEntry) Map(java.util.Map) HashMap(java.util.HashMap) Query(lucee.runtime.type.Query)

Example 3 with GatewayEntry

use of lucee.runtime.gateway.GatewayEntry in project Lucee by lucee.

the class Admin method doGetGatewayEntry.

private void doGetGatewayEntry() throws PageException {
    String id = getString("admin", action, "id");
    Map entries = ((ConfigWebImpl) config).getGatewayEngine().getEntries();
    Iterator it = entries.keySet().iterator();
    GatewayEntry ge;
    // Gateway g;
    Struct sct;
    while (it.hasNext()) {
        String key = (String) it.next();
        if (key.equalsIgnoreCase(id)) {
            ge = (GatewayEntry) entries.get(key);
            // g=ge.getGateway();
            sct = new StructImpl();
            sct.setEL("id", ge.getId());
            sct.setEL("class", ge.getClassDefinition().getClassName());
            sct.setEL("bundleName", ge.getClassDefinition().getName());
            sct.setEL("bundleVersion", ge.getClassDefinition().getVersionAsString());
            sct.setEL("listenerCfcPath", ge.getListenerCfcPath());
            sct.setEL("cfcPath", ge.getCfcPath());
            sct.setEL("startupMode", GatewayEntryImpl.toStartup(ge.getStartupMode(), "automatic"));
            sct.setEL("custom", ge.getCustom());
            sct.setEL("readOnly", Caster.toBoolean(ge.isReadOnly()));
            sct.setEL("state", GatewayEngineImpl.toStringState(GatewayUtil.getState(ge), "failed"));
            pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
            return;
        }
    }
    throw new ApplicationException("there is no gateway entry with id [" + id + "]");
}
Also used : StructImpl(lucee.runtime.type.StructImpl) ApplicationException(lucee.runtime.exp.ApplicationException) Iterator(java.util.Iterator) GatewayEntry(lucee.runtime.gateway.GatewayEntry) Map(java.util.Map) HashMap(java.util.HashMap) Struct(lucee.runtime.type.Struct)

Example 4 with GatewayEntry

use of lucee.runtime.gateway.GatewayEntry in project Lucee by lucee.

the class XMLConfigAdmin method _removeGatewayEntry.

protected void _removeGatewayEntry(String name) throws PageException {
    if (StringUtil.isEmpty(name))
        throw new ExpressionException("name for Gateway Id can be a empty value");
    Element parent = _getRootElement("gateways");
    // remove element
    Element[] children = XMLConfigWebFactory.getChildren(parent, "gateway");
    for (int i = 0; i < children.length; i++) {
        String n = children[i].getAttribute("id");
        if (n != null && n.equalsIgnoreCase(name)) {
            Map conns = ((ConfigWebImpl) config).getGatewayEngine().getEntries();
            GatewayEntry ge = (GatewayEntry) conns.get(n);
            if (ge != null) {
                ((ConfigWebImpl) config).getGatewayEngine().remove(ge);
            }
            parent.removeChild(children[i]);
        }
    }
}
Also used : Element(org.w3c.dom.Element) GatewayEntry(lucee.runtime.gateway.GatewayEntry) Map(java.util.Map) HashMap(java.util.HashMap) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

HashMap (java.util.HashMap)4 GatewayEntry (lucee.runtime.gateway.GatewayEntry)4 Map (java.util.Map)3 Iterator (java.util.Iterator)2 Entry (java.util.Map.Entry)2 Element (org.w3c.dom.Element)2 LinkedHashMap (java.util.LinkedHashMap)1 lucee.aprint (lucee.aprint)1 DumpWriterEntry (lucee.runtime.dump.DumpWriterEntry)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 GatewayEngineImpl (lucee.runtime.gateway.GatewayEngineImpl)1 GatewayEntryImpl (lucee.runtime.gateway.GatewayEntryImpl)1 Query (lucee.runtime.type.Query)1 QueryImpl (lucee.runtime.type.QueryImpl)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1