Package org.openrdf.repository

Examples of org.openrdf.repository.RepositoryException


        }
        else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_FILE_FORMAT) {
          throw new UnsupportedRDFormatException(errInfo.getErrorMessage());
        }
        else {
          throw new RepositoryException("Failed to upload data: " + errInfo);
        }
      }
    }
    finally {
      releaseConnection(method);
View Full Code Here


    try {
      getTupleQueryResult(method, handler);
    }
    catch (MalformedQueryException e) {
      logger.warn("Server reported unexpected malfored query error", e);
      throw new RepositoryException(e.getMessage(), e);
    }
    finally {
      releaseConnection(method);
    }
  }
View Full Code Here

    try {
      getTupleQueryResult(method, handler);
    }
    catch (MalformedQueryException e) {
      logger.warn("Server reported unexpected malfored query error", e);
      throw new RepositoryException(e.getMessage(), e);
    }
    finally {
      releaseConnection(method);
    }
  }
View Full Code Here

      else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
        throw new UnauthorizedException();
      }
      else {
        ErrorInfo errInfo = getErrorInfo(method);
        throw new RepositoryException("Failed to get namespace: " + errInfo + " (" + httpCode + ")");
      }
    }
    finally {
      releaseConnection(method);
    }
View Full Code Here

      if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
        throw new UnauthorizedException();
      }
      else if (!HttpClientUtil.is2xx(httpCode)) {
        ErrorInfo errInfo = getErrorInfo(method);
        throw new RepositoryException("Failed to set namespace: " + errInfo + " (" + httpCode + ")");
      }
    }
    finally {
      releaseConnection(method);
    }
View Full Code Here

      if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
        throw new UnauthorizedException();
      }
      else if (!HttpClientUtil.is2xx(httpCode)) {
        ErrorInfo errInfo = getErrorInfo(method);
        throw new RepositoryException("Failed to remove namespace: " + errInfo + " (" + httpCode + ")");
      }
    }
    finally {
      releaseConnection(method);
    }
View Full Code Here

      if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
        throw new UnauthorizedException();
      }
      else if (!HttpClientUtil.is2xx(httpCode)) {
        ErrorInfo errInfo = getErrorInfo(method);
        throw new RepositoryException("Failed to clear namespaces: " + errInfo + " (" + httpCode + ")");
      }
    }
    finally {
      releaseConnection(method);
    }
View Full Code Here

        String response = method.getResponseBodyAsString();
        try {
          return Long.parseLong(response);
        }
        catch (NumberFormatException e) {
          throw new RepositoryException("Server responded with invalid size value: " + response);
        }
      }
      else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
        throw new UnauthorizedException();
      }
      else {
        ErrorInfo errInfo = getErrorInfo(method);
        throw new RepositoryException(errInfo.toString());
      }
    }
    finally {
      method.releaseConnection();
    }
View Full Code Here

    UnauthorizedException
  {
    // Specify which formats we support using Accept headers
    Set<TupleQueryResultFormat> tqrFormats = TupleQueryResultParserRegistry.getInstance().getKeys();
    if (tqrFormats.isEmpty()) {
      throw new RepositoryException("No tuple query result parsers have been registered");
    }

    for (TupleQueryResultFormat format : tqrFormats) {
      // Determine a q-value that reflects the user specified preference
      int qValue = 10;

      if (preferredTQRFormat != null && !preferredTQRFormat.equals(format)) {
        // Prefer specified format over other formats
        qValue -= 2;
      }

      for (String mimeType : format.getMIMETypes()) {
        String acceptParam = mimeType;

        if (qValue < 10) {
          acceptParam += ";q=0." + qValue;
        }

        method.addRequestHeader(ACCEPT_PARAM_NAME, acceptParam);
      }
    }

    int httpCode = httpClient.executeMethod(method);

    if (httpCode == HttpURLConnection.HTTP_OK) {
      String mimeType = getResponseMIMEType(method);
      try {
        TupleQueryResultFormat format = TupleQueryResultFormat.matchMIMEType(mimeType, tqrFormats);
        TupleQueryResultParser parser = QueryResultIO.createParser(format, getValueFactory());
        parser.setTupleQueryResultHandler(handler);
        parser.parse(method.getResponseBodyAsStream());
      }
      catch (UnsupportedQueryResultFormatException e) {
        throw new RepositoryException("Server responded with an unsupported file format: " + mimeType);
      }
      catch (QueryResultParseException e) {
        throw new RepositoryException("Malformed query result from server", e);
      }
    }
    else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
      throw new UnauthorizedException();
    }
    else {
      ErrorInfo errInfo = getErrorInfo(method);

      // Throw appropriate exception
      if (errInfo.getErrorType() == ErrorType.MALFORMED_QUERY) {
        throw new MalformedQueryException(errInfo.getErrorMessage());
      }
      else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_QUERY_LANGUAGE) {
        throw new UnsupportedQueryLanguageException(errInfo.getErrorMessage());
      }
      else {
        throw new RepositoryException(errInfo.toString());
      }
    }
  }
View Full Code Here

    UnauthorizedException
  {
    // Specify which formats we support using Accept headers
    Set<RDFFormat> rdfFormats = RDFParserRegistry.getInstance().getKeys();
    if (rdfFormats.isEmpty()) {
      throw new RepositoryException("No tuple RDF parsers have been registered");
    }

    for (RDFFormat format : rdfFormats) {
      // Determine a q-value that reflects the necessity of context
      // support and the user specified preference
      int qValue = 10;

      if (requireContext && !format.supportsContexts()) {
        // Prefer context-supporting formats over pure triple-formats
        qValue -= 5;
      }

      if (preferredRDFFormat != null && !preferredRDFFormat.equals(format)) {
        // Prefer specified format over other formats
        qValue -= 2;
      }

      if (!format.supportsNamespaces()) {
        // We like reusing namespace prefixes
        qValue -= 1;
      }

      for (String mimeType : format.getMIMETypes()) {
        String acceptParam = mimeType;

        if (qValue < 10) {
          acceptParam += ";q=0." + qValue;
        }

        method.addRequestHeader(ACCEPT_PARAM_NAME, acceptParam);
      }
    }

    int httpCode = httpClient.executeMethod(method);

    if (httpCode == HttpURLConnection.HTTP_OK) {
      String mimeType = getResponseMIMEType(method);
      try {
        RDFFormat format = RDFFormat.matchMIMEType(mimeType, rdfFormats);
        RDFParser parser = Rio.createParser(format, getValueFactory());
        parser.setPreserveBNodeIDs(true);
        parser.setRDFHandler(handler);
        parser.parse(method.getResponseBodyAsStream(), method.getURI().getURI());
      }
      catch (UnsupportedRDFormatException e) {
        throw new RepositoryException("Server responded with an unsupported file format: " + mimeType);
      }
      catch (RDFParseException e) {
        throw new RepositoryException("Malformed query result from server", e);
      }
    }
    else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
      throw new UnauthorizedException();
    }
    else {
      ErrorInfo errInfo = getErrorInfo(method);

      // Throw appropriate exception
      if (errInfo.getErrorType() == ErrorType.MALFORMED_QUERY) {
        throw new MalformedQueryException(errInfo.getErrorMessage());
      }
      else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_QUERY_LANGUAGE) {
        throw new UnsupportedQueryLanguageException(errInfo.getErrorMessage());
      }
      else {
        throw new RepositoryException(errInfo.toString());
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.openrdf.repository.RepositoryException

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.