use of com.dexels.navajo.script.api.SystemException in project navajo by Dexels.
the class EvaluateExpression method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 1 && getOperands().size() != 3) {
throw new TMLExpressionException("Wrong number of arguments");
}
Navajo currentNavajo = this.getNavajo();
Message currentMessage = this.getCurrentMessage();
Operand result = null;
boolean conditional = (this.getOperands().size() == 3);
if (!conditional) {
String expression = (String) getOperand(0);
try {
result = Expression.evaluate(expression, currentNavajo, null, currentMessage, null, null, null, null);
} catch (TMLExpressionException ex) {
logger.error("Error: ", ex);
}
} else {
String condition = (String) getOperand(0);
String exp1 = (String) getOperand(1);
String exp2 = (String) getOperand(2);
try {
if (Condition.evaluate(condition, currentNavajo, null, currentMessage, getAccess())) {
result = Expression.evaluate(exp1, currentNavajo, null, currentMessage, null, null, null, null);
} else {
result = Expression.evaluate(exp2, currentNavajo, null, currentMessage, null, null, null, null);
}
} catch (SystemException ex1) {
logger.error("Error: ", ex1);
throw new TMLExpressionException(this, ex1.getMessage());
} catch (TMLExpressionException ex1) {
logger.error("Error: ", ex1);
throw new TMLExpressionException(this, ex1.getMessage());
}
}
if (result != null) {
return result.value;
} else {
return null;
}
}
use of com.dexels.navajo.script.api.SystemException in project navajo by Dexels.
the class RESTAdapter method setDoSend.
public void setDoSend(String url, Navajo od) throws UserException, ConditionErrorException, SystemException {
this.url = url.trim();
if (dateFormat != null && !dateFormat.equals("")) {
json.setDateFormat(new SimpleDateFormat(dateFormat));
}
Writer w = new StringWriter();
Binary bContent = new Binary();
if (textContent == null) {
// Remove globals and parms message
if (od.getMessage("__globals__") != null)
od.removeMessage("__globals__");
if (od.getMessage(Message.MSG_PARAMETERS_BLOCK) != null)
od.removeMessage(Message.MSG_PARAMETERS_BLOCK);
if (od.getMessage(Message.MSG_TOKEN_BLOCK) != null)
od.removeMessage(Message.MSG_TOKEN_BLOCK);
if (od.getMessage(Message.MSG_AAA_BLOCK) != null)
od.removeMessage(Message.MSG_AAA_BLOCK);
try {
json.format(od, w, true);
bContent.getOutputStream().write(w.toString().getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
logger.error("Exception on parsing input navajo as JSON! Not performing REST call!");
throw new UserException(e.getMessage(), e);
}
} else {
try {
bContent.getOutputStream().write(textContent.toString().getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
logger.error("IOException on writing textcontent! Not performing REST call!");
throw new UserException(e.getMessage(), e);
}
}
HTTPMap http = new HTTPMap();
setupHttpMap(http, bContent);
http.setDoSend(true);
Binary result = http.getResult();
responseCode = http.getResponseCode();
responseMessage = http.getResponseMessage();
try {
if (result == null) {
throw new UserException(-1, "Null result");
}
if (responseCode >= 300) {
logger.warn("Got a non-200 response code: {}!", responseCode);
if (breakOnException) {
throw new UserException(responseCode, responseMessage);
}
}
rawResult = new String(result.getData());
if (jsonResponse) {
if (http.getResponseContentType() != null && http.getResponseContentType().contains("application/json")) {
try {
inDoc = json.parse(result.getDataAsStream(), topMessage);
} catch (Throwable t) {
logger.warn("Unable to parse response as JSON!", t);
if (breakOnException) {
throw t;
}
}
} else if (http.getResponseContentType() == null) {
logger.info("No response content type - creating empty navajo as response");
inDoc = NavajoFactory.getInstance().createNavajo();
} else {
logger.warn("Unexpected output content type: {}", http.getResponseContentType());
if (breakOnException) {
throw new UserException(-1, "Unexpected content type: " + http.getResponseContentType());
}
}
} else {
logger.debug("Non-json response - creating empty Navajo");
inDoc = NavajoFactory.getInstance().createNavajo();
}
} catch (Throwable e) {
logger.error("Exception on getting response", e);
if (breakOnException) {
logger.warn("Raw response data: {}", rawResult);
throw new UserException(e.getMessage(), e);
} else {
logger.warn("Exception on getting response, but breakOnException was set. Continuing!");
}
}
if (inDoc == null) {
logger.warn("No indoc - creating empty one");
inDoc = NavajoFactory.getInstance().createNavajo();
}
}
use of com.dexels.navajo.script.api.SystemException in project navajo by Dexels.
the class NavajoMap method setDoSend.
/**
* Use this method to call another Navajo webservice. If server is not specified, the Navajo server that is used to handle this request is also used to
* handle the new request.
*
* @param method
* @throws UserException
*/
public void setDoSend(String method, Navajo od) throws UserException, ConditionErrorException, SystemException {
if (serviceCalled) {
logger.warn("DO NOT USE A NAVAJOMAP TO CALL A SECOND WEBSERVICE, USE NEW NAVAJOMAP INSTEAD");
}
// Reset current msgPointer when performing new doSend.
msgPointer = null;
setMethod(method);
this.outDoc = od;
this.username = (username == null) ? this.access.rpcUser : username;
this.password = (password == null) ? this.access.rpcPwd : password;
this.method = method;
if (password == null)
password = "";
try {
if (this.resource != null) {
serviceCalled = true;
AsyncClient ac = NavajoClientResourceManager.getInstance().getAsyncClient(this.resource);
if (ac == null) {
throw new UserException(-1, "No external resource found for: " + this.resource);
}
ac.callService(outDoc, method, this);
} else if (server != null) {
// External request.
try {
ManualAsyncClient ac = AsyncClientFactory.getManualInstance();
if (ac == null) {
logger.warn("unable to find async client - cannot perform navajomap call!");
throw new UserException(-1, "AsyncClient null");
}
String server = this.server.startsWith("http") ? this.server : "http://" + this.server;
Integer timeout = null;
if (serverTimeout > -1) {
timeout = serverTimeout;
}
ac.callService(server, username, password, outDoc, method, this, timeout);
} catch (Exception e) {
throw new UserException(-1, e.getMessage(), e);
}
serviceCalled = true;
} else // Internal request.
{
inDoc = null;
serviceFinished = false;
if (block) {
this.run();
} else {
SchedulerRegistry.submit(this, lowPriority);
}
serviceCalled = true;
if (getException() != null) {
if (getException() instanceof ConditionErrorException) {
throw (ConditionErrorException) getException();
} else if (getException() instanceof UserException) {
throw (UserException) getException();
} else if (getException() instanceof SystemException) {
throw (SystemException) getException();
} else {
throw new SystemException(-1, "", getException());
}
}
}
} catch (NavajoException | IOException e) {
throw new SystemException("Error connecting to remote server", e);
}
}
Aggregations