Search in sources :

Example 86 with ApplicationException

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

the class CreateDynamicProxy method _call.

public static Object _call(PageContext pc, Object oCFC, Object oInterfaces) throws PageException, IOException {
    if (SystemUtil.getLoaderVersion() < 5.9D)
        throw new ApplicationException("You need to update your lucee.jar to execute the function [createDynamicProxy], you can download the latest jar from http://download.lucee.org.");
    // Component
    Component cfc;
    if (oCFC instanceof Component)
        cfc = (Component) oCFC;
    else
        cfc = pc.loadComponent(Caster.toString(oCFC));
    // string list to array
    if (Decision.isString(oInterfaces)) {
        String list = Caster.toString(oInterfaces);
        oInterfaces = ListUtil.listToStringArray(list, ',');
    }
    Class[] interfaces = null;
    if (Decision.isArray(oInterfaces)) {
        Object[] arr = Caster.toNativeArray(oInterfaces);
        ClassLoader cl = ((PageContextImpl) pc).getClassLoader();
        interfaces = new Class[arr.length];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] instanceof JavaObject)
                interfaces[i] = ((JavaObject) arr[i]).getClazz();
            else
                interfaces[i] = ClassUtil.loadClass(cl, Caster.toString(arr[i]));
        }
    // strInterfaces=ListUtil.toStringArray(Caster.toArray(oInterfaces));
    } else if (oInterfaces instanceof JavaObject) {
        interfaces = new Class[] { ((JavaObject) oInterfaces).getClazz() };
    } else
        throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "invalid type [" + Caster.toClassName(oInterfaces) + "] for class defintion");
    // check if all classes are interfaces
    for (int i = 0; i < interfaces.length; i++) {
        if (!interfaces[i].isInterface())
            throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "definition [" + interfaces[i].getClass() + "] is a class and not a interface");
    }
    return JavaProxyFactory.createProxy(pc, cfc, null, interfaces);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) JavaObject(lucee.runtime.java.JavaObject) FunctionException(lucee.runtime.exp.FunctionException) JavaObject(lucee.runtime.java.JavaObject) PageContextImpl(lucee.runtime.PageContextImpl) Component(lucee.runtime.Component)

Example 87 with ApplicationException

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

the class _GetSuperStaticScope method call.

public static Struct call(PageContext pc) throws PageException {
    Component cfc = pc.getActiveComponent();
    if (cfc == null)
        throw new ApplicationException("[static::] is not supported outside a component.");
    Component base = cfc.getBaseComponent();
    if (base == null)
        throw new ApplicationException("component [" + cfc.getCallName() + "] does not have a base component.");
    return base.staticScope();
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) Component(lucee.runtime.Component)

Example 88 with ApplicationException

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

the class ESAPIEncode method encode.

public static String encode(String item, short encFor, boolean canonicalize) throws PageException {
    if (StringUtil.isEmpty(item))
        return item;
    PrintStream out = System.out;
    try {
        System.setOut(new PrintStream(DevNullOutputStream.DEV_NULL_OUTPUT_STREAM));
        Encoder encoder = ESAPI.encoder();
        if (canonicalize)
            item = encoder.canonicalize(item, false);
        switch(encFor) {
            case ENC_CSS:
                return encoder.encodeForCSS(item);
            case ENC_DN:
                return encoder.encodeForDN(item);
            case ENC_HTML:
                return encoder.encodeForHTML(item);
            case ENC_HTML_ATTR:
                return encoder.encodeForHTMLAttribute(item);
            case ENC_JAVA_SCRIPT:
                return encoder.encodeForJavaScript(item);
            case ENC_LDAP:
                return encoder.encodeForLDAP(item);
            case ENC_URL:
                return encoder.encodeForURL(item);
            case ENC_VB_SCRIPT:
                return encoder.encodeForVBScript(item);
            case ENC_XML:
                return encoder.encodeForXML(item);
            case ENC_XML_ATTR:
                return encoder.encodeForXMLAttribute(item);
            case ENC_XPATH:
                return encoder.encodeForXPath(item);
        }
        throw new ApplicationException("invalid target encoding defintion");
    } catch (EncodingException ee) {
        throw Caster.toPageException(ee);
    } finally {
        System.setOut(out);
    }
}
Also used : PrintStream(java.io.PrintStream) ApplicationException(lucee.runtime.exp.ApplicationException) EncodingException(org.owasp.esapi.errors.EncodingException) Encoder(org.owasp.esapi.Encoder)

Example 89 with ApplicationException

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

the class RestSetResponse method call.

public static String call(PageContext pc, Struct rsp) throws ApplicationException {
    HttpServletRequest req = pc.getHttpServletRequest();
    Result result = (Result) req.getAttribute("rest-result");
    if (result == null)
        throw new ApplicationException("not inside a REST Request");
    result.setCustomResponse(rsp);
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationException(lucee.runtime.exp.ApplicationException) Result(lucee.runtime.rest.Result)

Example 90 with ApplicationException

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

the class DatasourceResourceProvider method getCore.

private Core getCore(ConnectionData data) throws PageException {
    Core core = (Core) cores.get(data.datasourceName);
    if (core == null) {
        DatasourceConnection dc = getManager().getConnection(ThreadLocalPageContext.get(), data.getDatasourceName(), data.getUsername(), data.getPassword());
        try {
            dc.getConnection().setAutoCommit(false);
            dc.getConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
            if ("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(dc.getDatasource().getClassDefinition().getClassName()))
                core = new MSSQL(dc, data.getPrefix());
            else if ("com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(dc.getDatasource().getClassDefinition().getClassName()))
                core = new MSSQL(dc, data.getPrefix());
            else if ("net.sourceforge.jtds.jdbc.Driver".equals(dc.getDatasource().getClassDefinition().getClassName()))
                core = new MSSQL(dc, data.getPrefix());
            else if ("org.gjt.mm.mysql.Driver".equals(dc.getDatasource().getClassDefinition().getClassName()))
                core = new MySQL(dc, data.getPrefix());
            else
                throw new ApplicationException("there is no DatasourceResource driver for this database [" + data.getPrefix() + "]");
            cores.put(data.datasourceName, core);
        } catch (SQLException e) {
            throw new DatabaseException(e, dc);
        } finally {
            release(dc);
        // manager.releaseConnection(CONNECTION_ID,dc);
        }
    }
    return core;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) DatasourceConnection(lucee.runtime.db.DatasourceConnection) SQLException(java.sql.SQLException) MySQL(lucee.commons.io.res.type.datasource.core.MySQL) MSSQL(lucee.commons.io.res.type.datasource.core.MSSQL) DatabaseException(lucee.runtime.exp.DatabaseException) Core(lucee.commons.io.res.type.datasource.core.Core)

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