use of com.dexels.navajo.article.NoJSONOutputException in project navajo by Dexels.
the class ArticleTmlRunnable method runInternal.
private void runInternal() throws APIException {
try {
runtime.getAccess().setQueueId(this.getRequestQueue().getId());
runtime.getAccess().queueTime = (int) (System.currentTimeMillis() - scheduledAt);
runtime.execute(context);
runtime.getAccess().setExitCode(Access.EXIT_OK);
} catch (NoJSONOutputException e) {
httpResponse.setContentType(e.getMimeType());
try {
IOUtils.copy(e.getStream(), httpResponse.getOutputStream());
} catch (IOException e1) {
throw new APIException(e1.getMessage(), e1, APIErrorCode.InternalError);
}
return;
} catch (APIException apiException) {
if (apiException.getErrorCode() == APIErrorCode.InternalError) {
logExceptionToAccess(runtime.getAccess(), apiException, createNavajoFromRequest(httpRequest));
} else if (apiException.getErrorCode() == APIErrorCode.ConditionError) {
runtime.getAccess().setExitCode(Access.EXIT_VALIDATION_ERR);
}
throw apiException;
} catch (Throwable e) {
logExceptionToAccess(runtime.getAccess(), e, createNavajoFromRequest(httpRequest));
throw new APIException(e.getMessage(), e, APIErrorCode.InternalError);
}
}
use of com.dexels.navajo.article.NoJSONOutputException in project navajo by Dexels.
the class ElementCommand method execute.
@Override
public JsonNode execute(ArticleRuntime runtime, ArticleContext context, Map<String, String> parameters, XMLElement element) throws APIException, NoJSONOutputException {
String service = parameters.get("service");
Navajo current = null;
if (service == null) {
current = runtime.getNavajo();
} else {
current = runtime.getNavajo(service);
}
if (current == null) {
throw new APIException("No current navajo found for service " + service, null, APIErrorCode.InternalError);
}
String name = parameters.get("name");
if (name == null) {
throw new APIException("No 'name' parameter found in element for service " + service + " we've got parameters " + parameters, null, APIErrorCode.InternalError);
}
String propertyName = parameters.get("propertyName");
if (propertyName == null) {
propertyName = name;
}
Property p = current.getProperty(propertyName);
if (p == null) {
throw new APIException("No property: " + propertyName + " found in current navajo for service " + service, null, APIErrorCode.InternalError);
}
if (parameters.get("direct") != null) {
Object value = p.getTypedValue();
if (value instanceof Binary) {
Binary b = (Binary) value;
String mime = b.getMimeType();
if (mime == null) {
mime = b.guessContentType();
}
throw new NoJSONOutputException(mime, b.getDataAsStream());
} else {
String string = "" + value;
ByteArrayInputStream bais = new ByteArrayInputStream(string.getBytes());
throw new NoJSONOutputException("text/plain", bais);
}
}
if (name.indexOf('/') != -1) {
String msgpath = name.substring(0, name.lastIndexOf('/'));
String propname = name.substring(name.lastIndexOf('/') + 1, name.length());
ObjectNode msgNode = runtime.getGroupNode(msgpath);
APIValue.setValueOnNodeForType(msgNode, propname, parameters.get("type"), p, runtime);
return null;
} else {
ObjectNode on = runtime.getRootNode();
APIValue.setValueOnNodeForType(on, name, parameters.get("type"), p, runtime);
return on;
}
}
Aggregations