Package spark.api.exception

Examples of spark.api.exception.SparqlException


      if (u.length() > QUERY_LIMIT) {
        // POST connection
        try {
          req = new HttpPost(url.toURI());
        } catch (URISyntaxException e) {
          throw new SparqlException("Endpoint <" + url + "> not in an acceptable format", e);
        }
        ((HttpPost) req).setEntity((HttpEntity) new StringEntity(params));
      } else {
        // GET connection
        req = new HttpGet(u);
      }

      if (command.getTimeout() != Command.NO_TIMEOUT) {
        HttpParams reqParams = new BasicHttpParams();
        HttpConnectionParams.setSoTimeout(reqParams, (int) (command.getTimeout() * 1000));
        req.setParams(reqParams);
      }
     
      // Add Accept and Content-Type (for POST'ed queries) headers to the request.
      addHeaders(req, mimeType);
     
      // There's a small chance the request could be aborted before it's even executed, we'll have to live with that.
      command.setRequest(req);
     
      //dump(client, req);
      HttpResponse response = client.execute(req);
      StatusLine status = response.getStatusLine();
      int code = status.getStatusCode();
     
      // TODO the client doesn't handle redirects for posts; should we do that here?

      if (code >= SUCCESS_MIN && code <= SUCCESS_MAX) {
        return response;
      } else {
        throw new SparqlException("Unexpected status code in server response: " +
            status.getReasonPhrase() + "(" + code + ")");
      }
    } catch (UnsupportedEncodingException e) {
      throw new SparqlException("Unabled to encode data", e);
    } catch (ClientProtocolException cpe) {
      throw new SparqlException("Error in protocol", cpe);
    } catch (IOException e) {
      throw new SparqlException(e);
    }
  }
View Full Code Here


  /** Sets the currently executing request. */
  void setRequest(HttpUriRequest request) {
    requestLock.lock();
    try {
      if (this.request != null) {
        throw new SparqlException("Command is already executing a request.");
      }
      this.request = request;
    } finally {
      requestLock.unlock();
    }
View Full Code Here

   
    assert format != null:"Could not determine result format";
   
    // Validate that the chosen format can produce the expected result type.
    if (expectedType != null && !format.resultTypes.contains(expectedType)) {
      throw new SparqlException("Result format " + format + " does not support expected result type " + expectedType);
    }
   
    return format.parser;
  }
View Full Code Here

   * @throws SparqlException If the response from the server could not be parsed, or could not be
   *         converted to the expected result type.
   */
  public static Result getResult(Command cmd, HttpResponse response, ResultType expectedType) throws SparqlException {
    HttpEntity entity = response.getEntity();
    if (entity == null) throw new SparqlException("No data in response from server");
   
    Header header = entity.getContentType();
    String mediaType = (header != null) ? header.getValue() : null;
   
    ResultParser parser = null;
    try {
      parser = findParser(mediaType, expectedType);
    } catch (SparqlException e) {
      logger.debug("Couldn't find parser to use for protocol response; cleaning up.");
      try {
        entity.getContent().close();
      } catch (IOException ioe) {
        logger.warn("Error cleaning up response for failed protocol command", e);
      }
      throw e;
    }
    assert parser != null:"Could not find result parser";
   
    Result result = null;
    try {
      result = parser.parse(cmd, entity.getContent(), expectedType);
    } catch (IOException e) {
      throw new SparqlException("Error reading response from server", e);
    }
   
    if (result == null) {
      // Don't know how we got here, but parser should have returned a result or thrown an exception.
      throw new IllegalStateException("Could not parse result from server response.");
View Full Code Here

        e.initCause(cause);
      }
    } else {
      causeMessage = e.getMessage();
    }
    return new SparqlException("Remote Exception: " + causeMessage, e);
  }
View Full Code Here

        }
      }
    } catch (RuntimeException e) {
      throw e;
    } catch (Throwable t) {
      throw new SparqlException(t.getMessage(), t);
    }
  }
