Search in sources :

Example 41 with NavajoException

use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.

the class NavajoMap method prepareOutDoc.

protected Navajo prepareOutDoc() throws UserException {
    // If currentOutDoc flag was set, make sure to copy outdoc.
    if (this.useCurrentOutDoc || this.useCurrentMessages != null) {
        if (this.useCurrentOutDoc) {
            if (this.outDoc != null) {
                this.outDoc.merge(access.getOutputDoc().copy(), true);
            } else {
                this.outDoc = access.getOutputDoc().copy();
            }
        } else {
            String[] copy = useCurrentMessages.split(",");
            for (String msgName : copy) {
                Message msg = null;
                if ((msg = access.getOutputDoc().getMessage(msgName)) != null) {
                    if (this.outDoc.getMessage(msg.getName()) != null) {
                        this.outDoc.getMessage(msg.getName()).merge(msg, true);
                    } else {
                        this.outDoc.addMessage(msg);
                    }
                } else {
                    throw new UserException(-1, "Could not find message specified in useCurrentMessages: " + msgName);
                }
            }
        }
    }
    if (this.copyInputMessages != null) {
        String[] copy = copyInputMessages.split(",");
        for (String msgName : copy) {
            Message msg = null;
            if ((msg = access.getInDoc().getMessage(msgName)) != null) {
                if (this.outDoc.getMessage(msg.getName()) != null) {
                    this.outDoc.getMessage(msg.getName()).merge(msg, true);
                } else {
                    this.outDoc.addMessage(msg);
                }
            } else {
                throw new UserException(-1, "Could not find message specified in copyInputMessages: " + msgName);
            }
        }
    }
    if (this.useCurrentOutDoc) {
        // Copy param messages.
        if (inMessage.getMessage("__parms__") != null) {
            Message params = inMessage.getMessage("__parms__").copy(outDoc);
            try {
                outDoc.addMessage(params);
            } catch (NavajoException e) {
                e.printStackTrace(Access.getConsoleWriter(access));
            }
        }
        // Check for deleted messages.
        if (!deletedMessages.isEmpty()) {
            for (String dMn : deletedMessages) {
                Message dM = outDoc.getMessage(dMn);
                if (dM != null) {
                    Navajo rN = dM.getRootDoc();
                    rN.removeMessage(dMn);
                }
            }
        }
        // Check for deleted properties.
        if (!deletedProperties.isEmpty()) {
            for (String dPn : deletedProperties) {
                if (dPn != null) {
                    Property dP = outDoc.getProperty(dPn);
                    if (dP != null) {
                        Message dm = dP.getParentMessage();
                        dm.removeProperty(dP);
                    }
                }
            }
        }
    }
    if (this.sendThrough) {
        // Check for request messages with scope "local": remove those.
        for (Message m : access.getInDoc().getAllMessages()) {
            if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_LOCAL)) {
                if (outDoc.getMessage(m.getName()) != null) {
                    outDoc.removeMessage(m.getName());
                }
            }
        }
    }
    if (this.useCurrentOutDoc) {
        // Check for request messages with scope "local": remove those.
        for (Message m : access.getOutputDoc().getAllMessages()) {
            if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_LOCAL)) {
                if (outDoc.getMessage(m.getName()) != null) {
                    outDoc.removeMessage(m.getName());
                }
            }
        }
    }
    if (!this.sendThrough) {
        // Check for request messages with scope "global": add those.
        for (Message m : access.getInDoc().getAllMessages()) {
            if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_GLOBAL)) {
                if (outDoc.getMessage(m.getName()) != null) {
                    // Set preferthis flag to true to make sure that changes
                    // made in script are preferred over properties/messages
                    // already in global message.
                    outDoc.getMessage(m.getName()).merge(m.copy(outDoc), true);
                } else {
                    outDoc.addMessage(m.copy(outDoc));
                }
            }
        }
    }
    if (!this.useCurrentOutDoc) {
        // Check for response messages with scope "local": remove those.
        for (Message m : access.getOutputDoc().getAllMessages()) {
            if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_GLOBAL)) {
                if (outDoc.getMessage(m.getName()) != null) {
                    // Set preferthis flag to true to make sure that changes
                    // made in script are preferred over properties/messages
                    // already in global message.
                    outDoc.getMessage(m.getName()).merge(m.copy(outDoc), true);
                } else {
                    outDoc.addMessage(m.copy(outDoc));
                }
            }
            if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_LOCAL)) {
                if (outDoc.getMessage(m.getName()) != null) {
                    outDoc.removeMessage(m.getName());
                }
            }
        }
    }
    // Always copy globals.
    if (inMessage.getMessage("__globals__") != null) {
        Message globals = inMessage.getMessage("__globals__").copy(outDoc);
        try {
            outDoc.addMessage(globals);
        } catch (NavajoException e) {
            e.printStackTrace(Access.getConsoleWriter(access));
        }
    }
    // Always copy aaa message
    if (inMessage.getMessage(Message.MSG_AAA_BLOCK) != null) {
        Message aaa = inMessage.getMessage(Message.MSG_AAA_BLOCK).copy(outDoc);
        if (outDoc.getMessage(Message.MSG_AAA_BLOCK) != null) {
            outDoc.getMessage(Message.MSG_AAA_BLOCK).merge(aaa, true);
        } else {
            try {
                outDoc.addMessage(aaa);
            } catch (NavajoException e) {
                e.printStackTrace(Access.getConsoleWriter(access));
            }
        }
    }
    // Always copy token message if the user hasn't specified otherwise
    if (inMessage.getMessage(Message.MSG_TOKEN_BLOCK) != null && !this.dropTokenMessage) {
        Message token = inMessage.getMessage(Message.MSG_TOKEN_BLOCK).copy(outDoc);
        if (outDoc.getMessage(Message.MSG_TOKEN_BLOCK) != null) {
            outDoc.getMessage(Message.MSG_TOKEN_BLOCK).merge(token, true);
        } else {
            try {
                outDoc.addMessage(token);
            } catch (NavajoException e) {
                e.printStackTrace(Access.getConsoleWriter(access));
            }
        }
    }
    return outDoc;
}
Also used : Message(com.dexels.navajo.document.Message) NavajoException(com.dexels.navajo.document.NavajoException) UserException(com.dexels.navajo.script.api.UserException) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 42 with NavajoException

