Search in sources :

Example 71 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class GenericHandler method doService.

/**
 * doService() is called by Dispatcher to perform web service.
 *
 * @return
 * @throws NavajoException
 * @throws UserException
 * @throws SystemException
 * @throws AuthorizationException
 */
@Override
public final Navajo doService(Access a) throws UserException, SystemException, AuthorizationException {
    if (a.isBreakWasSet()) {
        if (a.getOutputDoc() == null) {
            Navajo outDoc = NavajoFactory.getInstance().createNavajo();
            a.setOutputDoc(outDoc);
        }
        return a.getOutputDoc();
    }
    Navajo outDoc = null;
    StringBuilder compilerErrors = new StringBuilder();
    outDoc = NavajoFactory.getInstance().createNavajo();
    CompiledScriptInterface cso = null;
    try {
        cso = loadOnDemand(a, a.rpcName);
    } catch (Throwable e) {
        logger.error("Exception on getting compiledscript", e);
        if (e instanceof FileNotFoundException) {
            a.setExitCode(Access.EXIT_SCRIPT_NOT_FOUND);
        }
        throw new SystemException(-1, e.getMessage(), e);
    }
    try {
        if (cso == null) {
            if (Version.osgiActive()) {
                logger.warn("Script not found from OSGi registry while OSGi is active");
            }
            logger.error("No compiled script found, proceeding further is useless.");
            throw new RuntimeException("Can not resolve script: " + a.rpcName);
        }
        a.setOutputDoc(outDoc);
        a.setCompiledScript(cso);
        if (cso.getClassLoader() == null) {
            logger.error("No classloader present!");
        }
        cso.run(a);
        return a.getOutputDoc();
    } catch (Throwable e) {
        if (e instanceof com.dexels.navajo.mapping.BreakEvent) {
            // Outdoc might have been changed by running script
            outDoc = a.getOutputDoc();
            // Create dummy header to set breakwasset attribute.
            Header h = NavajoFactory.getInstance().createHeader(outDoc, "", "", "", -1);
            outDoc.addHeader(h);
            outDoc.getHeader().setHeaderAttribute("breakwasset", "true");
            return outDoc;
        } else if (e instanceof com.dexels.navajo.server.ConditionErrorException) {
            return ((com.dexels.navajo.server.ConditionErrorException) e).getNavajo();
        } else if (e instanceof UserException) {
            throw (UserException) e;
        }
        throw new SystemException(-1, e.getMessage(), e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Navajo(com.dexels.navajo.document.Navajo) CompiledScriptInterface(com.dexels.navajo.script.api.CompiledScriptInterface) SystemException(com.dexels.navajo.script.api.SystemException) Header(com.dexels.navajo.document.Header) UserException(com.dexels.navajo.script.api.UserException)

Example 72 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class BinaryStoreAdapter method store.

@Override
public void store() throws MappableException, UserException {
    if (value != null) {
        BinaryStore os = BinaryStoreFactory.getInstance().getBinaryStore(resource, tenant);
        if (os == null) {
            logger.warn("Can not find swift resource: {} for tenant: {}", resource, tenant);
            throw new UserException(-1, "Can not find binary store resource");
        }
        os.store(this.value);
    }
}
Also used : BinaryStore(com.dexels.navajo.resource.binarystore.BinaryStore) UserException(com.dexels.navajo.script.api.UserException)

Example 73 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class TwitterAdapter method getSignPost.

public Binary getSignPost() throws UserException {
    if (mySignPost != null) {
        Binary b = new Binary();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(b.getOutputStream());
            oos.writeObject(mySignPost);
            oos.close();
        } catch (Exception e) {
            throw new UserException(-1, e.getMessage(), e);
        }
        return b;
    } else {
        throw new UserException(-1, "Signpost not set.");
    }
}
Also used : Binary(com.dexels.navajo.document.types.Binary) UserException(com.dexels.navajo.script.api.UserException) ObjectOutputStream(java.io.ObjectOutputStream) UserException(com.dexels.navajo.script.api.UserException) TwitterException(winterwell.jtwitter.TwitterException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 74 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class JDBCMap method createConnection.

protected final void createConnection() throws SQLException, UserException {
    if (this.debug) {
        Access.writeToConsole(myAccess, this.getClass() + ": in createConnection()\n");
    }
    if (transactionContext != -1) {
        con = JdbcResourceComponent.getInstance().getJdbc(transactionContext);
        if (con == null) {
            throw new UserException(-1, "Invalid transaction context set: " + transactionContext);
        }
        // Make sure to set connection id.
        this.connectionId = transactionContext;
    }
    if (con == null) {
        if (this.debug) {
            Access.writeToConsole(myAccess, "in createConnection() for datasource " + datasource);
        }
        DataSource jdbc = JdbcResourceComponent.getJdbc(datasource);
        con = jdbc.getConnection();
        setDbIdentifier(con);
        if (this.username != null) {
            String query = "ALTER SESSION SET CURRENT_SCHEMA = " + username;
            if (this.dbIdentifier.equals(SQLMapConstants.POSTGRESDB)) {
                query = "SET SEARCH_PATH TO " + username;
            }
            PreparedStatement ps = con.prepareStatement(query);
            ps.executeUpdate();
            ps.close();
            logger.info("Username set to: {}", this.username);
        }
        if (con == null) {
            AuditLog.log("SQLMap", "Could (still) not connect to database: " + datasource + ", check your connection", Level.SEVERE);
            throw new UserException(-1, "Could not connect to database: " + datasource + " ()" + ", check your connection");
        } else {
            if (this.debug) {
                Access.writeToConsole(myAccess, this.getClass() + ": returned a good connection from the broker manager\n");
            }
        }
        this.transactionContext = con.hashCode();
        logger.info(":::Creating transactioncontext: {}", transactionContext);
        this.ownContext = true;
        JdbcResourceComponent.getInstance().registerTransaction(con.hashCode(), con);
        this.connectionId = con.hashCode();
        if (this.debug) {
            Access.writeToConsole(myAccess, this.getClass() + ": put connection no. " + this.connectionId + " into the connection map\n");
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) UserException(com.dexels.navajo.script.api.UserException) DataSource(javax.sql.DataSource)

Example 75 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class JDBCMap method getDBResultSet.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.dexels.navajo.adapter.JDBCMappable#getDBResultSet(boolean)
	 */
@Override
public final ResultSet getDBResultSet(boolean updateOnly) throws SQLException, UserException {
    createConnection();
    if (con == null) {
        AuditLog.log("SQLMap", "Could not connect to database: " + datasource + ", check your connection", Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
        throw new UserException(-1, "in SQLMap. Could not open database connection']");
    }
    if (debug) {
        Access.writeToConsole(myAccess, "SQLMAP, GOT CONNECTION, STARTING QUERY\n");
    }
    if (updateOnly && ((this.query == null) || (this.query.length() == 0)) && (this.update != null) && (this.update.indexOf(SQLBatchUpdateHelper.DELIMITER) >= 0)) {
        if (this.debug) {
            Access.writeToConsole(myAccess, this.getClass() + ": detected batch mode, trying a batch update\n");
        }
        SQLBatchUpdateHelper helper = new SQLBatchUpdateHelper(this.update, this.con, this.parameters, this.myAccess, this.dbIdentifier, this, this.isLegacyMode, this.debug, updateOnly);
        this.updateCount = helper.getUpdateCount();
        return (helper.getResultSet());
    }
    if (debug) {
        Access.writeToConsole(myAccess, "BEFORE PREPARESTATEMENT()\n");
    }
    // Check for open statement.
    if (this.statement != null) {
        try {
            this.statement.close();
        } catch (Exception e) {
        }
        this.statement = null;
    }
    if (query != null) {
        this.statement = con.prepareStatement(query);
    } else {
        this.statement = con.prepareStatement(update);
    }
    if (debug) {
        Access.writeToConsole(myAccess, "AFTER PREPARESTATEMENT(), SETTING MAXROWS...\n");
    }
    if (debug) {
        Access.writeToConsole(myAccess, "SET MAXROWS DONE..SETTING STATEMENT PARAMETERS\n");
    }
    setStatementParameters(statement);
    ResultSet rs = null;
    if (updateOnly) {
        this.statement.executeUpdate();
    } else {
        if (debug) {
            Access.writeToConsole(myAccess, "CALLING EXECUTEQUERY()\n");
        }
        rs = this.statement.executeQuery();
        if (debug) {
            Access.writeToConsole(myAccess, "GOT RESULTSET!!!!!\n");
        }
    }
    this.updateCount = this.statement.getUpdateCount();
    // dump any SQL warnings
    if (debug) {
        SQLWarning warning = this.statement.getWarnings();
        while (warning != null) {
            Access.writeToConsole(myAccess, "SQL warning: " + warning.getMessage() + "\n");
            warning = warning.getNextWarning();
        }
    }
    return rs;
}
Also used : SQLWarning(java.sql.SQLWarning) SQLBatchUpdateHelper(com.dexels.navajo.adapter.sqlmap.SQLBatchUpdateHelper) ResultSet(java.sql.ResultSet) UserException(com.dexels.navajo.script.api.UserException) UserException(com.dexels.navajo.script.api.UserException) SQLException(java.sql.SQLException) MappableException(com.dexels.navajo.script.api.MappableException) IOException(java.io.IOException)

Aggregations

UserException (com.dexels.navajo.script.api.UserException)113 MappableException (com.dexels.navajo.script.api.MappableException)54 IOException (java.io.IOException)33 NavajoException (com.dexels.navajo.document.NavajoException)25 Message (com.dexels.navajo.document.Message)22 SQLException (java.sql.SQLException)19 SystemException (com.dexels.navajo.script.api.SystemException)18 Binary (com.dexels.navajo.document.types.Binary)14 ConditionErrorException (com.dexels.navajo.server.ConditionErrorException)13 Property (com.dexels.navajo.document.Property)12 ArrayList (java.util.ArrayList)12 Navajo (com.dexels.navajo.document.Navajo)11 AuthorizationException (com.dexels.navajo.script.api.AuthorizationException)11 ResultSet (java.sql.ResultSet)11 MappingException (com.dexels.navajo.script.api.MappingException)10 ResultSetMetaData (java.sql.ResultSetMetaData)9 Element (org.w3c.dom.Element)8 CompilationException (com.dexels.navajo.script.api.CompilationException)7 File (java.io.File)7 NodeList (org.w3c.dom.NodeList)7