You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/05/16 17:10:08 UTC

git commit: fixed access problem in marmotta-ldcache when ldcache is disabled

Updated Branches:
  refs/heads/develop 717792188 -> 6db1be5bb


fixed access problem in marmotta-ldcache when ldcache is disabled


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/6db1be5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/6db1be5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/6db1be5b

Branch: refs/heads/develop
Commit: 6db1be5bb257e6a4095088abf21eb79d64a22ace
Parents: 7177921
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Thu May 16 17:09:12 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Thu May 16 17:09:12 2013 +0200

----------------------------------------------------------------------
 .../model/filter/MarmottaNotCachedFilter.java      |    3 +
 .../services/ldcache/LDCacheSailProvider.java      |   18 ++-
 .../webservices/LinkedDataCachingWebService.java   |  161 +++++++++------
 3 files changed, 111 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6db1be5b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/model/filter/MarmottaNotCachedFilter.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/model/filter/MarmottaNotCachedFilter.java b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/model/filter/MarmottaNotCachedFilter.java
index d39fa4c..072da16 100644
--- a/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/model/filter/MarmottaNotCachedFilter.java
+++ b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/model/filter/MarmottaNotCachedFilter.java
@@ -61,6 +61,9 @@ public class MarmottaNotCachedFilter implements ResourceFilter {
         if(resource instanceof BNode) {
             return true;
         }
+        if(!cacheSailProvider.isEnabled()) {
+            return true;
+        }
 
         URI uri = (URI)resource;
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6db1be5b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/ldcache/LDCacheSailProvider.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/ldcache/LDCacheSailProvider.java b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/ldcache/LDCacheSailProvider.java
index f2a08db..bf438df 100644
--- a/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/ldcache/LDCacheSailProvider.java
+++ b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/ldcache/LDCacheSailProvider.java
@@ -64,7 +64,7 @@ public class LDCacheSailProvider implements NotifyingSailProvider {
 
     @Inject
     private SesameService sesameService;
-    
+
     @Inject
     private HttpClientService         httpClientService;
 
@@ -96,6 +96,10 @@ public class LDCacheSailProvider implements NotifyingSailProvider {
     public void configurationChanged(@Observes ConfigurationChangedEvent e) {
         if(e.containsChangedKey(LDCACHE_ENABLED)) {
             sesameService.restart();
+
+            if(!isEnabled()) {
+                sail = null;
+            }
         }
     }
 
@@ -149,7 +153,11 @@ public class LDCacheSailProvider implements NotifyingSailProvider {
      * @return
      */
     public LDClientService getLDClient() {
-        return sail.getLDCache().getLDClient();
+        if(sail != null) {
+            return sail.getLDCache().getLDClient();
+        } else {
+            return null;
+        }
     }
 
     /**
@@ -157,7 +165,11 @@ public class LDCacheSailProvider implements NotifyingSailProvider {
      * @return
      */
     public LDCache getLDCache() {
-        return sail.getLDCache();
+        if(sail != null) {
+            return sail.getLDCache();
+        } else {
+            return null;
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6db1be5b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/webservices/LinkedDataCachingWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/webservices/LinkedDataCachingWebService.java b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/webservices/LinkedDataCachingWebService.java
index c07e797..d245612 100644
--- a/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/webservices/LinkedDataCachingWebService.java
+++ b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/webservices/LinkedDataCachingWebService.java
@@ -78,116 +78,137 @@ public class LinkedDataCachingWebService {
     @GET
     @Path("/live")
     public Response retrieveLive(@QueryParam("uri") String uri) {
+        if(cacheSailProvider.isEnabled()) {
+            try {
+                ClientResponse response = cacheSailProvider.getLDClient().retrieveResource(uri);
 
-        try {
-            ClientResponse response = cacheSailProvider.getLDClient().retrieveResource(uri);
-
-            RepositoryConnection con = response.getTriples().getConnection();
-            con.begin();
+                RepositoryConnection con = response.getTriples().getConnection();
+                con.begin();
 
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            RDFHandler handler = new RDFXMLPrettyWriter(out);
-            con.export(handler);
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                RDFHandler handler = new RDFXMLPrettyWriter(out);
+                con.export(handler);
 
-            con.commit();
-            con.close();
+                con.commit();
+                con.close();
 
 
-            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();
+                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();
+            }
+        } else {
+            return Response.status(Status.SERVICE_UNAVAILABLE).entity("caching is disabled").build();
         }
     }
 
     @GET
     @Path("/cached")
     public Response retrieveCached(@QueryParam("uri") String uri) {
-
-        URI resource = sesameService.getValueFactory().createURI(uri);
+        if(cacheSailProvider.isEnabled()) {
+            URI resource = sesameService.getValueFactory().createURI(uri);
 
 
-        try {
-            cacheSailProvider.getLDCache().refreshResource(resource, false);
+            try {
+                cacheSailProvider.getLDCache().refreshResource(resource, false);
 
-            return Response.ok().build();
-        } catch (Exception e) {
-            log.error("exception while retrieving resource",e);
-            return Response.status(500).entity(e.getMessage()).build();
+                return Response.ok().build();
+            } catch (Exception e) {
+                log.error("exception while retrieving resource",e);
+                return Response.status(500).entity(e.getMessage()).build();
+            }
+        } else {
+            return Response.status(Status.SERVICE_UNAVAILABLE).entity("caching is disabled").build();
         }
+
     }
 
     @GET
     @Path("/refresh")
     public Response refreshCached(@QueryParam("uri") String uri) {
 
-        URI resource = sesameService.getValueFactory().createURI(uri);
+        if(cacheSailProvider.isEnabled()) {
+            URI resource = sesameService.getValueFactory().createURI(uri);
 
 
-        try {
-            cacheSailProvider.getLDCache().refreshResource(resource, true);
+            try {
+                cacheSailProvider.getLDCache().refreshResource(resource, true);
 
-            return Response.ok().build();
-        } catch (Exception e) {
-            log.error("exception while retrieving resource",e);
-            return Response.status(500).entity(e.getMessage()).build();
+                return Response.ok().build();
+            } catch (Exception e) {
+                log.error("exception while retrieving resource",e);
+                return Response.status(500).entity(e.getMessage()).build();
+            }
+        } else {
+            return Response.status(Status.SERVICE_UNAVAILABLE).entity("caching is disabled").build();
         }
+
     }
 
     @POST
     @Path("/expire")
     public Response expireCache(@QueryParam("uri") String uri) {
 
-        if (uri != null) {
-            URI resource = sesameService.getValueFactory().createURI(uri);
-            cacheSailProvider.getLDCache().expire(resource);
+        if(cacheSailProvider.isEnabled()) {
+            if (uri != null) {
+                URI resource = sesameService.getValueFactory().createURI(uri);
+                cacheSailProvider.getLDCache().expire(resource);
+            } else {
+                cacheSailProvider.getLDCache().expireAll();
+            }
+
+            return Response.ok().build();
         } else {
-            cacheSailProvider.getLDCache().expireAll();
+            return Response.status(Status.SERVICE_UNAVAILABLE).entity("caching is disabled").build();
         }
-
-        return Response.ok().build();
     }
 
     @POST
     @Path("/endpoint")
     public Response registerEndpoint(@QueryParam("name") String name,
-            @QueryParam("prefix") String prefix,
-            @QueryParam("endpoint") String endpointUrl,
-            @QueryParam("kind") String type,
-            @QueryParam("mimetype") String mimetype,
-            @QueryParam("expiry") long expiry) {
-
-        if (type == null || !getProviderNames().contains(type.toLowerCase())) {
-            type = LinkedDataProvider.PROVIDER_NAME;
-        }
+                                     @QueryParam("prefix") String prefix,
+                                     @QueryParam("endpoint") String endpointUrl,
+                                     @QueryParam("kind") String type,
+                                     @QueryParam("mimetype") String mimetype,
+                                     @QueryParam("expiry") long expiry) {
+
+        if(cacheSailProvider.isEnabled()) {
+            if (type == null || !getProviderNames().contains(type.toLowerCase())) {
+                type = LinkedDataProvider.PROVIDER_NAME;
+            }
 
-        // Check for valid Regex
-        if (prefix != null) {
-            try {
-                if (prefix.startsWith(Endpoint.REGEX_INDICATOR)) {
-                    Pattern.compile(prefix.substring(Endpoint.REGEX_INDICATOR.length()));
-                } else {
-                    Pattern.compile(prefix);
+            // Check for valid Regex
+            if (prefix != null) {
+                try {
+                    if (prefix.startsWith(Endpoint.REGEX_INDICATOR)) {
+                        Pattern.compile(prefix.substring(Endpoint.REGEX_INDICATOR.length()));
+                    } else {
+                        Pattern.compile(prefix);
+                    }
+                } catch (PatternSyntaxException pse) {
+                    return Response.status(Status.BAD_REQUEST).entity("Invalid Regex in prefix detected").build();
                 }
-            } catch (PatternSyntaxException pse) {
-                return Response.status(Status.BAD_REQUEST).entity("Invalid Regex in prefix detected").build();
             }
-        }
-        if (endpointUrl != null) {
-            endpointUrl = endpointUrl.replace('<', '{').replace('>', '}');
-        } else {
-            endpointUrl = "";
-        }
-        if (mimetype == null) {
-            mimetype ="";
-        }
-        Endpoint endpoint = new Endpoint(name, type, prefix, endpointUrl, mimetype, expiry);
-        endpointService.addEndpoint(endpoint);
+            if (endpointUrl != null) {
+                endpointUrl = endpointUrl.replace('<', '{').replace('>', '}');
+            } else {
+                endpointUrl = "";
+            }
+            if (mimetype == null) {
+                mimetype ="";
+            }
+            Endpoint endpoint = new Endpoint(name, type, prefix, endpointUrl, mimetype, expiry);
+            endpointService.addEndpoint(endpoint);
 
-        cacheSailProvider.updateEndpoints();
+            cacheSailProvider.updateEndpoints();
 
 
-        return Response.ok().build();
+            return Response.ok().build();
+        } else {
+            return Response.status(Status.SERVICE_UNAVAILABLE).entity("caching is disabled").build();
+        }
+
     }
 
     @GET
@@ -206,8 +227,12 @@ public class LinkedDataCachingWebService {
     @GET
     @Path("/provider/list")
     @Produces(Namespaces.MIME_TYPE_JSON)
-    public Set<String> listProviders() {
-        return getProviderNames();
+    public Response listProviders() {
+        if(cacheSailProvider.isEnabled()) {
+            return Response.ok(getProviderNames()).build();
+        } else {
+            return Response.status(Status.SERVICE_UNAVAILABLE).entity("caching is disabled").build();
+        }
     }