use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.

the class MessageMap method setRemoveSource.

public void setRemoveSource(boolean b) throws UserException {
    this.removeSource = b;
    Message m1 = null;
    Message m2 = null;
    if (this.joinMessage1 != null) {
        m1 = checkMessage(joinMessage1);
    }
    if (this.joinMessage2 != null) {
        m2 = checkMessage(joinMessage2);
    }
    if (removeSource) {
        if (myAccess.getCurrentOutMessage() == null) {
            try {
                myAccess.getOutputDoc().removeMessage(m1);
                if (m2 != null) {
                    myAccess.getOutputDoc().removeMessage(m2);
                }
            } catch (NavajoException ne) {
            }
        } else {
            if (m1.getParentMessage() != null) {
                m1.getParentMessage().removeMessage(m1);
            } else {
                myAccess.getOutputDoc().removeMessage(m1);
            }
            myAccess.getCurrentOutMessage().removeMessage(m1);
            if (m2 != null) {
                if (m2.getParentMessage() != null) {
                    m2.getParentMessage().removeMessage(m2);
                } else {
                    myAccess.getOutputDoc().removeMessage(m2);
                }
            }
        }
    }
}
Also used : Message(com.dexels.navajo.document.Message) ResultMessage(com.dexels.navajo.adapter.messagemap.ResultMessage) NavajoException(com.dexels.navajo.document.NavajoException)

Example 43 with NavajoException

use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.

the class SQLMap method setReload.

/**
 * @param reload
 */
