Search in sources :

Example 46 with Message

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

the class Dispatcher method generateErrorMessage.

/**
 * Generate a Navajo error message and log the error to the Database.
 */
@Override
public final Navajo generateErrorMessage(Access access, String message, int code, int level, Throwable t) throws FatalException {
    if (message == null) {
        message = "Null pointer exception";
    }
    if (t != null) {
        logger.error("Generating error message for: ", t);
    }
    try {
        Navajo outMessage = NavajoFactory.getInstance().createNavajo();
        // Make sure empty Header is constructed
        Header h = NavajoFactory.getInstance().createHeader(outMessage, "", "", "", -1);
        outMessage.addHeader(h);
        Message errorMessage = NavajoFactory.getInstance().createMessage(outMessage, Constants.ERROR_MESSAGE);
        outMessage.addMessage(errorMessage);
        Property prop = NavajoFactory.getInstance().createProperty(outMessage, "message", Property.STRING_PROPERTY, message, 200, "Message", Property.DIR_OUT);
        errorMessage.addProperty(prop);
        prop = NavajoFactory.getInstance().createProperty(outMessage, "code", Property.INTEGER_PROPERTY, code + "", 100, "Code", Property.DIR_OUT);
        errorMessage.addProperty(prop);
        prop = NavajoFactory.getInstance().createProperty(outMessage, "level", Property.INTEGER_PROPERTY, level + "", 100, "Level", Property.DIR_OUT);
        errorMessage.addProperty(prop);
        if (access != null) {
            prop = NavajoFactory.getInstance().createProperty(outMessage, "access_id", Property.STRING_PROPERTY, access.accessID + "", 100, "Access id", Property.DIR_OUT);
            errorMessage.addProperty(prop);
            access.setException(t);
        }
        if (access != null) {
            access.setOutputDoc(outMessage);
        }
        return outMessage;
    } catch (Exception e) {
        throw new FatalException(e.getMessage(), e);
    }
}
Also used : Header(com.dexels.navajo.document.Header) Message(com.dexels.navajo.document.Message) FatalException(com.dexels.navajo.script.api.FatalException) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) FatalException(com.dexels.navajo.script.api.FatalException) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) TriggerException(com.dexels.navajo.server.enterprise.scheduler.TriggerException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException)

Example 47 with Message

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

the class CachedDescriptionProvider method dumpCacheMessage.

public Message dumpCacheMessage(Navajo n) throws NavajoException {
    Message m = NavajoFactory.getInstance().createMessage(n, "Cache", Message.MSG_TYPE_ARRAY);
    for (Iterator<String> iter = cache.keySet().iterator(); iter.hasNext(); ) {
        String element = iter.next();
        String value = cache.get(element);
        Property keyProp = NavajoFactory.getInstance().createProperty(n, "Key", Property.STRING_PROPERTY, element, 521, "", Property.DIR_IN);
        Property valProp = NavajoFactory.getInstance().createProperty(n, "Value", Property.STRING_PROPERTY, value, 521, "", Property.DIR_IN);
        Message ii = NavajoFactory.getInstance().createMessage(n, "Cache", Message.MSG_TYPE_ARRAY_ELEMENT);
        m.addMessage(ii);
        ii.addProperty(keyProp);
        ii.addProperty(valProp);
    }
    return m;
}
Also used : Message(com.dexels.navajo.document.Message) Property(com.dexels.navajo.document.Property)

Example 48 with Message

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

the class PropertyFileDescriptionProvider method updatePropertyDescriptions.

@Override
public void updatePropertyDescriptions(Navajo in, Navajo out, Access access) {
    if (!enabled)
        return;
    try {
        String locale = in.getHeader().getHeaderAttribute("locale");
        if (locale == null) {
            return;
        }
        ResourceBundle properties;
        try {
            properties = this.getResourceBundle(in, access);
        } catch (IOException e) {
            logger.error("Exception getting resources", e);
            return;
        }
        for (Message message : out.getAllMessages()) {
            updateMessage(properties, message, access);
        }
    } catch (Throwable t) {
        logger.error("Exception in handling property descriptions", t);
    }
}
Also used : Message(com.dexels.navajo.document.Message) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException)

Example 49 with Message

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

the class Request method getThanksMessage.

/**
 * Generate a simple "feedback" message with only 1 property: "resultaat".
 */
public Navajo getThanksMessage(String what) throws NavajoException {
    // Create Navajo out message
    Navajo outMessage = NavajoFactory.getInstance().createNavajo();
    Message resultMessage = NavajoFactory.getInstance().createMessage(outMessage, "feedback");
    outMessage.addMessage(resultMessage);
    Property prop = NavajoFactory.getInstance().createProperty(outMessage, "resultaat", Property.STRING_PROPERTY, what, 1, "", Property.DIR_OUT);
    resultMessage.addProperty(prop);
    return outMessage;
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 50 with Message

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

the class Dispatcher method generateScheduledMessage.

private final Navajo generateScheduledMessage(Header h, String taskId, boolean rejected) {
    try {
        Navajo outMessage = NavajoFactory.getInstance().createNavajo();
        Header hnew = NavajoFactory.getInstance().createHeader(outMessage, h.getRPCName(), h.getRPCUser(), "", -1);
        if (!rejected) {
            hnew.setSchedule(taskId);
        } else {
            Message msg = NavajoFactory.getInstance().createMessage(outMessage, "Warning");
            outMessage.addMessage(msg);
            Property prop = NavajoFactory.getInstance().createProperty(outMessage, "Status", Property.STRING_PROPERTY, "TimeExpired", 32, "Created by generateScheduledMessage", Property.DIR_OUT);
            msg.addProperty(prop);
        }
        outMessage.addHeader(hnew);
        return outMessage;
    } catch (Exception e) {
        logger.error("Error: ", e);
        return null;
    }
}
Also used : Header(com.dexels.navajo.document.Header) Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) FatalException(com.dexels.navajo.script.api.FatalException) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) TriggerException(com.dexels.navajo.server.enterprise.scheduler.TriggerException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException)

Aggregations

Message (com.dexels.navajo.document.Message)312 Property (com.dexels.navajo.document.Property)149 Navajo (com.dexels.navajo.document.Navajo)127 Test (org.junit.Test)95 NavajoException (com.dexels.navajo.document.NavajoException)39 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)35 Access (com.dexels.navajo.script.api.Access)27 UserException (com.dexels.navajo.script.api.UserException)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 Selection (com.dexels.navajo.document.Selection)25 Operand (com.dexels.navajo.document.Operand)22 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)19 MappableException (com.dexels.navajo.script.api.MappableException)18 Ignore (org.junit.Ignore)17 SystemException (com.dexels.navajo.script.api.SystemException)16 Optional (java.util.Optional)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)13 HashMap (java.util.HashMap)13