Search in sources :

Example 21 with UserException

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

the class SFTPMap method send.

private void send() throws UserException {
    // String SFTPWORKINGDIR = "file/to/transfer";
    Session session = null;
    Channel channel = null;
    ChannelSftp channelSftp = null;
    logger.debug("preparing the host information for sftp.");
    InputStream data = null;
    try {
        JSch jsch = new JSch();
        session = jsch.getSession(this.username, this.server, this.remotePort);
        if (this.password != null) {
            session.setPassword(this.password);
        }
        java.util.Properties config = new java.util.Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.connect();
        logger.debug("Host connected.");
        channel = session.openChannel("sftp");
        channel.connect();
        logger.debug("sftp channel opened and connected.");
        channelSftp = (ChannelSftp) channel;
        if (this.path != null) {
            channelSftp.cd(this.path);
        }
        File f = new File(this.filename);
        data = content.getDataAsStream();
        channelSftp.put(data, f.getName());
        logger.info("File transfered successfully to host.");
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new UserException("SFTP problem", ex);
    } finally {
        if (data != null) {
            try {
                data.close();
            } catch (IOException e) {
            }
        }
        if (channelSftp != null) {
            channelSftp.exit();
        }
        logger.info("sftp Channel exited.");
        if (channel != null) {
            channel.disconnect();
        }
        logger.info("Channel disconnected.");
        if (session != null) {
            session.disconnect();
        }
        logger.info("Host Session disconnected.");
    }
}
Also used : InputStream(java.io.InputStream) Channel(com.jcraft.jsch.Channel) IOException(java.io.IOException) JSch(com.jcraft.jsch.JSch) IOException(java.io.IOException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) ChannelSftp(com.jcraft.jsch.ChannelSftp) UserException(com.dexels.navajo.script.api.UserException) File(java.io.File) Session(com.jcraft.jsch.Session)

Example 22 with UserException

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

the class TslPreCompiler method getAllDependencies.

public void getAllDependencies(File script, String scriptFolder, List<Dependency> deps, String scriptTenant) throws XPathExpressionException, UserException {
    Document tslDoc = null;
    InputStream is = null;
    try {
        if (script.getAbsolutePath().endsWith(".ns")) {
            // Check for NS3 type script
            NS3ToNSXML ns3toxml = new NS3ToNSXML();
            ns3toxml.initialize();
            String content = ns3toxml.read(script.getAbsolutePath());
            InputStream metais = ns3toxml.parseNavascript(content);
            MapMetaData mmd = MapMetaData.getInstance();
            String intermed = mmd.parse(script.getAbsolutePath(), metais);
            metais.close();
            is = new ByteArrayInputStream(intermed.getBytes());
        } else if (MapMetaData.isMetaScript(script.getAbsolutePath())) {
            // Check for navascript type script
            MapMetaData mmd = MapMetaData.getInstance();
            InputStream metais = inputStreamReader.getResource(script.getAbsolutePath());
            String intermed = mmd.parse(script.getAbsolutePath(), metais);
            metais.close();
            is = new ByteArrayInputStream(intermed.getBytes());
        } else {
            // Normal tsl type script
            is = inputStreamReader.getResource(script.getAbsolutePath());
        }
        tslDoc = XMLDocumentUtils.createDocument(is, false);
    } catch (Exception e) {
        throw new UserException(-1, "Exception on pre-compiling script: " + script, e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                logger.error("Error: ", e);
            }
        }
    }
    getAllDependencies(script.getAbsolutePath(), scriptTenant, scriptFolder, deps, tslDoc);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NS3ToNSXML(com.dexels.navajo.mapping.compiler.navascript.NS3ToNSXML) UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException) Document(org.w3c.dom.Document) MapMetaData(com.dexels.navajo.mapping.compiler.meta.MapMetaData) XPathExpressionException(javax.xml.xpath.XPathExpressionException) UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException)

Example 23 with UserException

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

the class TslPreCompiler method findIncludeDependencies.

