Package org.openrdf.http.client.connections

Examples of org.openrdf.http.client.connections.HTTPRequest


  }

  public boolean delete(String id)
    throws StoreConfigException
  {
    HTTPRequest request = pool.slash(id).delete();

    try {
      request.execute();
      return true;
    }
    catch (NotFound e) {
      return false;
    }
    catch (HTTPException e) {
      throw new StoreConfigException(e);
    }
    catch (IOException e) {
      throw new StoreConfigException(e);
    }
    finally {
      request.release();
    }
  }
View Full Code Here


  }

  public boolean get()
    throws StoreException
  {
    HTTPRequest request = createRequest();

    try {
      request.acceptBoolean();
      execute(request);
      return request.readBoolean();
    }
    catch (NoCompatibleMediaType e) {
      throw new UnsupportedRDFormatException(e);
    }
    catch (IOException e) {
      throw new StoreException(e);
    }
    catch (QueryResultParseException e) {
      throw new StoreException(e);
    }
    finally {
      request.release();
    }
  }
View Full Code Here

  }

  public GraphResult get(Resource subj, URI pred, Value obj, boolean includeInferred, Resource... contexts)
    throws StoreException
  {
    final HTTPRequest request = pool.get();

    if (match != null) {
      request.ifNoneMatch(match);
    }

    request.sendQueryString(getParams(subj, pred, obj, includeInferred, contexts));

    Callable<GraphResult> task = new Callable<GraphResult>() {

      public GraphResult call()
        throws Exception
      {
        request.acceptRDF(true);
        if (execute(request) && !request.isNotModified()) {
          return request.getGraphQueryResult();
        }
        else if (request.isNotModified()) {
          return null;
        }
        else {
          Map<String, String> ns = Collections.emptyMap();
          Cursor<Statement> cursor = EmptyCursor.getInstance();
View Full Code Here

  public void get(Resource subj, URI pred, Value obj, boolean includeInferred, RDFHandler handler,
      Resource... contexts)
    throws RDFHandlerException, StoreException
  {
    HTTPRequest request = pool.get();
    if (match != null) {
      request.ifNoneMatch(match);
    }

    try {
      request.acceptRDF(true);
      request.sendQueryString(getParams(subj, pred, obj, includeInferred, contexts));
      if (execute(request) && !request.isNotModified()) {
        request.readRDF(handler);
      }
    }
    catch (NoCompatibleMediaType e) {
      throw new StoreException(e);
    }
    catch (IOException e) {
      throw new StoreException(e);
    }
    catch (RDFParseException e) {
      throw new StoreException(e);
    }
    finally {
      request.release();
    }
  }
View Full Code Here

  }

  public void post(final Iterable<? extends TransactionOperation> txn)
    throws StoreException
  {
    HTTPRequest request = pool.post();

    // Create a RequestEntity for the transaction data
    request.sendEntity(new RequestEntity() {

      public long getContentLength() {
        return -1; // don't know
      }

      public String getContentType() {
        return Protocol.TXN_MIME_TYPE + "; charset=utf-8";
      }

      public boolean isRepeatable() {
        return true;
      }

      public void writeRequest(OutputStream out)
        throws IOException
      {
        TransactionWriter txnWriter = new TransactionWriter();
        txnWriter.serialize(txn, out);
      }
    });

    try {
      if (!execute(request)) {
        throw new StoreException("Not Found");
      }
    }
    catch (IOException e) {
      throw new StoreException(e);
    }
    finally {
      request.release();
    }
  }
View Full Code Here

  private void upload(RequestEntity reqEntity, String baseURI, boolean overwrite, Resource... contexts)
    throws RDFParseException, StoreException
  {
    // Select appropriate HTTP method
    HTTPRequest request;
    if (overwrite) {
      request = pool.put();
    }
    else {
      request = pool.post();
    }

    // Set relevant query parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>(5);
    for (String encodedContext : Protocol.encodeContexts(contexts)) {
      params.add(new NameValuePair(Protocol.CONTEXT_PARAM_NAME, encodedContext));
    }
    if (baseURI != null && baseURI.trim().length() != 0) {
      String encodedBaseURI = Protocol.encodeValue(new URIImpl(baseURI));
      params.add(new NameValuePair(Protocol.BASEURI_PARAM_NAME, encodedBaseURI));
    }
    request.sendQueryString(params);

    // Set payload
    request.sendEntity(reqEntity);

    // Send request
    try {
      executeUpload(request);
    }
    catch (IOException e) {
      throw new StoreException(e);
    }
    finally {
      request.release();
    }
  }
View Full Code Here

      public GraphResult call()
        throws Exception
      {
        try {
          HTTPRequest request = createRequest();
          request.acceptGraphQueryResult();
          execute(request);
          return request.getGraphQueryResult();
        }
        catch (NoCompatibleMediaType e) {
          throw new UnsupportedRDFormatException(e);
        }
      }
View Full Code Here

  }

  public void get(RDFHandler handler)
    throws RDFHandlerException, StoreException
  {
    HTTPRequest request = createRequest();

    try {
      request.acceptRDF(false);
      execute(request);
      request.readRDF(handler);
    }
    catch (NoCompatibleMediaType e) {
      throw new UnsupportedRDFormatException(e);
    }
    catch (IOException e) {
      throw new StoreException(e);
    }
    catch (RDFParseException e) {
      throw new StoreException(e);
    }
    finally {
      request.release();
    }
  }
View Full Code Here

   *-------------------------*/

  public Long get(Resource subj, URI pred, Value obj, boolean includeInferred, Resource... contexts)
    throws StoreException
  {
    HTTPRequest request = pool.get();

    try {
      if (match != null) {
        request.ifNoneMatch(match);
      }
      request.acceptLong();
      request.sendQueryString(getParams(subj, pred, obj, includeInferred, contexts));
      execute(request);
      if (request.isNotModified()) {
        return null;
      }
      return request.readLong();
    }
    catch (NumberFormatException e) {
      throw new StoreException("Server responded with invalid size value");
    }
    catch (IOException e) {
      throw new StoreException(e);
    }
    finally {
      request.release();
    }
  }
View Full Code Here

  }

  public TupleResult post(int amount)
    throws StoreException, QueryResultParseException, NoCompatibleMediaType
  {
    HTTPRequest request = pool.post();

    NameValuePair pair = new NameValuePair(AMOUNT, valueOf(amount));
    request.sendQueryString(Arrays.asList(pair));

    try {
      request.acceptTupleQueryResult();
      execute(request);
      return request.getTupleQueryResult();
    }
    catch (IOException e) {
      throw new StoreException(e);
    }
  }
View Full Code Here

TOP

Related Classes of org.openrdf.http.client.connections.HTTPRequest

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.