@Deprecated
public void setReload(String datasourceName) throws MappableException, UserException {
    if (Version.osgiActive()) {
        // this method makes no sense in OSGi
        return;
    }
    // synchronized ( semaphore ) {
    if (debug) {
        Access.writeToConsole(myAccess, "SQLMAP setReload(" + datasourceName + ") called!\n");
    }
    try {
        synchronized (semaphore) {
            if (!initialized || !datasourceName.equals("")) {
                if (configFile == null) {
                    configFile = navajoConfig.readConfig("sqlmap.xml");
                    // SQLMap!!!
                    if (fixedBroker == null && datasourceName.equals("")) {
                        // Only
                        // re-create
                        // entire
                        // HashMap
                        // at
                        // initialization!
                        fixedBroker = new ConnectionBrokerManager();
                    }
                    if (datasourceName.equals("")) {
                        // Get other data sources.
                        if (configFile != null) {
                            List<Message> all = configFile.getMessages("/datasources/.*");
                            for (int i = 0; i < all.size(); i++) {
                                Message body = all.get(i);
                                createDataSource(body, navajoConfig);
                            }
                        } else {
                            logger.debug("No config file set. Normal in multitenant.");
                        }
                    } else {
                        createDataSource(configFile.getMessage("/datasources/" + datasourceName), navajoConfig);
                    }
                    this.checkDefaultDatasource();
                }
                initialized = true;
            }
        }
        rowCount = 0;
    } catch (NavajoException ne) {
        ne.printStackTrace(Access.getConsoleWriter(myAccess));
        AuditLog.log("SQLMap", ne.getMessage(), ne, Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
        throw new MappableException(ne.getMessage(), ne);
    } catch (java.io.IOException fnfe) {
        fnfe.printStackTrace(Access.getConsoleWriter(myAccess));
        AuditLog.log("SQLMap", fnfe.getMessage(), fnfe, Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
        throw new MappableException("Could not load configuration file for SQLMap object: " + fnfe.getMessage(), fnfe);
    } catch (Throwable t) {
        t.printStackTrace(Access.getConsoleWriter(myAccess));
        AuditLog.log("SQLMap", t.getMessage(), Level.SEVERE, (myAccess != null ? myAccess.accessID : ""));
        throw new MappableException(t.getMessage(), t);
    }
// }
}
Also used : MappableException(com.dexels.navajo.script.api.MappableException) Message(com.dexels.navajo.document.Message) ConnectionBrokerManager(com.dexels.navajo.adapter.sqlmap.ConnectionBrokerManager) NavajoException(com.dexels.navajo.document.NavajoException)

Example 44 with NavajoException

use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.

the class VersionedNavajoMap method setDoSend.

@Override
public void setDoSend(String method) throws UserException, ConditionErrorException, SystemException {
    super.setDoSend(method);
    logger.debug("in VersionedNavajoMap store()");
    if (!this.isEqual) {
        logger.debug("ABOUT TO CONSTRUCT MESSAGES!");
        try {
            Navajo currentOutDoc = super.access.getOutputDoc();
            Message confirm = NavajoFactory.getInstance().createMessage(currentOutDoc, "DataHasChanged");
            currentOutDoc.addMessage(confirm);
            Property b = NavajoFactory.getInstance().createProperty(currentOutDoc, "Overwrite", Property.BOOLEAN_PROPERTY, "false", 1, "", Property.DIR_IN);
            confirm.addProperty(b);
            List<Method> allMethods = inMessage.getAllMethods();
            for (int i = 0; i < allMethods.size(); i++) {
                Method m = allMethods.get(i);
                logger.debug("Adding method: {}", m.getName());
                Method a = NavajoFactory.getInstance().createMethod(currentOutDoc, m.getName(), "");
                List<String> required = m.getRequiredMessages();
                for (int j = 0; j < required.size(); j++) {
                    String name = required.get(j);
                    logger.debug("Adding required message: {}", name);
                    a.addRequired(name);
                }
                currentOutDoc.addMethod(a);
            }
            List<Message> allMessages = inMessage.getAllMessages();
            for (int i = 0; i < allMessages.size(); i++) {
                Message m = allMessages.get(i);
                logger.debug("Adding message: " + m.getName());
                Message a = inMessage.copyMessage(m, currentOutDoc);
                currentOutDoc.addMessage(a);
            }
        } catch (NavajoException ne) {
            throw new UserException(-1, ne.getMessage(), ne);
        }
    }
}
Also used : Message(com.dexels.navajo.document.Message) NavajoException(com.dexels.navajo.document.NavajoException) Navajo(com.dexels.navajo.document.Navajo) Method(com.dexels.navajo.document.Method) UserException(com.dexels.navajo.script.api.UserException) Property(com.dexels.navajo.document.Property)

Example 45 with NavajoException

use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.

the class RestTmlServlet method callDirect.

private final void callDirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String service = request.getParameter("service");
    // String type = request.getParameter("type");
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    logger.info(">in callDirect(): service = " + service + ", username = " + username + " class: " + getClass().getName());
    if (service == null) {
        // logger.info("Empty service specified, request originating from "
        // + request.getRemoteHost());
        logger.info("thread = " + Thread.currentThread().hashCode());
        logger.info("path = " + request.getPathInfo());
        logger.info("query = " + request.getQueryString());
        logger.info("protocol = " + request.getProtocol());
        logger.info("agent = " + request.getRemoteUser());
        logger.info("uri = " + request.getRequestURI());
        logger.info("method = " + request.getMethod());
        logger.info("contenttype = " + request.getContentType());
        logger.info("scheme = " + request.getScheme());
        logger.info("server = " + request.getServerName());
        logger.info("port = " + request.getServerPort());
        logger.info("contentlength = " + request.getContentLength());
        Enumeration<String> enm = request.getHeaderNames();
        while (enm.hasMoreElements()) {
            String key = enm.nextElement();
            String header = request.getHeader(key);
            logger.info(">>" + key + "=" + header);
        }
        return;
    }
    Navajo tbMessage;
    try {
        tbMessage = constructFromRequest(request);
        Header header = constructHeader(tbMessage, service, username, password, -1);
        tbMessage.addHeader(header);
        LocalClient lc = (LocalClient) getServletContext().getAttribute("localClient");
        if (lc == null) {
            response.sendError(500, "No navajocontext configured (in NavajoFilterServlet)");
            return;
        }
        Navajo resultMessage = lc.call(tbMessage);
        response.setContentType("text/xml");
        ServletOutputStream outputStream = response.getOutputStream();
        java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
        response.setContentType("text/xml; charset=UTF-8");
        writeOutput(resultMessage, out, service);
        // resultMessage.write(out);
        out.flush();
        out.close();
    } catch (NavajoException e) {
        logger.error("Error: ", e);
    } catch (FatalException e) {
        logger.error("Error: ", e);
    }
}
Also used : Header(com.dexels.navajo.document.Header) ServletOutputStream(javax.servlet.ServletOutputStream) FatalException(com.dexels.navajo.script.api.FatalException) LocalClient(com.dexels.navajo.script.api.LocalClient) NavajoException(com.dexels.navajo.document.NavajoException) Navajo(com.dexels.navajo.document.Navajo)

Aggregations

NavajoException (com.dexels.navajo.document.NavajoException)46 Message (com.dexels.navajo.document.Message)28 Property (com.dexels.navajo.document.Property)25 Navajo (com.dexels.navajo.document.Navajo)21 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)12 SystemException (com.dexels.navajo.script.api.SystemException)9 Operand (com.dexels.navajo.document.Operand)8 UserException (com.dexels.navajo.script.api.UserException)8 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)6 Selection (com.dexels.navajo.document.Selection)5 MappableException (com.dexels.navajo.script.api.MappableException)5 ArrayList (java.util.ArrayList)4 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)3 ManualAsyncClient (com.dexels.navajo.client.async.ManualAsyncClient)3 FatalException (com.dexels.navajo.script.api.FatalException)3 File (java.io.File)3 ClientException (com.dexels.navajo.client.ClientException)2 NavajoResponseHandler (com.dexels.navajo.client.NavajoResponseHandler)2 Header (com.dexels.navajo.document.Header)2