Examples of HttpErrorException


Examples of de.innovationgate.wgpublisher.webtml.utils.HttpErrorException

                List debugDocuments = WGACore.getDebugDocumentsList(session);
                if (index == -1) {
                    index = debugDocuments.size() - 1;
                }
                if (index >= debugDocuments.size()) {
                    throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "Index out of range: " + index + " where maximum index is " + (debugDocuments.size() - 1), null);
                }
                else {
                    Document doc = (Document) debugDocuments.get(index);
                    doc.getRootElement().addAttribute("index", String.valueOf(index));

                    try {
                        DOMWriter domWriter = new DOMWriter();
                        org.w3c.dom.Document domDocument = domWriter.write(doc);

                        Transformer trans = getDebugModulesTransformer(request.getParameter("throwAway") != null);
                        trans.transform(new DOMSource(domDocument), new StreamResult(response.getOutputStream()));
                    }
                    catch (TransformerConfigurationException e) {
                        response.sendError(500, e.getMessageAndLocation());
                        e.printStackTrace();
                    }
                    catch (TransformerFactoryConfigurationError e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                    catch (TransformerException e) {
                        response.sendError(500, e.getMessageAndLocation());
                        e.printStackTrace();
                    }
                    catch (IOException e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                    catch (DocumentException e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                }
            }
            else {
                throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "You must include either parameter index or url to address the debug document to show", null);
            }
        }
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.HttpErrorException

                List debugDocuments = WGACore.getDebugDocumentsList(session);
                if (index == -1) {
                    index = debugDocuments.size() - 1;
                }
                if (index >= debugDocuments.size()) {
                    throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "Index out of range: " + index + " where maximum index is " + (debugDocuments.size() - 1), null);
                }
                else {
                    Document doc = (Document) debugDocuments.get(index);
                    Element element = (Element) doc.selectSingleNode(request.getParameter("root"));
                    doc = DocumentFactory.getInstance().createDocument(element.createCopy());
                    doc.getRootElement().addAttribute("index", String.valueOf(index));

                    try {
                        DOMWriter domWriter = new DOMWriter();
                        org.w3c.dom.Document domDocument = domWriter.write(doc);

                        Transformer trans = getDebugTagsTransformer(request.getParameter("throwAway") != null);
                        trans.transform(new DOMSource(domDocument), new StreamResult(response.getOutputStream()));
                    }
                    catch (TransformerConfigurationException e) {
                        response.sendError(500, e.getMessageAndLocation());
                        e.printStackTrace();
                    }
                    catch (TransformerFactoryConfigurationError e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                    catch (TransformerException e) {
                        response.sendError(500, e.getMessageAndLocation());
                        e.printStackTrace();
                    }
                    catch (IOException e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                    catch (DocumentException e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                }
            }
            else {
                throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "You must include either parameter index or url to address the debug document to show", null);
            }
        }
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.HttpErrorException

   
    this.maybeResponsibleDesign = maybeResponsibleDesign;
     
    this.exception = exception;
    if (this.exception instanceof HttpErrorException) {
      HttpErrorException httpError = (HttpErrorException) this.exception;
      this.mainMessage = "An error occured while processing your request";
      this.subMessage = "Http Error "  + httpError.getCode() + " - " + httpError.getMessage();
      this.detailMessage = null;
      this.stackTrace = "(None)";
            this.errorCode = httpError.getCode();
            this.httpError = true;
    }
    else {
      this.mainMessage =  "The page you requested is currently not available";
      this.subMessage = "The cause might be maintenance operations or technical problems. Please try again later.";
View Full Code Here

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

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

        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

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

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

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

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

                } 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

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

                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

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

                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

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

                        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
TOP
Copyright © 2018 www.massapi.com. 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.