Package org.restlet.resource

Examples of org.restlet.resource.ResourceException


    MediaType mediaType = variant.getMediaType();

    FF format = registry.getFileFormatForMIMEType(mediaType.getName());

    if (format == null) {
      throw new ResourceException(CLIENT_ERROR_NOT_ACCEPTABLE, "No acceptable file format found.");
    }

    S service = registry.get(format);

    Representation representation = getRepresentation(service, mediaType);
View Full Code Here


    throws ResourceException
  {
    String queryStr = params.getFirstValue(Protocol.QUERY_PARAM_NAME);

    if (queryStr == null) {
      throw new ResourceException(CLIENT_ERROR_BAD_REQUEST, "Missing parameter: " + QUERY_PARAM_NAME);
    }

    QueryLanguage queryLn = getQueryLanguage(params, response);
    String baseURI = params.getFirstValue(BASEURI_PARAM_NAME);

    try {
      RepositoryConnection connection = RequestAtt.getConnection(request);
      Query query = connection.prepareQuery(queryLn, queryStr, baseURI);
      parseQueryParameters(query, params, connection.getValueFactory());
      return query;
    }
    catch (StoreException e) {
      throw new ResourceException(SERVER_ERROR_INTERNAL, "Failed to prepare query", e);
    }
    catch (MalformedQueryException e) {
      throw new ErrorInfoException(MALFORMED_QUERY, e.getMessage());
    }
  }
View Full Code Here

          try {
            URI uri = vf.createURI(defaultGraphURI);
            dataset.addDefaultGraph(uri);
          }
          catch (IllegalArgumentException e) {
            throw new ResourceException(CLIENT_ERROR_BAD_REQUEST, "Illegal URI for default graph: "
                + defaultGraphURI);
          }
        }
      }

      if (namedGraphURIs != null) {
        for (String namedGraphURI : namedGraphURIs) {
          try {
            URI uri = vf.createURI(namedGraphURI);
            dataset.addNamedGraph(uri);
          }
          catch (IllegalArgumentException e) {
            throw new ResourceException(CLIENT_ERROR_BAD_REQUEST, "Illegal URI for named graph: "
                + namedGraphURI);
          }
        }
      }
    }
View Full Code Here

      ModelResultRepresentation result = new ModelResultRepresentation(modelResult, factory, mediaType);
      result.setTrimNamespaces(true);
      return result;
    }
    catch (StoreException e) {
      throw new ResourceException(e);
    }
  }
View Full Code Here

      con.removeMatch(p.getSubject(), p.getPredicate(), p.getObject(), p.getContext());
      con.getCacheInfo().processUpdate();
      return null;
    }
    catch (StoreException e) {
      throw new ResourceException(SERVER_ERROR_INTERNAL, "Repository update error", e);
    }
  }
View Full Code Here

    }
    catch (SAXParseException e) {
      throw new ErrorInfoException(MALFORMED_DATA, e.getMessage());
    }
    catch (SAXException e) {
      throw new ResourceException(e);
    }
    catch (IOException e) {
      throw new ResourceException(e);
    }
    catch (StoreException e) {
      throw new ResourceException(e);
    }
  }
View Full Code Here

  {
    String mimeType = entity.getMediaType().getName();

    RDFFormat rdfFormat = Rio.getParserFormatForMIMEType(mimeType);
    if (rdfFormat == null) {
      throw new ResourceException(CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE, "Unsupported MIME type: "
          + mimeType);
    }

    ServerConnection connection = getConnection();
    ValueFactory vf = connection.getValueFactory();

    Form params = getQuery();
    Resource[] contexts = ServerUtil.parseContextParam(params, CONTEXT_PARAM_NAME, vf);
    URI baseURI = ServerUtil.parseURIParam(params, BASEURI_PARAM_NAME, vf);

    if (baseURI == null) {
      baseURI = vf.createURI("foo:bar");
      logger.info("no base URI specified, using dummy '{}'", baseURI);
    }

    try {
      InputStream in = entity.getStream();

      boolean autoCommit = connection.isAutoCommit();
      if (autoCommit) {
        connection.begin();
      }

      try {
        if (replaceCurrent) {
          connection.clear(contexts);
        }
        connection.add(in, baseURI.toString(), rdfFormat, contexts);

        if (autoCommit) {
          connection.commit();
        }

        connection.getCacheInfo().processUpdate();
      }
      finally {
        if (autoCommit && !connection.isAutoCommit()) {
          // restore auto-commit by rolling back'
          connection.rollback();
        }
      }
    }
    catch (UnsupportedRDFormatException e) {
      throw new ResourceException(CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE,
          "No RDF parser available for format " + rdfFormat.getName());
    }
    catch (RDFParseException e) {
      throw new ErrorInfoException(MALFORMED_DATA, e.getMessage());
    }
    catch (IOException e) {
      throw new ResourceException(e);
    }
    catch (StoreException e) {
      throw new ResourceException(e);
    }
  }
View Full Code Here

  {
    Query query = RequestAtt.getQuery(getRequest());

    if (query == null) {
      // query is expected to be available in the request attributes
      throw new ResourceException(SERVER_ERROR_INTERNAL, "missing query attribute");
    }

    if (!(query instanceof TupleQuery)) {
      throw new ResourceException(SERVER_ERROR_INTERNAL, "unexpected query type: "
          + query.getClass().getName());
    }

    try {
      return ((TupleQuery)query).evaluate();
    }
    catch (StoreException e) {
      throw new ResourceException(e);
    }
  }
View Full Code Here

      }

      return new TupleResultImpl(columnNames, ids);
    }
    catch (StoreConfigException e) {
      throw new ResourceException(e);
    }
  }
View Full Code Here

      try {
        long size = connection.sizeMatch(subj, pred, obj, includeInferred, contexts);
        return new StringRepresentation(String.valueOf(size));
      }
      catch (StoreException e) {
        throw new ResourceException(e);
      }
    }

    throw new ResourceException(SERVER_ERROR_INTERNAL, "Unsupported media type: " + variant.getMediaType());
  }
View Full Code Here

TOP

Related Classes of org.restlet.resource.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.