marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject [1/2] git commit: MARMOTTA-545: make path generation more robust for the LdpBinaryStoreServiceImpl
Date Wed, 24 Sep 2014 15:49:28 GMT
Repository: marmotta
Updated Branches:
  refs/heads/develop 28913e9ef -> d58451153


MARMOTTA-545: make path generation more robust for the LdpBinaryStoreServiceImpl


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

Branch: refs/heads/develop
Commit: d58451153f1a42d9e755156abc3e3ae7f3bc10da
Parents: 97ba8cb
Author: Jakob Frank <jakob@apache.org>
Authored: Tue Sep 23 16:10:01 2014 +0200
Committer: Jakob Frank <jakob@apache.org>
Committed: Wed Sep 24 17:39:18 2014 +0200

----------------------------------------------------------------------
 .../triplestore/ContextWebService.java          |  2 +-
 .../ldp/services/LdpBinaryStoreServiceImpl.java | 31 +++++++----
 .../services/LdpBinaryStoreServiceImplTest.java | 54 ++++++++++++++++++++
 3 files changed, 75 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/d5845115/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
index e09cc60..3527b5b 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
@@ -252,7 +252,7 @@ public class ContextWebService {
     
     private URI buildExportUri(String uri, String accept, String format) throws URISyntaxException
{
         List<ContentType> acceptedTypes;
-        if(StringUtils.isNoneBlank(format)) {
+        if(StringUtils.isNotBlank(format)) {
             acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(format);
         } else {
             acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(accept);

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d5845115/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImpl.java
b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImpl.java
index 290f658..a775872 100644
--- a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImpl.java
+++ b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImpl.java
@@ -18,11 +18,8 @@
 package org.apache.marmotta.platform.ldp.services;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
 import org.apache.marmotta.commons.util.HashUtils;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.platform.core.events.ConfigurationChangedEvent;
-import org.apache.marmotta.platform.core.events.SystemStartupEvent;
 import org.apache.marmotta.platform.ldp.api.LdpBinaryStoreService;
 import org.openrdf.model.URI;
 import org.slf4j.Logger;
@@ -30,9 +27,10 @@ import org.slf4j.LoggerFactory;
 
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
 import javax.inject.Inject;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -61,15 +59,26 @@ public class LdpBinaryStoreServiceImpl implements LdpBinaryStoreService
{
         log.info("Initialized binary data store over {}", base.toString());
     }
 
-    private Path getFile(String resource) throws URISyntaxException {
-        java.net.URI uri = new java.net.URI(resource);
-        String schema = uri.getScheme();
-        if ("http".compareTo(schema) != 0) {
-            String msg = "Binary storage not supported for URIs with " + schema + " as schema";
+    Path getFile(String resource) throws URISyntaxException {
+        final java.net.URI uri = new java.net.URI(resource);
+        final String schema = uri.getScheme();
+        if ("http".compareTo(schema) != 0 && "https".compareTo(schema) != 0) {
+            final String msg = "Binary storage not supported for URIs with " + schema + "
as schema";
             log.error(msg);
             throw new RuntimeException(msg);
         }
-        return base.resolve(StringUtils.removeStart(resource, "http://"));
+        final int port;
+        if (uri.getPort() > 0) {
+            port = uri.getPort();
+        } else if ("http".compareTo(schema) == 0) {
+            port = 80;
+        } else if ("https".compareTo(schema) == 0) {
+            port = 443;
+        } else {
+            port = 0;
+        }
+
+        return base.resolve(String.format("%s.%d/%s", uri.getHost(), port, uri.getRawPath()));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d5845115/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImplTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImplTest.java
b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImplTest.java
new file mode 100644
index 0000000..87ea78a
--- /dev/null
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/services/LdpBinaryStoreServiceImplTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.platform.ldp.services;
+
+import org.apache.marmotta.platform.core.test.base.AbstractMarmotta;
+import org.apache.marmotta.platform.core.test.base.EmbeddedMarmotta;
+import org.hamcrest.CoreMatchers;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LdpBinaryStoreServiceImplTest {
+
+    private static AbstractMarmotta marmotta;
+    private static Logger log = LoggerFactory.getLogger(LdpBinaryStoreServiceImplTest.class);
+
+    @BeforeClass
+    public static void init() {
+        marmotta = new EmbeddedMarmotta();
+    }
+
+    @AfterClass
+    public static void shutdown() throws Exception {
+        marmotta.shutdown();
+        marmotta = null;
+    }
+
+    @Test
+    public void testGetFile() throws Exception {
+        final LdpBinaryStoreServiceImpl store = marmotta.getService(LdpBinaryStoreServiceImpl.class);
+
+        final String test1 = "http://localhost:8080/foo/bar/123";
+        Assert.assertThat(store.getFile(test1).toString(), CoreMatchers.endsWith("/localhost.8080/foo/bar/123"));
+
+        // There might be more testing like this here...
+    }
+}
\ No newline at end of file


Mime
View raw message