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);
}
}
}
}
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);
}
}
}
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);
}
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;
}
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;
}
Aggregations