Package org.lilyproject.rest

Examples of org.lilyproject.rest.ResourceException


            throws IOException, WebApplicationException {

        JsonNode node = JsonFormat.deserializeNonStd(entityStream);

        if (!(node instanceof ObjectNode)) {
            throw new ResourceException("Request body should be a JSON object.", BAD_REQUEST.getStatusCode());
        }

        ObjectNode objectNode = (ObjectNode)node;

        try {
            // Multiple repositories: ok to use public repo since only non-repository-specific things are needed
            return EntityRegistry.findReader(type).fromJson(objectNode, null, repositoryMgr.getDefaultRepository(),
                    linkTransformer);
        } catch (JsonFormatException e) {
            throw new ResourceException("Error in submitted JSON.", e, BAD_REQUEST.getStatusCode());
        } catch (Exception e) {
            throw new ResourceException("Error reading submitted JSON.", e, INTERNAL_SERVER_ERROR.getStatusCode());
        }
    }
View Full Code Here


public class GenericExceptionMapper implements ExceptionMapper<Throwable> {

    @Override
    public Response toResponse(Throwable throwable) {
        if (throwable instanceof ResourceException) {
            ResourceException re = (ResourceException) throwable;
            return createResponseForResourceException(re);
        } else if (throwable instanceof WebApplicationException) {
            return ((WebApplicationException)throwable).getResponse();
        } else {
            return createGenericResponse(throwable);
View Full Code Here

        JsonNode node = null;
        try {
            node = JsonFormat.deserializeNonStd(entityStream);
        } catch (JsonParseException e) {
            throw new ResourceException(e, BAD_REQUEST.getStatusCode());
        }

        if (!(node instanceof ObjectNode)) {
            throw new ResourceException("Request body should be a JSON object.", BAD_REQUEST.getStatusCode());
        }

        ObjectNode postNode = (ObjectNode)node;
        String action = JsonUtil.getString(postNode, "action");
        List<MutationCondition> conditions;
        Object entity = null;

        try {
            Namespaces namespaces = NamespacesConverter.fromContextJsonIfAvailable(postNode);

            conditions = readMutationConditions(postNode, namespaces);

            // Hardcoded behavior that action 'delete' does not need a submitted entity (and any other does)
            if (!action.equals("delete")) {
                EntityRegistry.RegistryEntry registryEntry = EntityRegistry.findReaderRegistryEntry((Class)entityType);
                ObjectNode objectNode = JsonUtil.getObject(postNode, registryEntry.getPropertyName());
                // Multiple repositories: ok to use public repo since only non-repository-specific things are needed
                entity = EntityRegistry.findReader((Class)entityType).fromJson(objectNode, namespaces,
                    repositoryMgr.getDefaultRepository(), linkTransformer);
            }
        } catch (JsonFormatException e) {
            throw new ResourceException("Error in submitted JSON.", e, BAD_REQUEST.getStatusCode());
        } catch (Exception e) {
            throw new ResourceException("Error reading submitted JSON.", e, INTERNAL_SERVER_ERROR.getStatusCode());
        }

        return new PostAction(action, entity, conditions);
    }
View Full Code Here

            JsonFormat.serialize(listNode, new CloseShieldOutputStream(entityStream));
        } catch (Throwable e) {
            // We catch every throwable, since otherwise no one does it and we will not have any trace
            // of Errors that happened.
            throw new ResourceException("Error serializing entity list.", e, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
        }
    }
View Full Code Here

        try {
            JsonFormat.serialize(BlobConverter.toJson(blob), new CloseShieldOutputStream(entityStream));
        } catch (Throwable e) {
            // We catch every throwable, since otherwise no one does it and we will not have any trace
            // of Errors that happened.
            throw new ResourceException("Error serializing entity.", e, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
        }
    }
View Full Code Here

                    repositoryMgr.getDefaultRepository());
            JsonFormat.serialize(json, new CloseShieldOutputStream(entityStream));
        } catch (Throwable e) {
            // We catch every throwable, since otherwise no one does it and we will not have any trace
            // of Errors that happened.
            throw new ResourceException("Error serializing entity.", e,
                    Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
        }
    }
View Full Code Here

TOP

Related Classes of org.lilyproject.rest.ResourceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.