Package org.apache.marmotta.platform.core.exception

Examples of org.apache.marmotta.platform.core.exception.HttpErrorException


                        log.error("Error retrieving the blank node <{}>: {}", resource, e.getMessage());
                        return Response.status(Status.NOT_FOUND).entity("blank node id " + resource + " not found").build();
                    }
                }
                if (r == null) {
                    throw new HttpErrorException(Status.NOT_FOUND, resource, "the requested resource could not be found in Marmotta right now, but may be available again in the future");
                }
                // FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
                // "/" + uuid;

                List<ContentType> offeredTypes = MarmottaHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
View Full Code Here


        if (StringUtils.isNotBlank(uri)) {
            return getMeta(URLDecoder.decode(uri, "utf-8"), mimetype);
        } else if (StringUtils.isNotBlank(genid)) {
            return getMeta(URLDecoder.decode(genid, "utf-8"), mimetype);
        } else {
            throw new HttpErrorException(Status.BAD_REQUEST, uri, "Invalid Request");
        }
    }
View Full Code Here

                connection.commit();
                connection.close();
            }

        } catch (RepositoryException e) {
            throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, e.getMessage());
        }
    }
View Full Code Here

                } else {
                    r = ResourceUtils.getAnonResource(conn, resource);
                }

                if (r == null || !ResourceUtils.isUsed(conn, r)) {
                    throw new HttpErrorException(Response.Status.NOT_FOUND, resource, "the requested resource could not be found in Marmotta right now, but may be available again in the future");
                }

                // create parser
                final RDFFormat serializer = kiWiIOService.getSerializer(mimetype);
                if (serializer == null) {
                    ImmutableMap<String, String> headers = ImmutableMap.of("Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getProducedTypes()));
                    throw new HttpErrorException(Status.NOT_ACCEPTABLE, resource, "mimetype can not be processed", headers);
                }

                final Resource subject = r;

                StreamingOutput entity = new StreamingOutput() {
                    @Override
                    public void write(OutputStream output) throws IOException, WebApplicationException {
                        // FIXME: This method is executed AFTER the @Transactional!
                        RDFWriter writer = Rio.createWriter(serializer, output);
                        try {
                            RepositoryConnection connection = sesameService.getConnection();
                            try {
                                connection.begin();
                                connection.exportStatements(subject, null, null, true, writer);
                            } finally {
                                connection.commit();
                                connection.close();
                            }
                        } catch (RepositoryException e) {
                            throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
                        } catch (RDFHandlerException e) {
                            throw new IOException("error while writing RDF data to stream", e);
                        }

                    }
                };

                // build response
                Response response = Response.ok(entity).lastModified(ResourceUtils.getLastModified(conn, r)).build();
                response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");

                if (!mimetype.contains("html")) { // then create a proper filename
                    String[] components;
                    if (resource.contains("#")) {
                        components = resource.split("#");
                    } else {
                        components = resource.split("/");
                    }
                    final String fileName = components[components.length - 1] + "." + serializer.getDefaultFileExtension();
                    response.getMetadata().add("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
                }

                // create the Content-Type header for the response
                if (mimetype.startsWith("text/") || mimetype.startsWith("application/")) {
                    response.getMetadata().add("Content-Type", mimetype + "; charset=" + ResourceWebService.CHARSET);
                } else {
                    response.getMetadata().add("Content-Type", mimetype);
                }

                // create the Link headers for the response
                List<String> links = new LinkedList<String>();

                // build the link to the human readable content of this resource (if it exists)
                String contentLink = ResourceWebServiceHelper.buildContentLink(r, contentService.getContentType(r), configurationService);
                if (!"".equals(contentLink)) {
                    links.add(contentLink);
                }

                if (links.size() > 0) {
                    response.getMetadata().add("Link", CollectionUtils.fold(links, ", "));
                }
                return response;
            } finally {
                if (conn.isOpen()) {
                    conn.commit();
                    conn.close();
                }
            }
        } catch (RepositoryException e) {
            throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, resource, e.getMessage());
        }
    }
View Full Code Here

                Response response = Response.status(Status.UNSUPPORTED_MEDIA_TYPE).entity("media type " + mimetype + " not supported").build();
                ResourceWebServiceHelper.addHeader(response, "Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getProducedTypes()));
                return response;
            }
            if (request.getContentLength() == 0) {
                throw new HttpErrorException(Status.BAD_REQUEST, uri, "content may not be empty in resource update");
            }

            // a intercepting connection that filters out all triples that have
            // the wrong subject
            InterceptingRepositoryConnection connection = new InterceptingRepositoryConnectionWrapper(sesameService.getRepository(), sesameService.getConnection());
            //RepositoryConnection connection = sesameService.getConnection();
            try {
                connection.begin();
                final Resource subject = connection.getValueFactory().createURI(uri);

                connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));

                // delete all triples for given subject
                connection.remove(subject, null, null, (Resource) null);

                // add RDF data from input to the suject
                connection.add(request.getReader(), configurationService.getBaseUri(), parser, contextService.getDefaultContext());
            } finally {
                connection.commit();
                connection.close();
            }
            return Response.ok().build();
        } catch (URISyntaxException e) {
            throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, "invalid target context");
        } catch (IOException | RDFParseException e) {
            throw new HttpErrorException(Status.NOT_ACCEPTABLE, uri, "could not parse request body");
        } catch (RepositoryException e) {
            throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, e.getMessage());
        }
    }
View Full Code Here

                Resource resource = conn.getValueFactory().createURI(uri);
                if (resource != null) {
                    if (contentService.deleteContent(resource)) {
                        return Response.ok().build();
                    } else {
                        throw new HttpErrorException(Response.Status.NOT_FOUND, uri, "no content found for this resource in Marmotta right now, but may be available again in the future");
                    }
                }
                return Response.status(Response.Status.NOT_FOUND).build();
            } finally {
                conn.commit();
View Full Code Here

                        response.getMetadata().add("Links", s);
                    }
                    return response;
                } else {
                    ImmutableMap<String, String> headers = ImmutableMap.of("Content-Type", ResourceWebServiceHelper.appendContentTypes(contentService.getContentType(resource)));
                    throw new HttpErrorException(Status.NOT_ACCEPTABLE, resource.stringValue(), "no content for mimetype " + mimetype, headers);
                }
            } finally {
                conn.close();
            }
        } catch (IOException e) {
View Full Code Here

    }

    public Response putContent(URI resource, String mimetype, HttpServletRequest request) throws HttpErrorException {
        try {
            if (request.getContentLength() == 0) {
                throw new HttpErrorException(Status.BAD_REQUEST, resource.stringValue(), "content may not be empty for writing");
            }
            contentService.setContentStream(resource, request.getInputStream(), mimetype); // store content
            if(configurationService.getBooleanConfiguration(ENHANCER_STANBOL_ENHANCER_ENABLED, false)) {
                afterContentCreated.fire(new ContentCreatedEvent(resource)); //enhancer
            }
            return Response.ok().build();
        } catch (IOException e) {
            throw new HttpErrorException(Status.BAD_REQUEST, resource.stringValue(), "could not read request body");
        } catch (WritingNotSupportedException e) {
            throw new HttpErrorException(Status.FORBIDDEN, resource.stringValue(), "writting this content is not supported");
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.marmotta.platform.core.exception.HttpErrorException

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.