예제 #1
0
  @Test
  public void testDummyProvider() throws Exception {
    ClientResponse resp1 = ldclient.retrieveResource("http://localhost/resource1");
    RepositoryConnection con1 = ModelCommons.asRepository(resp1.getData()).getConnection();
    try {
      con1.begin();
      Assert.assertEquals(3, con1.size());
      con1.commit();
    } finally {
      con1.close();
    }

    ClientResponse resp2 = ldclient.retrieveResource("http://localhost/resource2");
    RepositoryConnection con2 = ModelCommons.asRepository(resp2.getData()).getConnection();
    try {
      con2.begin();
      Assert.assertEquals(2, con2.size());
      con2.commit();
    } finally {
      con2.close();
    }

    ClientResponse resp3 = ldclient.retrieveResource("http://localhost/resource3");
    RepositoryConnection con3 = ModelCommons.asRepository(resp3.getData()).getConnection();
    try {
      con3.begin();
      Assert.assertEquals(2, con3.size());
      con3.commit();
    } finally {
      con3.close();
    }
  }
예제 #2
0
  /**
   * Parse the HTTP response entity returned by the web service call and return its contents as a
   * Sesame RDF repository. The content type returned by the web service is passed as argument to
   * help the implementation decide how to parse the data.
   *
   * @param resourceUri
   * @param triples
   * @param in input stream as returned by the remote webservice
   * @param contentType content type as returned in the HTTP headers of the remote
   *     webservice @return an RDF repository containing an RDF representation of the dataset
   *     located at the remote resource.
   * @throws java.io.IOException in case an error occurs while reading the input stream
   */
  @Override
  public List<String> parseResponse(
      final String resourceUri,
      String requestUrl,
      Model triples,
      InputStream in,
      String contentType)
      throws DataRetrievalException {
    RDFFormat format =
        RDFParserRegistry.getInstance().getFileFormatForMIMEType(contentType, RDFFormat.RDFXML);

    try {
      ModelCommons.add(
          triples,
          in,
          resourceUri,
          format,
          new Predicate<Statement>() {
            @Override
            public boolean test(Statement param) {
              return StringUtils.equals(param.getSubject().stringValue(), resourceUri);
            }
          });

      return Collections.emptyList();
    } catch (RDFParseException e) {
      throw new DataRetrievalException("parse error while trying to parse remote RDF content", e);
    } catch (IOException e) {
      throw new DataRetrievalException("I/O error while trying to read remote RDF content", e);
    }
  }