private void findIncludeDependencies(String fullScriptPath, String scriptTenant, String scriptFolder, List<Dependency> deps, Document tslDoc) throws UserException {
    NodeList includes = tslDoc.getElementsByTagName("include");
    for (int i = 0; i < includes.getLength(); i++) {
        Element n = (Element) includes.item(i);
        String includedScript = n.getAttribute("script");
        if (includedScript == null || includedScript.equals("")) {
            throw new UserException(-1, "No script name found in include tag (missing or empty script attribute): " + n);
        }
        if (scriptTenant != null) {
            // trying tenant-specific variant first
            String includeScriptFile = fetchScriptFileName(scriptFolder + File.separator + includedScript + "_" + scriptTenant);
            // Check if exists
            if (includeScriptFile != null) {
                deps.add(new Dependency(fullScriptPath, includeScriptFile, Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
                // Thus continue with next include
                continue;
            }
        }
        String includeScriptFile = fetchScriptFileName(scriptFolder + File.separator + includedScript);
        // Check if exists
        boolean isBroken = false;
        if (includeScriptFile == null) {
            isBroken = true;
            includeScriptFile = scriptFolder + File.separator + includedScript + ".broken";
        }
        if (includeScriptFile.equals(fullScriptPath)) {
            throw new UserException(-1, "Cannot include myself!");
        }
        deps.add(new Dependency(fullScriptPath, includeScriptFile, Dependency.INCLUDE_DEPENDENCY, getLineNr(n), isBroken));
        // Going to check for tenant-specific include-variants
        if (scriptTenant == null) {
            File scriptFolderFile = new File(includeScriptFile).getParentFile();
            if (scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
                AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(includedScript) + "_*.xml");
                Collection<File> files = FileUtils.listFiles(scriptFolderFile, fileFilter, null);
                for (File f : files) {
                    deps.add(new Dependency(fullScriptPath, f.getAbsolutePath(), Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
                }
                // NS3
                AbstractFileFilter fileFilterNS3 = new WildcardFileFilter(FilenameUtils.getName(includedScript) + "_*.xml");
                Collection<File> filesNS3 = FileUtils.listFiles(scriptFolderFile, fileFilterNS3, null);
                for (File f : filesNS3) {
                    deps.add(new Dependency(fullScriptPath, f.getAbsolutePath(), Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) UserException(com.dexels.navajo.script.api.UserException) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) AbstractFileFilter(org.apache.commons.io.filefilter.AbstractFileFilter)

Example 24 with UserException

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

the class JDBCMap method setQuery.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.dexels.navajo.adapter.JDBCMappable#setQuery(java.lang.String)
	 */
@Override
public void setQuery(final String newQuery) throws UserException {
    if (newQuery.indexOf(';') != -1) {
        throw new UserException(-1, "Use of semicolon in query fields is not allowed, maybe you meant to use an update field?");
    }
    query = newQuery.replace('"', (this.replaceQueryDoubleQuotes) ? '\'' : '\"');
    if (debug) {
        Access.writeToConsole(myAccess, "SQLMap(): query = " + query + "\n");
    }
    this.savedQuery = query;
    this.resultSet = null;
    this.update = null;
    parameters = new ArrayList();
}
Also used : ArrayList(java.util.ArrayList) UserException(com.dexels.navajo.script.api.UserException)

Example 25 with UserException

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

the class JDBCMap method getResultSet.

protected ResultSetMap[] getResultSet(boolean updateOnly) throws UserException {
    ResultSet rs = null;
    try {
        if (resultSet == null) {
            rs = getDBResultSet(updateOnly);
        }
        if (debug) {
            Access.writeToConsole(myAccess, "SQLMAP, QUERY HAS BEEN EXECUTED, RETRIEVING RESULTSET\n");
        }
        if (rs != null) {
            int columns = 0;
            ResultSetMetaData meta = null;
            try {
                meta = rs.getMetaData();
                columns = meta.getColumnCount();
            } catch (Exception e) {
                throw new UserException(-1, "Error retrieving metadata / columncount", e);
            }
            List<ResultSetMap> dummy = new ArrayList<>();
            int index = 1;
            rowCount = 0;
            try {
                while (rs.next()) {
                    ResultSetMap rm = new ResultSetMap();
                    for (int i = 1; i < (columns + 1); i++) {
                        String param = meta.getColumnLabel(i);
                        int type = meta.getColumnType(i);
                        Object value = null;
                        final Object strVal = rs.getObject(i);
                        if ((strVal != null && !rs.wasNull()) || type == Types.BLOB) {
                            value = SQLMapHelper.getColumnValue(rs, type, i);
                        }
                        rm.addValue(param.toUpperCase(), value);
                    }
                    dummy.add(rm);
                }
                rowCount++;
                index++;
            } catch (Exception e) {
                if (debug) {
                    Access.writeToConsole(myAccess, "batch mode did not provide a fully baked result set, sorry.\n");
                    Access.writeToConsole(myAccess, "SQL exception is '" + e.toString() + "'\n");
                    logger.warn("Some sql problem: ", e);
                }
                rs.close();
                rs = null;
                resetAll();
            }
            if (debug) {
                Access.writeToConsole(myAccess, "GOT RESULTSET. Size: " + dummy.size() + " indexcounter says: " + index + "\n");
            }
            resultSet = dummy.toArray(new ResultSetMap[] {});
            rowCount = resultSet.length;
        }
    } catch (SQLException sqle) {
        logger.error("SQL Problem: ");
        AuditLog.log("SQLMap", sqle.getMessage(), Level.SEVERE, (myAccess != null ? (myAccess != null ? myAccess.accessID : "unknown access") : "unknown access"));
        throw new UserException(-1, sqle.getMessage(), sqle);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
                e.printStackTrace(Access.getConsoleWriter(myAccess));
            }
            rs = null;
        }
        this.resetAll();
    }
    return resultSet;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ResultSetMap(com.dexels.navajo.adapter.sqlmap.ResultSetMap) ArrayList(java.util.ArrayList) 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