Search in sources :

Example 1 with ApplicationContextSupport

use of lucee.runtime.listener.ApplicationContextSupport in project Lucee by lucee.

the class Axis1Client method _call.

private Object _call(PageContext pc, Config secondChanceConfig, String methodName, Struct namedArguments, Object[] arguments) throws PageException, ServiceException, RemoteException {
    ApplicationContextSupport acs = (ApplicationContextSupport) pc.getApplicationContext();
    javax.wsdl.Service service = getWSDLService();
    Service axisService = new Service(parser, service.getQName());
    axisService.setMaintainSession(acs.getWSMaintainSession());
    TypeMappingUtil.registerDefaults(axisService.getTypeMappingRegistry());
    Port port = WSUtil.getSoapPort(service);
    Binding binding = port.getBinding();
    SymbolTable symbolTable = parser.getSymbolTable();
    BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
    // get matching operation/method
    Iterator<Entry<Operation, Parameters>> itr = bEntry.getParameters().entrySet().iterator();
    Operation operation = null;
    Entry<Operation, Parameters> e;
    Parameters parameters = null;
    while (itr.hasNext()) {
        e = itr.next();
        if (e.getKey().getName().equalsIgnoreCase(methodName)) {
            operation = e.getKey();
            parameters = e.getValue();
            break;
        }
    }
    // no operation found!
    if (operation == null || parameters == null) {
        // get array of existing methods
        Set<Operation> set = bEntry.getParameters().keySet();
        Iterator<Operation> it = set.iterator();
        Collection.Key[] keys = new Collection.Key[set.size()];
        int index = 0;
        while (it.hasNext()) {
            keys[index++] = KeyImpl.init(it.next().getName());
        }
        throw new RPCException(ExceptionUtil.similarKeyMessage(keys, methodName, "method/operation", "methods/operations", null, true) + " Webservice: " + wsdlUrl);
    }
    org.apache.axis.client.Call call = (Call) axisService.createCall(QName.valueOf(port.getName()), QName.valueOf(operation.getName()));
    if (!StringUtil.isEmpty(username, true)) {
        call.setUsername(username);
        call.setPassword(password);
    }
    org.apache.axis.encoding.TypeMapping tm = call.getTypeMapping();
    Vector<String> inNames = new Vector<String>();
    Vector<Parameter> inTypes = new Vector<Parameter>();
    Vector<String> outNames = new Vector<String>();
    Vector<Parameter> outTypes = new Vector<Parameter>();
    Parameter p = null;
    for (int j = 0; j < parameters.list.size(); j++) {
        p = (Parameter) parameters.list.get(j);
        map(pc, symbolTable, secondChanceConfig, tm, p.getType());
        switch(p.getMode()) {
            case Parameter.IN:
                inNames.add(p.getQName().getLocalPart());
                inTypes.add(p);
                break;
            case Parameter.OUT:
                outNames.add(p.getQName().getLocalPart());
                outTypes.add(p);
                break;
            case Parameter.INOUT:
                inNames.add(p.getQName().getLocalPart());
                inTypes.add(p);
                outNames.add(p.getQName().getLocalPart());
                outTypes.add(p);
                break;
        }
    }
    // set output type
    if (parameters.returnParam != null) {
        QName rtnQName = parameters.returnParam.getQName();
        // TypeEntry rtnType = parameters.returnParam.getType();
        map(pc, symbolTable, secondChanceConfig, tm, parameters.returnParam.getType());
        outNames.add(rtnQName.getLocalPart());
        outTypes.add(parameters.returnParam);
    }
    // get timezone
    TimeZone tz;
    if (pc == null)
        tz = ThreadLocalPageContext.getTimeZone(secondChanceConfig);
    else
        tz = ThreadLocalPageContext.getTimeZone(pc);
    // check arguments
    Object[] inputs = new Object[inNames.size()];
    if (arguments != null) {
        if (inNames.size() != arguments.length)
            throw new RPCException("Invalid arguments count for operation " + methodName + " (" + arguments.length + " instead of " + inNames.size() + ")");
        for (int pos = 0; pos < inNames.size(); pos++) {
            p = inTypes.get(pos);
            inputs[pos] = getArgumentData(tm, tz, p, arguments[pos]);
        }
    } else {
        UDFUtil.argumentCollection(namedArguments);
        if (inNames.size() != namedArguments.size())
            throw new RPCException("Invalid arguments count for operation " + methodName + " (" + namedArguments.size() + " instead of " + inNames.size() + ")");
        Object arg;
        for (int pos = 0; pos < inNames.size(); pos++) {
            p = inTypes.get(pos);
            arg = namedArguments.get(KeyImpl.init(p.getName()), null);
            if (arg == null) {
                throw new RPCException("Invalid arguments for operation " + methodName, getErrorDetailForArguments(inNames.toArray(new String[inNames.size()]), CollectionUtil.keysAsString(namedArguments)));
            }
            inputs[pos] = getArgumentData(tm, tz, p, arg);
        }
    }
    Object ret = null;
    // add header
    if (headers != null && !headers.isEmpty()) {
        Iterator<SOAPHeaderElement> it = headers.iterator();
        while (it.hasNext()) {
            call.addHeader(it.next());
        }
    }
    try {
        ret = invoke(call, inputs);
    } catch (AxisFault af) {
        boolean rethrow = true;
        Throwable cause = af.getCause();
        if (cause != null) {
            /*
        		// first check if that missing type is around
        		String[] notFound=new String[]{"could not find deserializer for type","No deserializer for"};
        		int index;
        		if(msg!=null)for(int i=0; i<notFound.length;i++) {
        			if((index=msg.indexOf(notFound[i]))==-1)continue;;
        			
        			String raw=msg.substring(index+notFound[i].length()+1).trim();
        			QName qn = QName.valueOf(raw);
        			print.e(qn.getLocalPart());
        			print.e(qn.getNamespaceURI());
        			Type type = symbolTable.getType(qn);
        			if(type!=null) {
        				map(pc,secondChanceConfig,call.getTypeMapping(),type);
        				ret = invoke(call,inputs);
        				rethrow=false;
        			}
        		}*/
            // get the missing types from the SOAP Body, if possible
            String msg = cause.getMessage();
            // if(StringUtil.indexOfIgnoreCase(msg, "deserializer")!=-1) {
            try {
                InputSource is = new InputSource(new StringReader(call.getResponseMessage().getSOAPPartAsString()));
                Document doc = XMLUtil.parse(is, null, false);
                Element body = XMLUtil.getChildWithName("soapenv:Body", doc.getDocumentElement());
                Vector types = SOAPUtil.getTypes(body, symbolTable);
                map(pc, symbolTable, secondChanceConfig, (org.apache.axis.encoding.TypeMapping) (axisService.getTypeMappingRegistry().getDefaultTypeMapping()), types);
                ret = invoke(call, inputs);
                rethrow = false;
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        // }
        }
        if (rethrow)
            throw af;
    }
    last = call;
    if (outNames.size() <= 1)
        return AxisCaster.toLuceeType(null, ret);
    // getParamData((org.apache.axis.client.Call)call,parameters.returnParam,ret);
    Map outputs = call.getOutputParams();
    Struct sct = new StructImpl();
    for (int pos = 0; pos < outNames.size(); pos++) {
        String name = outNames.get(pos);
        // print.ln(name);
        Object value = outputs.get(name);
        if (value == null && pos == 0) {
            sct.setEL(name, AxisCaster.toLuceeType(null, ret));
        } else {
            sct.setEL(name, AxisCaster.toLuceeType(null, value));
        }
    }
    return sct;
}
Also used : AxisFault(org.apache.axis.AxisFault) InputSource(org.xml.sax.InputSource) Port(javax.wsdl.Port) SOAPHeaderElement(org.apache.axis.message.SOAPHeaderElement) Element(org.w3c.dom.Element) Call(org.apache.axis.client.Call) Operation(javax.wsdl.Operation) Document(org.w3c.dom.Document) Struct(lucee.runtime.type.Struct) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) Entry(java.util.Map.Entry) SymTabEntry(org.apache.axis.wsdl.symbolTable.SymTabEntry) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry) ServiceEntry(org.apache.axis.wsdl.symbolTable.ServiceEntry) RPCException(lucee.runtime.net.rpc.RPCException) StringReader(java.io.StringReader) Vector(java.util.Vector) Binding(javax.wsdl.Binding) SOAPHeaderElement(org.apache.axis.message.SOAPHeaderElement) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) Call(org.apache.axis.client.Call) Parameters(org.apache.axis.wsdl.symbolTable.Parameters) QName(javax.xml.namespace.QName) Service(org.apache.axis.client.Service) SymbolTable(org.apache.axis.wsdl.symbolTable.SymbolTable) TimeZone(java.util.TimeZone) StructImpl(lucee.runtime.type.StructImpl) Parameter(org.apache.axis.wsdl.symbolTable.Parameter) TypeMapping(javax.xml.rpc.encoding.TypeMapping) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) Map(java.util.Map) Key(lucee.runtime.type.Collection.Key)

