use of com.dexels.navajo.server.ConditionErrorException in project navajo by Dexels.
the class CompiledScript method run.
/*
* (non-Javadoc)
*
* @see
* com.dexels.navajo.script.api.CompiledScriptInterface#run(com.dexels.navajo
* .api.Access)
*/
@Override
public final void run(Access access) throws Exception {
myAccess = access;
long start = System.currentTimeMillis();
try {
dumpRequest();
setValidations();
currentParamMsg = access.getInDoc().getMessage("__parms__");
ConditionData[] conditions = getValidationRules(access);
boolean conditionsFailed = false;
if (conditions != null && conditions.length > 0) {
Navajo outMessage = access.getOutputDoc();
Message[] failed = checkValidationRules(conditions, access.getInDoc(), outMessage, access);
if (failed != null) {
conditionsFailed = true;
access.setExitCode(Access.EXIT_VALIDATION_ERR);
Message msg = NavajoFactory.getInstance().createMessage(outMessage, "ConditionErrors");
outMessage.addMessage(msg);
msg.setType(Message.MSG_TYPE_ARRAY);
for (int i = 0; i < failed.length; i++) {
msg.addMessage(failed[i]);
}
}
}
if (!conditionsFailed) {
try {
execute(access);
access.setExitCode(Access.EXIT_OK);
} catch (com.dexels.navajo.mapping.BreakEvent be) {
access.setExitCode(Access.EXIT_BREAK);
throw be;
} catch (UserException e) {
access.setExitCode(Access.EXIT_USEREXCEPTION);
throw e;
} catch (ConditionErrorException e) {
access.setExitCode(Access.EXIT_VALIDATION_ERR);
throw e;
} catch (Exception e) {
access.setExitCode(Access.EXIT_EXCEPTION);
throw e;
} finally {
finalBlock(access);
}
}
} finally {
dumpResponse();
// Release acquired locks.
for (Lock l : acquiredLocks) {
try {
l.unlock();
} catch (Throwable t) {
}
}
acquiredLocks.clear();
access.processingTime = (int) (System.currentTimeMillis() - start);
}
}
use of com.dexels.navajo.server.ConditionErrorException in project navajo by Dexels.
the class ServiceCommand method handleError.
private void handleError(Navajo result) throws UserException, AuthorizationException, ConditionErrorException {
Message error = result.getMessage("error");
if (error != null) {
String errMsg = error.getProperty("message").getValue();
String errCode = error.getProperty("code").getValue();
int errorCode = -1;
try {
errorCode = Integer.parseInt(errCode);
} catch (NumberFormatException e) {
logger.error("Error: ", e);
}
throw new UserException(errorCode, errMsg);
}
boolean authenticationError = false;
Message aaaError = result.getMessage(AuthorizationException.AUTHENTICATION_ERROR_MESSAGE);
if (aaaError == null) {
aaaError = result.getMessage(AuthorizationException.AUTHORIZATION_ERROR_MESSAGE);
} else {
authenticationError = true;
}
if (aaaError != null) {
throw new AuthorizationException(authenticationError, !authenticationError, aaaError.getProperty("User").getValue(), aaaError.getProperty("Message").getValue());
}
if (result.getMessage("ConditionErrors") != null) {
throw new ConditionErrorException(result);
}
}
use of com.dexels.navajo.server.ConditionErrorException in project navajo by Dexels.
the class ServiceCommand method performCall.
protected Navajo performCall(ArticleRuntime runtime, String name, Navajo n, String instance) throws APIException {
try {
Navajo result = dispatcher.handle(n, instance, true);
handleError(result);
return result;
} catch (UserException | AuthorizationException | FatalException e) {
throw new APIException(e.getMessage(), e, APIErrorCode.InternalError);
} catch (ConditionErrorException e) {
throw new APIException(e.getMessage(), e, APIErrorCode.ConditionError);
}
}
use of com.dexels.navajo.server.ConditionErrorException 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.server.ConditionErrorException 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