View Full Code Here

   
    InetSocketAddress address;
    try {
      address = new InetSocketAddress(InetAddress.getByName(host), port);
    } catch(UnknownHostException e) {
      throw new SparqlException("Invalid host: " + host, e);
    }

    try {
      transceiver = new SaslSocketTransceiver(address);
    } catch(IOException e) {
      throw new SparqlException("Socket error connecting client", e);
    }
   
    try {
      requestor = new SpecificRequestor(SherpaServer.class, transceiver);
    } catch (IOException e) {
      throw new SparqlException("Error creating client requestor", e);
    }

    try {
      server = SpecificRequestor.getClient(SherpaServer.class, requestor);
    } catch (IOException e) {
      throw new SparqlException("Unable to create client data proxy.", e);
    }

  }
View Full Code Here

  public void close() throws SparqlException, IOException {
    super.close();
    try {
      reader.close();
    } catch (XMLStreamException e) {
      throw new SparqlException("Error closing stream", e);
    } finally {
      Command c = getCommand();
      // Need this check because command can be null when testing the parser...
      if (c != null && c instanceof ProtocolCommand) {
        ((ProtocolCommand)c).release();
View Full Code Here

        // already read the final result, so clean up and return nothing
        if (nameIs(RESULTS)) {
          cleanup();
          return null;
        }
        else throw new SparqlException("Bad element closure with: " + reader.getLocalName());
      }
      // we only expect a <result> here
      testOpen(eventType, RESULT, "Expected a new result. Got :" +
          ((eventType == END_ELEMENT) ? "/" : "") + reader.getLocalName());

      Map<String,RDFNode> result = new HashMap<String,RDFNode>();
      // read <binding> list
      while ((eventType = reader.nextTag()) == START_ELEMENT && nameIs(BINDING)) {
        // get the name of the binding
        String name = reader.getAttributeValue(null, VAR_NAME);
        result.put(name, parseValue());
        testClose(reader.nextTag(), BINDING, "Single Binding not closed correctly");
      }

      // a non- <binding> was read, so it should have been a </result>
      testClose(eventType, RESULT, "Single Result not closed correctly");
      return result;
    } catch (XMLStreamException e) {
      throw new SparqlException("Error reading from XML stream", e);
    }
  }
View Full Code Here

   * @return The parsed RDFNode.
   * @throws SparqlException If there was a consistency error in the parsed data.
   * @throws XMLStreamException If there was an error accessing the XML.
   */
  RDFNode parseValue() throws SparqlException, XMLStreamException {
    if (reader.nextTag() != START_ELEMENT) throw new SparqlException("No value in variable binding");
    Element elt = Element.valueOf(reader.getLocalName().toUpperCase());
    try {
      switch (elt) {
      case URI:
        if (reader.next() != CHARACTERS) throw new SparqlException("Unexpected data in URI binding");
        return new NamedNodeImpl(new URI(reader.getText()));
      case BNODE:
        if (reader.next() != CHARACTERS) throw new SparqlException("Unexpected data in BNode binding");
        return new BlankNodeImpl(reader.getText());
      case LITERAL:
        String dt = reader.getAttributeValue(null, DATATYPE);
        URI datatype = (dt == null) ? null : new URI(dt);
        String lang = reader.getAttributeValue(XML_NS, LANG);
        if (reader.next() != CHARACTERS) throw new SparqlException("Unexpected data in Literal binding");
        String lex = reader.getText();
        return (datatype != null) ? new TypedLiteralImpl(lex, datatype) : new PlainLiteralImpl(lex, lang);
      default:
        throw new SparqlException("Unexpected binding value: " + reader.getLocalName());
      }
    } catch (URISyntaxException e) {
      e.printStackTrace();
      throw new SparqlException("Bad URI in binding: " + e.getMessage());
    } catch (Throwable t) {
      t.printStackTrace();
      throw new SparqlException(t);
    } finally {
      testClose(reader.nextTag(), elt, "Bad close of value in binding");
    }
  }
View Full Code Here

TOP

Related Classes of spark.api.exception.SparqlException

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.