Example 2 with ApplicationContextSupport

use of lucee.runtime.listener.ApplicationContextSupport in project Lucee by lucee.

the class PageContextImpl method getCacheConnection.

public CacheConnection getCacheConnection(String cacheName, CacheConnection defaultValue) {
    cacheName = cacheName.toLowerCase().trim();
    CacheConnection cc = null;
    if (getApplicationContext() != null)
        cc = ((ApplicationContextSupport) getApplicationContext()).getCacheConnection(cacheName, null);
    if (cc == null)
        cc = config.getCacheConnections().get(cacheName);
    if (cc == null)
        return defaultValue;
    return cc;
}
Also used : ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) CacheConnection(lucee.runtime.cache.CacheConnection)

Example 3 with ApplicationContextSupport

use of lucee.runtime.listener.ApplicationContextSupport in project Lucee by lucee.

the class GetApplicationSettings method call.

public static Struct call(PageContext pc, boolean suppressFunctions) {
    ApplicationContext ac = pc.getApplicationContext();
    Component cfc = null;
    if (ac instanceof ModernApplicationContext)
        cfc = ((ModernApplicationContext) ac).getComponent();
    Struct sct = new StructImpl();
    sct.setEL("applicationTimeout", ac.getApplicationTimeout());
    sct.setEL("clientManagement", Caster.toBoolean(ac.isSetClientManagement()));
    sct.setEL("clientStorage", ac.getClientstorage());
    sct.setEL("sessionStorage", ac.getSessionstorage());
    sct.setEL("customTagPaths", toArray(ac.getCustomTagMappings()));
    sct.setEL("loginStorage", AppListenerUtil.translateLoginStorage(ac.getLoginStorage()));
    sct.setEL(KeyConstants._mappings, toStruct(ac.getMappings()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("scriptProtect", AppListenerUtil.translateScriptProtect(ac.getScriptProtect()));
    sct.setEL("secureJson", Caster.toBoolean(ac.getSecureJson()));
    sct.setEL("typeChecking", Caster.toBoolean(ac.getTypeChecking()));
    sct.setEL("secureJsonPrefix", ac.getSecureJsonPrefix());
    sct.setEL("sessionManagement", Caster.toBoolean(ac.isSetSessionManagement()));
    sct.setEL("sessionTimeout", ac.getSessionTimeout());
    sct.setEL("clientTimeout", ac.getClientTimeout());
    sct.setEL("setClientCookies", Caster.toBoolean(ac.isSetClientCookies()));
    sct.setEL("setDomainCookies", Caster.toBoolean(ac.isSetDomainCookies()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("localMode", ac.getLocalMode() == Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS ? Boolean.TRUE : Boolean.FALSE);
    sct.setEL(KeyConstants._locale, LocaleFactory.toString(pc.getLocale()));
    sct.setEL(KeyConstants._timezone, TimeZoneUtil.toString(pc.getTimeZone()));
    // scope cascading
    sct.setEL("scopeCascading", ConfigWebUtil.toScopeCascading(ac.getScopeCascading(), null));
    if (ac.getScopeCascading() != Config.SCOPE_SMALL) {
        sct.setEL("searchImplicitScopes", ac.getScopeCascading() == Config.SCOPE_STANDARD);
    }
    Struct cs = new StructImpl();
    cs.setEL("web", pc.getWebCharset().name());
    cs.setEL("resource", ((PageContextImpl) pc).getResourceCharset().name());
    sct.setEL("charset", cs);
    sct.setEL("sessionType", AppListenerUtil.toSessionType(((PageContextImpl) pc).getSessionType(), "application"));
    // TODO impl
    sct.setEL("serverSideFormValidation", Boolean.FALSE);
    sct.setEL("clientCluster", Caster.toBoolean(ac.getClientCluster()));
    sct.setEL("sessionCluster", Caster.toBoolean(ac.getSessionCluster()));
    sct.setEL("invokeImplicitAccessor", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("triggerDataMember", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("sameformfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_FORM)));
    sct.setEL("sameurlfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_URL)));
    Object ds = ac.getDefDataSource();
    if (ds instanceof DataSource)
        ds = _call((DataSource) ds);
    else
        ds = Caster.toString(ds, null);
    sct.setEL(KeyConstants._datasource, ds);
    sct.setEL("defaultDatasource", ds);
    Resource src = ac.getSource();
    if (src != null)
        sct.setEL(KeyConstants._source, src.getAbsolutePath());
    // orm
    if (ac.isORMEnabled()) {
        ORMConfiguration conf = ac.getORMConfiguration();
        if (conf != null)
            sct.setEL(KeyConstants._orm, conf.toStruct());
    }
    // s3
    Properties props = ac.getS3();
    if (props != null) {
        sct.setEL(KeyConstants._s3, props.toStruct());
    }
    // ws settings
    {
        Struct wssettings = new StructImpl();
        wssettings.put(KeyConstants._type, AppListenerUtil.toWSType(ac.getWSType(), "Axis1"));
        sct.setEL("wssettings", wssettings);
    }
    // datasources
    Struct _sources = new StructImpl();
    sct.setEL(KeyConstants._datasources, _sources);
    DataSource[] sources = ac.getDataSources();
    if (!ArrayUtil.isEmpty(sources)) {
        for (int i = 0; i < sources.length; i++) {
            _sources.setEL(KeyImpl.init(sources[i].getName()), _call(sources[i]));
        }
    }
    // logs
    Struct _logs = new StructImpl();
    sct.setEL("logs", _logs);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Iterator<Key> it = acs.getLogNames().iterator();
        Key name;
        while (it.hasNext()) {
            name = it.next();
            _logs.setEL(name, acs.getLogMetaData(name.getString()));
        }
    }
    // mails
    Array _mails = new ArrayImpl();
    sct.setEL("mails", _mails);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Server[] servers = acs.getMailServers();
        Struct s;
        Server srv;
        if (servers != null) {
            for (int i = 0; i < servers.length; i++) {
                srv = servers[i];
                s = new StructImpl();
                _mails.appendEL(s);
                s.setEL(KeyConstants._host, srv.getHostName());
                s.setEL(KeyConstants._port, srv.getPort());
                if (!StringUtil.isEmpty(srv.getUsername()))
                    s.setEL(KeyConstants._username, srv.getUsername());
                if (!StringUtil.isEmpty(srv.getPassword()))
                    s.setEL(KeyConstants._password, srv.getPassword());
                s.setEL(KeyConstants._readonly, srv.isReadOnly());
                s.setEL("ssl", srv.isSSL());
                s.setEL("tls", srv.isTLS());
                if (srv instanceof ServerImpl) {
                    ServerImpl srvi = (ServerImpl) srv;
                    s.setEL("lifeTimespan", TimeSpanImpl.fromMillis(srvi.getLifeTimeSpan()));
                    s.setEL("idleTimespan", TimeSpanImpl.fromMillis(srvi.getIdleTimeSpan()));
                }
            }
        }
    }
    // tag
    Map<Key, Map<Collection.Key, Object>> tags = ac.getTagAttributeDefaultValues(pc);
    if (tags != null) {
        Struct tag = new StructImpl();
        Iterator<Entry<Key, Map<Collection.Key, Object>>> it = tags.entrySet().iterator();
        Entry<Collection.Key, Map<Collection.Key, Object>> e;
        Iterator<Entry<Collection.Key, Object>> iit;
        Entry<Collection.Key, Object> ee;
        Struct tmp;
        // TagLib lib = ((ConfigImpl)pc.getConfig()).getCoreTagLib();
        while (it.hasNext()) {
            e = it.next();
            iit = e.getValue().entrySet().iterator();
            tmp = new StructImpl();
            while (iit.hasNext()) {
                ee = iit.next();
                // lib.getTagByClassName(ee.getKey());
                tmp.setEL(ee.getKey(), ee.getValue());
            }
            tag.setEL(e.getKey(), tmp);
        }
        sct.setEL(KeyConstants._tag, tag);
    }
    // cache
    String fun = ac.getDefaultCacheName(Config.CACHE_TYPE_FUNCTION);
    String obj = ac.getDefaultCacheName(Config.CACHE_TYPE_OBJECT);
    String qry = ac.getDefaultCacheName(Config.CACHE_TYPE_QUERY);
    String res = ac.getDefaultCacheName(Config.CACHE_TYPE_RESOURCE);
    String tmp = ac.getDefaultCacheName(Config.CACHE_TYPE_TEMPLATE);
    String inc = ac.getDefaultCacheName(Config.CACHE_TYPE_INCLUDE);
    String htt = ac.getDefaultCacheName(Config.CACHE_TYPE_HTTP);
    String fil = ac.getDefaultCacheName(Config.CACHE_TYPE_FILE);
    String wse = ac.getDefaultCacheName(Config.CACHE_TYPE_WEBSERVICE);
    // cache connections
    Struct conns = new StructImpl();
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Key[] names = acs.getCacheConnectionNames();
        for (Key name : names) {
            CacheConnection data = acs.getCacheConnection(name.getString(), null);
            Struct _sct = new StructImpl();
            conns.setEL(name, _sct);
            _sct.setEL(KeyConstants._custom, data.getCustom());
            _sct.setEL(KeyConstants._storage, data.isStorage());
            ClassDefinition cd = data.getClassDefinition();
            if (cd != null) {
                _sct.setEL(KeyConstants._class, cd.getClassName());
                if (!StringUtil.isEmpty(cd.getName()))
                    _sct.setEL(KeyConstants._bundleName, cd.getClassName());
                if (cd.getVersion() != null)
                    _sct.setEL(KeyConstants._bundleVersion, cd.getVersionAsString());
            }
        }
    }
    if (!conns.isEmpty() || fun != null || obj != null || qry != null || res != null || tmp != null || inc != null || htt != null || fil != null || wse != null) {
        Struct cache = new StructImpl();
        sct.setEL(KeyConstants._cache, cache);
        if (fun != null)
            cache.setEL(KeyConstants._function, fun);
        if (obj != null)
            cache.setEL(KeyConstants._object, obj);
        if (qry != null)
            cache.setEL(KeyConstants._query, qry);
        if (res != null)
            cache.setEL(KeyConstants._resource, res);
        if (tmp != null)
            cache.setEL(KeyConstants._template, tmp);
        if (inc != null)
            cache.setEL(KeyConstants._include, inc);
        if (htt != null)
            cache.setEL(KeyConstants._http, htt);
        if (fil != null)
            cache.setEL(KeyConstants._file, fil);
        if (wse != null)
            cache.setEL(KeyConstants._webservice, wse);
        if (conns != null)
            cache.setEL(KeyConstants._connections, conns);
    }
    // java settings
    JavaSettings js = ac.getJavaSettings();
    StructImpl jsSct = new StructImpl();
    jsSct.put("loadCFMLClassPath", js.loadCFMLClassPath());
    jsSct.put("reloadOnChange", js.reloadOnChange());
    jsSct.put("watchInterval", new Double(js.watchInterval()));
    jsSct.put("watchExtensions", ListUtil.arrayToList(js.watchedExtensions(), ","));
    Resource[] reses = js.getResources();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < reses.length; i++) {
        if (i > 0)
            sb.append(',');
        sb.append(reses[i].getAbsolutePath());
    }
    jsSct.put("loadCFMLClassPath", sb.toString());
    sct.put("javaSettings", jsSct);
    if (cfc != null) {
        sct.setEL(KeyConstants._component, cfc.getPageSource().getDisplayPath());
        try {
            ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, cfc);
            Iterator<Key> it = cw.keyIterator();
            Collection.Key key;
            Object value;
            while (it.hasNext()) {
                key = it.next();
                value = cw.get(key);
                if (suppressFunctions && value instanceof UDF)
                    continue;
                if (!sct.containsKey(key))
                    sct.setEL(key, value);
            }
        } catch (PageException e) {
            SystemOut.printDate(e);
        }
    }
    return sct;
}
Also used : Server(lucee.runtime.net.mail.Server) ArrayImpl(lucee.runtime.type.ArrayImpl) Properties(lucee.runtime.net.s3.Properties) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) ApplicationContext(lucee.runtime.listener.ApplicationContext) Entry(java.util.Map.Entry) ServerImpl(lucee.runtime.net.mail.ServerImpl) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Component(lucee.runtime.Component) ORMConfiguration(lucee.runtime.orm.ORMConfiguration) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) PageException(lucee.runtime.exp.PageException) JavaSettings(lucee.runtime.listener.JavaSettings) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) DataSource(lucee.runtime.db.DataSource) Array(lucee.runtime.type.Array) Key(lucee.runtime.type.Collection.Key) StructImpl(lucee.runtime.type.StructImpl) Collection(lucee.runtime.type.Collection) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) Map(java.util.Map) CacheConnection(lucee.runtime.cache.CacheConnection) Key(lucee.runtime.type.Collection.Key)

