Search in sources :

Example 1 with NoJSONOutputException

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);
    }
}
Also used : APIException(com.dexels.navajo.article.APIException) IOException(java.io.IOException) NoJSONOutputException(com.dexels.navajo.article.NoJSONOutputException)

Example 2 with NoJSONOutputException

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;
    }
}
Also used : APIException(com.dexels.navajo.article.APIException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary) NoJSONOutputException(com.dexels.navajo.article.NoJSONOutputException) Property(com.dexels.navajo.document.Property)

Aggregations

APIException (com.dexels.navajo.article.APIException)2 NoJSONOutputException (com.dexels.navajo.article.NoJSONOutputException)2 Navajo (com.dexels.navajo.document.Navajo)1 Property (com.dexels.navajo.document.Property)1 Binary (com.dexels.navajo.document.types.Binary)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1