Package org.apache.marmotta.ldclient.model

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


    @GET
    @Path("/live")
    public Response retrieveLive(@QueryParam("uri") String uri) {
        if(cacheSailProvider.isEnabled()) {
            try {
                ClientResponse response = cacheSailProvider.getLDClient().retrieveResource(uri);

                ByteArrayOutputStream out = new ByteArrayOutputStream();
                RDFHandler handler = new RDFXMLPrettyWriter(out);

                ModelCommons.export(response.getData(), handler);

                return Response.ok().entity( new String(out.toByteArray(), "utf-8")).build();
            } catch (Exception e) {
                log.error("exception while retrieving resource",e);
                return Response.status(500).entity(e.getMessage()).build();
View Full Code Here


            // refresh the resource by calling LDClient
            log.debug("refreshing resource {}",resource);
            this.lock.readLock().lock();
            try {
                ClientResponse response = ldclient.retrieveResource(resource.stringValue());

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

                    CacheEntry newEntry = new CacheEntry();
                    newEntry.setResource(resource);
                    newEntry.setExpiryDate(response.getExpires());
                    newEntry.setLastRetrieved(new Date());
                    if(entry != null) {
                        newEntry.setUpdateCount(entry.getUpdateCount()+1);
                    } else {
                        newEntry.setUpdateCount(1);
                    }
                    newEntry.setTripleCount(response.getData().size());
                    newEntry.setTriples(response.getData());

                    backend.putEntry(resource, newEntry);

                }
View Full Code Here

   
    private void genericTestImplementation(Endpoint endpoint, String resource) throws Exception {     
        ClientConfiguration config = new ClientConfiguration();
        config.addEndpoint(endpoint);
        LDClientService ldclient = new TestLDClient(new LDClient(config));
        ClientResponse response = ldclient.retrieveResource(resource);
        RepositoryConnection connection = ModelCommons.asRepository(response.getData()).getConnection();
        connection.begin();
        Assert.assertTrue(connection.size() > 0);
        connection.commit();
        connection.close();
    }
View Full Code Here

                    }
                }

            }

            final ClientResponse resp = new ClientResponse(200, model);
            resp.setExpires(new Date());
            return resp;

        } catch (LdapException | CursorException | IOException e) {
            log.warn("could not access LDAP repository: {}", e.getMessage());
            throw new DataRetrievalException(e);
View Full Code Here

    protected void testResource(String uri) throws Exception {

        Assume.assumeTrue(ldclient.ping(uri));

        ClientResponse response = ldclient.retrieveResource(uri);

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

        connection.commit();
        connection.close();
View Full Code Here

    protected void testResource(String uri, String sparqlFile) throws Exception {

        Assume.assumeTrue(ldclient.ping(uri));

        ClientResponse response = ldclient.retrieveResource(uri);

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

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

        log.info("blocked retrieval of resource {}", resource);

        long defaultExpires = client.getClientConfiguration().getDefaultExpiry();
        Date expiresDate = new Date(System.currentTimeMillis() + defaultExpires * 1000);

        ClientResponse result = new ClientResponse(200, empty_repository);
        result.setExpires(expiresDate);
        return result;
    }
View Full Code Here

            if(log.isInfoEnabled()) {
                log.info("retrieved {} triples for resource {}; expiry date: {}", new Object[]{handler.triples.size(), resource, expiresDate});
            }

            ClientResponse result = new ClientResponse(handler.httpStatus, 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 parse resource data for file "+filename);
        } catch (IOException e) {
            throw new DataRetrievalException("could not load resource data for file "+filename);
        }

        ClientResponse response = new ClientResponse(200, triples);

        return response;

    }
View Full Code Here

        ldclient.shutdown();
    }

    @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 {
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.