Example 4 with ApplicationContextSupport

use of lucee.runtime.listener.ApplicationContextSupport in project Lucee by lucee.

the class Application method set.

private boolean set(ApplicationContext ac, boolean update) throws PageException {
    if (applicationTimeout != null)
        ac.setApplicationTimeout(applicationTimeout);
    if (sessionTimeout != null)
        ac.setSessionTimeout(sessionTimeout);
    if (clientTimeout != null)
        ac.setClientTimeout(clientTimeout);
    if (requestTimeout != null)
        ac.setRequestTimeout(requestTimeout);
    if (clientstorage != null) {
        ac.setClientstorage(clientstorage);
    }
    if (sessionstorage != null) {
        ac.setSessionstorage(sessionstorage);
    }
    if (customTagMappings != null)
        ac.setCustomTagMappings(customTagMappings);
    if (componentMappings != null)
        ac.setComponentMappings(componentMappings);
    if (mappings != null)
        ac.setMappings(mappings);
    if (loginstorage != Scope.SCOPE_UNDEFINED)
        ac.setLoginStorage(loginstorage);
    if (!StringUtil.isEmpty(datasource)) {
        ac.setDefDataSource(datasource);
        ac.setORMDataSource(datasource);
    }
    if (!StringUtil.isEmpty(defaultdatasource))
        ac.setDefDataSource(defaultdatasource);
    if (datasources != null) {
        try {
            ac.setDataSources(AppListenerUtil.toDataSources(pageContext.getConfig(), datasources, pageContext.getConfig().getLog("application")));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    if (logs != null) {
        try {
            ApplicationContextSupport acs = (ApplicationContextSupport) ac;
            acs.setLoggers(ApplicationContextSupport.initLog(logs));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    if (mails != null) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        try {
            acs.setMailServers(AppListenerUtil.toMailServers(pageContext.getConfig(), mails, null));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    if (caches != null) {
        try {
            ApplicationContextSupport acs = (ApplicationContextSupport) ac;
            Iterator<Entry<Key, Object>> it = caches.entryIterator();
            Entry<Key, Object> e;
            String name;
            Struct sct;
            while (it.hasNext()) {
                e = it.next();
                // default value by name
                if (!StringUtil.isEmpty(name = Caster.toString(e.getValue(), null))) {
                    setDefault(ac, e.getKey(), name);
                } else // cache definition
                if ((sct = Caster.toStruct(e.getValue(), null)) != null) {
                    CacheConnection cc = ModernApplicationContext.toCacheConnection(pageContext.getConfig(), e.getKey().getString(), sct);
                    if (cc != null) {
                        name = e.getKey().getString();
                        acs.setCacheConnection(name, cc);
                        // key is a cache type
                        setDefault(ac, e.getKey(), name);
                        // default key
                        Key def = Caster.toKey(sct.get(KeyConstants._default, null), null);
                        if (def != null)
                            setDefault(ac, def, name);
                    }
                }
            }
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    if (onmissingtemplate != null && ac instanceof ClassicApplicationContext) {
        ((ClassicApplicationContext) ac).setOnMissingTemplate(onmissingtemplate);
    }
    if (scriptrotect != null)
        ac.setScriptProtect(AppListenerUtil.translateScriptProtect(scriptrotect));
    if (bufferOutput != null)
        ac.setBufferOutput(bufferOutput.booleanValue());
    if (secureJson != null)
        ac.setSecureJson(secureJson.booleanValue());
    if (typeChecking != null)
        ac.setTypeChecking(typeChecking.booleanValue());
    if (suppress != null)
        ac.setSuppressContent(suppress.booleanValue());
    if (secureJsonPrefix != null)
        ac.setSecureJsonPrefix(secureJsonPrefix);
    if (setClientCookies != null)
        ac.setSetClientCookies(setClientCookies.booleanValue());
    if (setClientManagement != null)
        ac.setSetClientManagement(setClientManagement.booleanValue());
    if (setDomainCookies != null)
        ac.setSetDomainCookies(setDomainCookies.booleanValue());
    if (setSessionManagement != null)
        ac.setSetSessionManagement(setSessionManagement.booleanValue());
    if (localMode != -1)
        ac.setLocalMode(localMode);
    if (mailListener != null)
        ((ApplicationContextSupport) ac).setMailListener(mailListener);
    if (locale != null)
        ac.setLocale(locale);
    if (timeZone != null)
        ac.setTimeZone(timeZone);
    if (webCharset != null)
        ac.setWebCharset(webCharset.toCharset());
    if (resourceCharset != null)
        ac.setResourceCharset(resourceCharset.toCharset());
    if (sessionType != -1)
        ac.setSessionType(sessionType);
    if (wsType != -1)
        ac.setWSType(wsType);
    if (triggerDataMember != null)
        ac.setTriggerComponentDataMember(triggerDataMember.booleanValue());
    if (compression != null)
        ac.setAllowCompression(compression.booleanValue());
    if (cacheFunction != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_FUNCTION, cacheFunction);
    if (cacheObject != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_OBJECT, cacheObject);
    if (cacheQuery != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_QUERY, cacheQuery);
    if (cacheResource != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_RESOURCE, cacheResource);
    if (cacheTemplate != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_TEMPLATE, cacheTemplate);
    if (cacheInclude != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_INCLUDE, cacheInclude);
    if (cacheHTTP != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_HTTP, cacheHTTP);
    if (cacheFile != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_FILE, cacheFile);
    if (cacheWebservice != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_WEBSERVICE, cacheWebservice);
    if (antiSamyPolicyResource != null)
        ((ApplicationContextSupport) ac).setAntiSamyPolicyResource(antiSamyPolicyResource);
    if (sessionCookie != null) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        acs.setSessionCookie(sessionCookie);
    }
    if (authCookie != null) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        acs.setAuthCookie(authCookie);
    }
    if (tag != null)
        ac.setTagAttributeDefaultValues(pageContext, tag);
    ac.setClientCluster(clientCluster);
    ac.setSessionCluster(sessionCluster);
    ac.setCGIScopeReadonly(cgiReadOnly);
    if (s3 != null)
        ac.setS3(AppListenerUtil.toS3(s3));
    // Scope cascading
    if (scopeCascading != -1)
        ac.setScopeCascading(scopeCascading);
    // ORM
    boolean initORM = false;
    if (!update) {
        if (ormenabled == null)
            ormenabled = false;
        if (ormsettings == null)
            ormsettings = new StructImpl();
    }
    if (ormenabled != null)
        ac.setORMEnabled(ormenabled);
    if (ac.isORMEnabled()) {
        initORM = true;
        if (ormsettings != null)
            AppListenerUtil.setORMConfiguration(pageContext, ac, ormsettings);
    }
    return initORM;
}
Also used : ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) ClassicApplicationContext(lucee.runtime.listener.ClassicApplicationContext) PageException(lucee.runtime.exp.PageException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) Struct(lucee.runtime.type.Struct) Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) CacheConnection(lucee.runtime.cache.CacheConnection) Key(lucee.runtime.type.Collection.Key)

Example 5 with ApplicationContextSupport

use of lucee.runtime.listener.ApplicationContextSupport in project Lucee by lucee.

the class Cookie method doStartTag.

@Override
public int doStartTag() throws PageException {
    Key key = KeyImpl.getInstance(name);
    String appName = Login.getApplicationName(pageContext.getApplicationContext());
    boolean isAppName = false;
    if (KeyConstants._CFID.equalsIgnoreCase(key) || KeyConstants._CFTOKEN.equalsIgnoreCase(key) || (isAppName = key.equals(appName))) {
        ApplicationContext ac = pageContext.getApplicationContext();
        if (ac instanceof ApplicationContextSupport) {
            ApplicationContextSupport acs = (ApplicationContextSupport) ac;
            CookieData data = isAppName ? acs.getAuthCookie() : acs.getSessionCookie();
            if (data != null && data.isDisableUpdate())
                throw new ExpressionException("customize " + key + " is disabled!");
        }
    }
    pageContext.cookieScope().setCookie(key, value, expires, secure, path, domain, httponly, preservecase, encode);
    return SKIP_BODY;
}
Also used : CookieData(lucee.runtime.listener.CookieData) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) ApplicationContext(lucee.runtime.listener.ApplicationContext) Key(lucee.runtime.type.Collection.Key) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

ApplicationContextSupport (lucee.runtime.listener.ApplicationContextSupport)9 CacheConnection (lucee.runtime.cache.CacheConnection)4 ApplicationContext (lucee.runtime.listener.ApplicationContext)4 Key (lucee.runtime.type.Collection.Key)4 Entry (java.util.Map.Entry)3 Struct (lucee.runtime.type.Struct)3 StructImpl (lucee.runtime.type.StructImpl)3 Map (java.util.Map)2 Resource (lucee.commons.io.res.Resource)2 ExpressionException (lucee.runtime.exp.ExpressionException)2 PageException (lucee.runtime.exp.PageException)2 ClassicApplicationContext (lucee.runtime.listener.ClassicApplicationContext)2 TimeSpan (lucee.runtime.type.dt.TimeSpan)2 StringReader (java.io.StringReader)1 TimeZone (java.util.TimeZone)1 Vector (java.util.Vector)1 Tag (javax.servlet.jsp.tagext.Tag)1 Binding (javax.wsdl.Binding)1 Operation (javax.wsdl.Operation)1 Port (javax.wsdl.Port)1