Search in sources :

Example 16 with NavajoException

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

the class TmlHttpServlet method sendResponse.

private static void sendResponse(HttpServletRequest request, HttpServletResponse response, Navajo resultMessage) {
    ServletOutputStream outputStream = null;
    try {
        String dataPath = request.getParameter("dataPath");
        outputStream = response.getOutputStream();
        if (dataPath != null) {
            Property bin = resultMessage.getProperty(dataPath);
            if (bin == null) {
                java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
                response.setContentType("text/xml; charset=UTF-8");
                resultMessage.write(out);
                out.flush();
                out.close();
            } else {
                // Will throw cce when not a binary?
                if (bin.getTypedValue() instanceof Binary) {
                    Binary b = (Binary) bin.getTypedValue();
                    response.setContentType(b.getMimeType());
                    if (b.getLength() > 0) {
                        response.setContentLength((int) b.getLength());
                        response.setHeader("Accept-Ranges", "none");
                        response.setHeader("Connection", "close");
                    }
                    copyResource(outputStream, b.getDataAsStream());
                } else {
                    outputStream.write(bin.getValue().getBytes());
                }
                outputStream.flush();
            }
        } else {
            java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
            response.setContentType("text/xml; charset=UTF-8");
            resultMessage.write(out);
            out.flush();
            out.close();
        }
    } catch (NavajoException e) {
        logger.error("Error handling response: ", e);
    } catch (IOException e) {
        logger.error("Error handling response: ", e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                logger.warn("Stream closing problem", e);
            }
        }
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) NavajoException(com.dexels.navajo.document.NavajoException) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException) Property(com.dexels.navajo.document.Property)

Example 17 with NavajoException

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

the class Access method setInDoc.

public void setInDoc(Navajo in) {
    if (in == null) {
        return;
    }
    this.inDoc = in;
    if (in.getHeader() != null) {
        // Check for parent access id header.
        String s = in.getHeader().getHeaderAttribute("parentaccessid");
        if (s != null && !s.equals("")) {
            setParentAccessId(s);
        }
    }
    // Check if __parms__ exists.
    Message msg = inDoc.getMessage("__parms__");
    if (msg == null) {
        msg = NavajoFactory.getInstance().createMessage(inDoc, "__parms__");
        try {
            inDoc.addMessage(msg);
        } catch (NavajoException e) {
            logger.error("Error: ", e);
        }
    }
}
Also used : Message(com.dexels.navajo.document.Message) NavajoException(com.dexels.navajo.document.NavajoException)

Example 18 with NavajoException

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

the class ITAsyncClient method testAsync.

@Test
@Ignore
public void testAsync() throws Exception {
    final ManualAsyncClient ac = new AsyncClientImpl();
    String service = "club/InitUpdateClub";
    System.err.println(TestConfig.NAVAJO_TEST_SERVER.getValue());
    ac.setServer(TestConfig.NAVAJO_TEST_SERVER.getValue());
    ac.setUsername(TestConfig.NAVAJO_TEST_USER.getValue());
    ac.setPassword(TestConfig.NAVAJO_TEST_PASS.getValue());
    Navajo input = NavajoFactory.getInstance().createNavajo();
    final NavajoResponseHandler showOutput = new NavajoResponseHandler() {

        @Override
        public void onResponse(Navajo n) {
            logger.info("Navajo finished!");
            try {
                StringWriter sw = new StringWriter();
                n.write(sw);
                logger.info("Response2 : {}", sw);
            } catch (NavajoException e) {
                logger.error("Error: ", e);
            }
        }

        @Override
        public void onFail(Throwable t) {
            logger.error("whoops: ", t);
        }

        @Override
        public Throwable getCaughtException() {
            return null;
        }
    };
    for (int i = 0; i < 10; i++) {
        ac.callService(input, service, showOutput);
        logger.info("Exchange sent");
    }
    Thread.sleep(10000);
}
Also used : ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) StringWriter(java.io.StringWriter) NavajoException(com.dexels.navajo.document.NavajoException) NavajoResponseHandler(com.dexels.navajo.client.NavajoResponseHandler) Navajo(com.dexels.navajo.document.Navajo) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with NavajoException

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

the class Exists method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    /**
     *@todo Implement this com.dexels.navajo.parser.FunctionInterface abstract method
     */
    Message arrayMessage = null;
    String messagePath = null;
    if (getOperand(0) instanceof Message) {
        arrayMessage = (Message) getOperand(0);
    } else {
        messagePath = (String) getOperand(0);
    }
    String expression = (String) getOperand(1);
    String filter = null;
    if (getOperands().size() > 2) {
        filter = (String) getOperand(2);
    }
    Message parent = getCurrentMessage();
    Navajo doc = getNavajo();
    // try {
    try {
        List<Message> arrayMsg = null;
        if (arrayMessage != null) {
            arrayMsg = arrayMessage.getAllMessages();
        } else {
            arrayMsg = (parent != null ? parent.getMessages(messagePath) : doc.getMessages(messagePath));
        }
        if (arrayMsg == null) {
            throw new TMLExpressionException(this, "Empty or non existing array message: " + messagePath);
        }
        for (int i = 0; i < arrayMsg.size(); i++) {
            Message current = arrayMsg.get(i);
            try {
                boolean evaluate = (filter != null ? Condition.evaluate(filter, doc, null, current, getAccess()) : true);
                if (evaluate) {
                    Operand result = Expression.evaluate(expression, doc, null, current);
                    if (result == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
                    }
                    if (result.value == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
                    }
                    String res2 = "" + result.value;
                    Operand result2 = Expression.evaluate(res2, doc, null, current);
                    if (result2 == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
                    }
                    if (result2.value == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
                    }
                    boolean res = ((Boolean) result2.value).booleanValue();
                    if (res) {
                        return Boolean.TRUE;
                    }
                }
            } catch (SystemException ex) {
                logger.error("Error: ", ex);
            }
        }
    } catch (NavajoException ex) {
        throw new TMLExpressionException(this, "Error evaluating message path");
    }
    return Boolean.FALSE;
}
Also used : Message(com.dexels.navajo.document.Message) SystemException(com.dexels.navajo.script.api.SystemException) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 20 with NavajoException

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

the class ExistsSelectionValue method evaluate.

@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() != 2) {
        throw new TMLExpressionException(this, "Invalid function call, need two parameters");
    }
    Object o = getOperand(0);
    if (o == null) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter null");
    }
    Object v = getOperand(1);
    if (v == null) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: Second parameter null");
    }
    if (!(v instanceof String)) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: Second parameter not a string");
    }
    if (o instanceof Property) {
        Property p = (Property) o;
        try {
            Selection s = p.getSelectionByValue((String) v);
            return !s.getValue().equals(Selection.DUMMY_ELEMENT);
        } catch (NavajoException ne) {
            throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter not a selection property");
        }
    }
    if (!(o instanceof List)) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter not a selection property");
    }
    List<Selection> l = (List<Selection>) o;
    for (Selection selection : l) {
        if (v.equals(selection.getValue())) {
            return true;
        }
    }
    return false;
}
Also used : Selection(com.dexels.navajo.document.Selection) NavajoException(com.dexels.navajo.document.NavajoException) List(java.util.List) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

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