Search in sources :

Example 1 with GatewayEngineImpl

use of lucee.runtime.gateway.GatewayEngineImpl 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 GatewayEngineImpl

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

the class Props method call.

@Override
public Object call(PageContext pc) throws PageException {
    // remote persistent (only type server is supported)
    // Caster.toString(pc.urlFormScope().get(REMOTE_PERSISTENT_ID,null),null);
    String strRemotePersisId = Caster.toString(getURLorForm(pc, REMOTE_PERSISTENT_ID, null), null);
    if (!StringUtil.isEmpty(strRemotePersisId, true)) {
        strRemotePersisId = strRemotePersisId.trim();
    } else
        strRemotePersisId = null;
    HttpServletRequest req = pc.getHttpServletRequest();
    // client
    String client = Caster.toString(req.getAttribute("client"), null);
    // call type (invocation, store-only)
    String callType = Caster.toString(req.getAttribute("call-type"), null);
    boolean internalCall = "lucee-gateway-1-0".equals(client) || "lucee-listener-1-0".equals(client);
    boolean fromRest = "lucee-rest-1-0".equals(client);
    Component component;
    try {
        pc.setSilent();
        // load the cfc
        try {
            if (internalCall && strRemotePersisId != null) {
                ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
                GatewayEngineImpl engine = config.getGatewayEngine();
                component = engine.getPersistentRemoteCFC(strRemotePersisId);
                if (component == null) {
                    component = newInstance(pc, getComponentName(), false, false, true);
                    if (!internalCall)
                        component = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_REMOTE, component);
                    engine.setPersistentRemoteCFC(strRemotePersisId, component);
                }
            } else {
                component = newInstance(pc, getComponentName(), false, false, true);
                if (!internalCall)
                    component = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_REMOTE, component);
            }
        } finally {
            pc.unsetSilent();
        }
        // Only get the Component, no invocation
        if ("store-only".equals(callType)) {
            req.setAttribute("component", component);
            return null;
        }
        // METHOD INVOCATION
        String qs = ReqRspUtil.getQueryString(pc.getHttpServletRequest());
        if (pc.getBasePageSource() == this.getPageSource() && pc.getConfig().debug())
            pc.getDebugger().setOutput(false);
        boolean isPost = pc.getHttpServletRequest().getMethod().equalsIgnoreCase("POST");
        boolean suppressContent = pc.getRequestDialect() == CFMLEngine.DIALECT_LUCEE || ((PageContextImpl) pc).getSuppressContent();
        if (suppressContent)
            pc.clear();
        Object method;
        if (fromRest) {
            callRest(pc, component, Caster.toString(req.getAttribute("rest-path"), ""), (Result) req.getAttribute("rest-result"), suppressContent);
            return null;
        }
        // POST
        if (isPost) {
            // Soap
            if (isSoap(pc)) {
                callWebservice(pc, component);
                // close(pc);
                return null;
            } else // WDDX
            if ((method = getURLorForm(pc, KeyConstants._method, null)) != null) {
                callWDDX(pc, component, KeyImpl.toKey(method), suppressContent);
                // close(pc);
                return null;
            }
        } else // GET
        {
            // WSDL
            if (qs != null && (qs.trim().equalsIgnoreCase("wsdl") || qs.trim().startsWith("wsdl&"))) {
                callWSDL(pc, component);
                // close(pc);
                return null;
            } else // WDDX
            if ((method = getURLorForm(pc, KeyConstants._method, null)) != null) {
                callWDDX(pc, component, KeyImpl.toKey(method), suppressContent);
                // close(pc);
                return null;
            }
            if (qs != null) {
                int rf = UDFUtil.toReturnFormat(qs.trim(), -1);
                if (rf != -1)
                    callCFCMetaData(pc, component, rf);
                // close(pc);
                return null;
            }
        }
        // Include MUST
        Array path = pc.getTemplatePath();
        // if(path.size()>1 ) {
        if (path.size() > 1 && !(path.size() == 3 && ListUtil.last(path.getE(2).toString(), "/\\", true).equalsIgnoreCase(pc.getRequestDialect() == CFMLEngine.DIALECT_CFML ? lucee.runtime.config.Constants.CFML_APPLICATION_EVENT_HANDLER : lucee.runtime.config.Constants.LUCEE_APPLICATION_EVENT_HANDLER))) {
            // MUSTMUST bad impl -> check with and without application . cfc
            ComponentSpecificAccess c = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, component);
            Key[] keys = c.keys();
            Object el;
            Scope var = pc.variablesScope();
            for (int i = 0; i < keys.length; i++) {
                el = c.get(keys[i], null);
                if (el instanceof UDF)
                    var.set(keys[i], el);
            }
            return null;
        }
        // DUMP
        // TODO component.setAccess(pc,Component.ACCESS_PUBLIC);
        String cdf = pc.getConfig().getComponentDumpTemplate();
        if (cdf != null && cdf.trim().length() > 0) {
            pc.variablesScope().set(KeyConstants._component, component);
            pc.doInclude(cdf, false);
        } else
            pc.write(pc.getConfig().getDefaultDumpWriter(DumpWriter.DEFAULT_RICH).toString(pc, component.toDumpData(pc, 9999, DumpUtil.toDumpProperties()), true));
    } catch (Throwable t) {
        // Exception Handler.castAnd Stack(t, this, pc);
        throw Caster.toPageException(t);
    }
    return null;
}
Also used : GatewayEngineImpl(lucee.runtime.gateway.GatewayEngineImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) Array(lucee.runtime.type.Array) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Scope(lucee.runtime.type.scope.Scope) UDF(lucee.runtime.type.UDF) Key(lucee.runtime.type.Collection.Key)

Aggregations

GatewayEngineImpl (lucee.runtime.gateway.GatewayEngineImpl)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 lucee.aprint (lucee.aprint)1 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)1 DumpWriterEntry (lucee.runtime.dump.DumpWriterEntry)1 GatewayEntry (lucee.runtime.gateway.GatewayEntry)1 GatewayEntryImpl (lucee.runtime.gateway.GatewayEntryImpl)1 Array (lucee.runtime.type.Array)1 Key (lucee.runtime.type.Collection.Key)1 UDF (lucee.runtime.type.UDF)1 Scope (lucee.runtime.type.scope.Scope)1 Element (org.w3c.dom.Element)1