use of com.dexels.navajo.article.APIException in project navajo by Dexels.
the class ServletArticleRuntimeImpl method resolveArgument.
@Override
public String resolveArgument(String name) throws APIException {
final String trimmedName = name.substring(1);
String res = request.getParameter(trimmedName);
if (res != null) {
return res;
}
XMLElement args = article.getElementByTagName("_arguments");
if (args == null) {
throw new APIException("Unspecified parameter reference: " + name + ". No argument data found.", null, APIErrorCode.InternalError);
}
List<XMLElement> lts = args.getChildren();
for (XMLElement xmlElement : lts) {
if (trimmedName.equals(xmlElement.getStringAttribute("name"))) {
boolean optional = xmlElement.getBooleanAttribute("optional", "true", "false", false);
if (!optional) {
// not optional + no value = fail
throw new APIException("Missing parameter not optional: " + trimmedName, null, APIErrorCode.MissingRequiredArgument);
}
return xmlElement.getStringAttribute("default");
}
}
throw new APIException("Unspecified parameter reference: " + name + ". No argument data found.", null, APIErrorCode.InternalError);
}
use of com.dexels.navajo.article.APIException in project navajo by Dexels.
the class OAuthArticleServlet method doServiceImpl.
@Override
protected void doServiceImpl(HttpServletRequest req, HttpServletResponse resp) throws APIException {
String token = getToken(req);
OAuthToken oauthToken = null;
Client client = null;
if (token != null) {
oauthToken = getOAuthToken(token);
client = getClient(oauthToken);
} else {
client = getClient(req);
}
String username = client.getUsername();
if (oauthToken != null && oauthToken.getUsername() != null && !oauthToken.getUsername().equals("")) {
username = oauthToken.getUsername();
}
String pathInfo = req.getPathInfo();
String instance = client.getInstance();
if (pathInfo == null) {
throw new APIException("Pathinfo is null, we cannot find an article then", null, APIErrorCode.ArticleNotFound);
}
String articleName = determineArticleFromRequest(req);
File article = getContext().resolveArticle(articleName);
if (!article.exists()) {
throw new APIException("Article does not exist", null, APIErrorCode.ArticleNotFound);
}
try {
String ip = req.getHeader("X-Forwarded-For");
if (ip == null || ip.equals("")) {
ip = req.getRemoteAddr();
}
Access access = new Access(-1, -1, username, ACCESS_PREFIX + articleName, "", "", "", null, false, null);
access.setTenant(instance);
access.rpcPwd = token;
access.created = new Date();
access.ipAddress = ip;
access.setClientDescription("Article");
access.setClientToken("Client id: " + client.getId());
ArticleRuntime runtime = new ServletArticleRuntimeImpl(req, resp, "", username, article, pathInfo, req.getParameterMap(), instance, oauthToken);
runtime.setAccess(access);
runtime.setUsername(username);
ArticleTmlRunnable runner = new ArticleTmlRunnable(req, resp, client, runtime, getContext(), requestTimeout);
if (!runner.isAborted()) {
tmlScheduler.submit(runner, false);
}
} catch (Throwable e) {
throw new APIException(e.getMessage(), e, APIErrorCode.InternalError);
}
}
use of com.dexels.navajo.article.APIException 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.article.APIException in project navajo by Dexels.
the class ArticleListServlet method doServiceImpl.
protected void doServiceImpl(HttpServletRequest request, HttpServletResponse response) throws APIException {
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = mapper.createObjectNode();
boolean extended = request.getParameter(ARGUMENT_EXTENDED) != null ? true : false;
String requestedArticle = request.getParameter(ARGUMENT_ARTICLE);
ObjectWriter writer = mapper.writer().withDefaultPrettyPrinter();
if (requestedArticle != null) {
getContext().writeArticleMeta(requestedArticle, rootNode, mapper, extended);
} else {
List<String> articles = getContext().listArticles();
for (String article : articles) {
getContext().writeArticleMeta(article, rootNode, mapper, extended);
}
}
try (PrintWriter pw = response.getWriter()) {
writer.writeValue(pw, rootNode);
} catch (IOException e) {
throw new APIException("Autoclose on printwriter failed", e, APIErrorCode.InternalError);
}
}
use of com.dexels.navajo.article.APIException in project navajo by Dexels.
the class BaseRuntimeImpl method getGroupNode.
public ObjectNode getGroupNode(ObjectNode parent, String name) throws APIException {
JsonNode existing = parent.get(name);
if (existing != null) {
if (existing instanceof ObjectNode) {
return (ObjectNode) existing;
} else {
throw new APIException("Error getting group node: " + name + " there is an existing node, but it is not an ObjectNode", null, APIErrorCode.InternalError);
}
}
ObjectNode result = mapper.createObjectNode();
rootNode.set(name, result);
return result;
}
Aggregations