Package org.apache.marmotta.ldclient.model

Examples of org.apache.marmotta.ldclient.model.ClientResponse


        config.addEndpoint(new SPARQLEndpoint("DBPedia (SPARQL)","http://dbpedia.org/sparql","^http://dbpedia\\.org/resource/.*"));

        LDClientService ldclient = new TestLDClient(new LDClient(config));

        String uriBerlin = "http://dbpedia.org/resource/Berlin";
        ClientResponse respBerlin = ldclient.retrieveResource(uriBerlin);

        RepositoryConnection conBerlin = ModelCommons.asRepository(respBerlin.getData()).getConnection();
        conBerlin.begin();
        Assert.assertTrue(conBerlin.size() > 0);

        // run a SPARQL test to see if the returned data is correct
        InputStream sparql = this.getClass().getResourceAsStream("dbpedia-berlin.sparql");
View Full Code Here


     * @throws Exception
     *
     */
    @Test(expected=DataRetrievalException.class)
    public void testNotRDF() throws Exception {
        ClientResponse response = ldclient.retrieveResource(EXAMPLE);
        Assert.assertTrue(response.getData().size() == 0);
    }
View Full Code Here

     * @throws Exception
     *
     */
    @Test(expected=DataRetrievalException.class)
    public void testSSL() throws Exception {
        ClientResponse response = ldclient.retrieveResource(SSL);
        Assert.assertTrue(response.getData().size() == 0);
    }
View Full Code Here

        LDClientService ldclient = new TestLDClient(new LDClient(config));

        Assume.assumeTrue(ldclient.ping("http://dev.iks-project.eu:8080/"));

        String uriBerlin = "http://dbpedia.org/resource/Berlin";
        ClientResponse respBerlin = ldclient.retrieveResource(uriBerlin);

        RepositoryConnection conBerlin = ModelCommons.asRepository(respBerlin.getData()).getConnection();
        conBerlin.begin();
        Assert.assertTrue(conBerlin.size() > 0);

        // run a SPARQL test to see if the returned data is correct
        InputStream sparql = this.getClass().getResourceAsStream("dbpedia-berlin.sparql");
View Full Code Here

            throw new DataRetrievalException(msg);
        } else {
            model.add(new URIImpl(uri), new URIImpl(FOAF_PRIMARY_TOPIC), new URIImpl(YoutubeVideoProvider.YOUTUBE_BASE_URI + video_id), (Resource)null);
            // FIXME: add inverse triple, but maybe at the YoutubeVideoProvider

            ClientResponse clientResponse = new ClientResponse(200, model);
            clientResponse.setExpires(DateUtils.addYears(new Date(), 10));
            return clientResponse;
        }

    }
View Full Code Here

                RepositoryConnection con = handler.triples.getConnection();
                log.info("retrieved {} triples for resource {}; expiry date: {}",new Object[] {con.size(),resourceUri,expiresDate});
                con.close();
            }

            ClientResponse result = new ClientResponse(handler.triples);
            result.setExpires(expiresDate);
            return result;
        } catch (RepositoryException e) {
            log.error("error while initialising Sesame repository; classpath problem?",e);
            throw new DataRetrievalException("error while initialising Sesame repository; classpath problem?",e);
        } catch (ClientProtocolException e) {
View Full Code Here

                throw new DataRetrievalException("could not load resource data for file "+filename);
            } finally {
                con.close();
            }

            ClientResponse response = new ClientResponse(triples);

            return response;
        } catch (RepositoryException e) {
            throw new DataRetrievalException("could not load resource data for file "+filename);
        }
View Full Code Here

            } catch (RepositoryException e) {
                String msg = "Error adding triples: " + e.getMessage();
                log.error(msg);
                throw new RuntimeException(msg, e);
            }
            ClientResponse clientResponse = new ClientResponse(triples);
            clientResponse.setExpires(DateUtils.addYears(new Date(), 10));
            return clientResponse;
        }

    }
View Full Code Here

            // 4.
            log.debug("refreshing resource {}",resource);
            this.lock.readLock().lock();
            try {
                ClientResponse response = ldclient.retrieveResource(resource.stringValue());

                if(response != null) {
                    log.info("refreshed resource {}",resource);

                    // obtain a new cache connection, since we closed the original connection above
                    LDCachingConnection cacheConnection1 = backend.getCacheConnection(resource.stringValue());
                    cacheConnection1.begin();
                    try {
                        URI subject = cacheConnection1.getValueFactory().createURI(resource.stringValue());

                        RepositoryConnection respConnection = response.getTriples().getConnection();

                        cacheConnection1.remove(subject, null, null);


                        RepositoryResult<Statement> triples = respConnection.getStatements(null,null,null,true);
                        while(triples.hasNext()) {
                            Statement triple = triples.next();
                            try {
                                cacheConnection1.add(triple);
                            } catch (RuntimeException ex) {
                                log.warn("not adding triple {}: an exception occurred ({})",triple,ex.getMessage());
                            }
                        }
                        triples.close();
                        respConnection.close();

                        CacheEntry newEntry = new CacheEntry();
                        newEntry.setResource(subject);
                        newEntry.setExpiryDate(response.getExpires());
                        newEntry.setLastRetrieved(new Date());
                        if(entry != null) {
                            newEntry.setUpdateCount(entry.getUpdateCount()+1);
                        } else {
                            newEntry.setUpdateCount(1);
View Full Code Here

    @GET
    @Path("/live")
    public Response retrieveLive(@QueryParam("uri") String uri) {

        try {
            ClientResponse response = cacheSailProvider.getLDClient().retrieveResource(uri);

            RepositoryConnection con = response.getTriples().getConnection();
            con.begin();

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            RDFHandler handler = new RDFXMLPrettyWriter(out);
            con.export(handler);
View Full Code Here

TOP

Related Classes of org.apache.marmotta.ldclient.model.ClientResponse

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.