Repository: any23
Updated Branches:
  refs/heads/master b7693a5eb -> ebcaaaecb


ANY23-343 upgrade to jsonld-java version 0.12.0


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

Branch: refs/heads/master
Commit: ebcaaaecbd264cc5f21b6a2d33a48c2d438c9d09
Parents: b7693a5
Author: Hans <firedrak...@gmail.com>
Authored: Thu Apr 12 15:58:44 2018 -0500
Committer: Hans <firedrak...@gmail.com>
Committed: Thu Apr 12 15:58:44 2018 -0500

----------------------------------------------------------------------
 .../any23/extractor/rdf/JSONLDExtractor.java    | 92 ++------------------
 .../extractor/rdf/JSONLDExtractorTest.java      |  4 +-
 pom.xml                                         |  2 +-
 3 files changed, 10 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/ebcaaaec/core/src/main/java/org/apache/any23/extractor/rdf/JSONLDExtractor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/any23/extractor/rdf/JSONLDExtractor.java 
b/core/src/main/java/org/apache/any23/extractor/rdf/JSONLDExtractor.java
index a073a21..402e267 100644
--- a/core/src/main/java/org/apache/any23/extractor/rdf/JSONLDExtractor.java
+++ b/core/src/main/java/org/apache/any23/extractor/rdf/JSONLDExtractor.java
@@ -17,27 +17,11 @@
 
 package org.apache.any23.extractor.rdf;
 
-import com.github.jsonldjava.utils.JarCacheStorage;
 import com.github.jsonldjava.utils.JsonUtils;
 import org.apache.any23.extractor.ExtractionContext;
 import org.apache.any23.extractor.ExtractionResult;
 import org.apache.any23.extractor.ExtractorDescription;
-import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheStorage;
-import org.apache.http.client.protocol.RequestAcceptEncoding;
-import org.apache.http.client.protocol.ResponseContentEncoding;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.DefaultRedirectStrategy;
-import org.apache.http.impl.client.cache.BasicHttpCacheStorage;
-import org.apache.http.impl.client.cache.CacheConfig;
-import org.apache.http.impl.client.cache.CachingHttpClientBuilder;
 import org.eclipse.rdf4j.rio.RDFParser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.lang.reflect.Field;
 
 /**
  * Concrete implementation of {@link 
org.apache.any23.extractor.Extractor.ContentExtractor}
@@ -46,80 +30,20 @@ import java.lang.reflect.Field;
  */
 public class JSONLDExtractor extends BaseRDFExtractor {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-    //TODO: the static members of this class can be removed once jsonldjava 
0.11.2 is released
-    //See https://issues.apache.org/jira/browse/ANY23-336
-    static final boolean needsHttpClientSwap;
-
     static {
-        if (!(needsHttpClientSwap = isHttpClientSwapNeeded())) {
-            LOG.warn("The static members of this class are no longer needed.");
-        } else {
-            try {
-                Field field = 
JsonUtils.class.getDeclaredField("DEFAULT_HTTP_CLIENT");
-                field.setAccessible(true);
-                field.set(null, createDefaultHttpClient());
-            } catch (Throwable e) {
-                LOG.warn("failed to swap jsonldjava http client", e);
-            }
-        }
-    }
-
-    private static boolean isHttpClientSwapNeeded() {
+        //See https://issues.apache.org/jira/browse/ANY23-336
         try {
-            JsonUtils.class.getDeclaredField("JSONLD_JAVA_USER_AGENT");
-            return false;
-        } catch (Throwable th) {
-            return true;
-        }
-    }
-
-    private static CloseableHttpClient createDefaultHttpClient() {
-        // Common CacheConfig for both the JarCacheStorage and the underlying
-        // BasicHttpCacheStorage
-        final CacheConfig cacheConfig = 
CacheConfig.custom().setMaxCacheEntries(500)
-                .setMaxObjectSize(1024 * 256).setSharedCache(false)
-                
.setHeuristicCachingEnabled(true).setHeuristicDefaultLifetime(86400).build();
-
-        final CloseableHttpClient result = CachingHttpClientBuilder.create()
-                // allow caching
-                .setCacheConfig(cacheConfig)
-                // Wrap the local JarCacheStorage around a 
BasicHttpCacheStorage
-                .setHttpCacheStorage(new JarCacheStorage0(null, cacheConfig,
-                        new BasicHttpCacheStorage(cacheConfig)))
-                // Support compressed data
-                // 
https://wayback.archive.org/web/20130901115452/http://hc.apache.org:80/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238
-                .addInterceptorFirst(new RequestAcceptEncoding())
-                .addInterceptorFirst(new ResponseContentEncoding())
-                .setRedirectStrategy(DefaultRedirectStrategy.INSTANCE)
-                // use system defaults for proxy etc.
-                .useSystemProperties().build();
-
-        return result;
-    }
-
-    private static class JarCacheStorage0 extends JarCacheStorage {
-
-        private final HttpCacheStorage delegate;
-
-        public JarCacheStorage0(ClassLoader classLoader, CacheConfig 
cacheConfig,
-                               HttpCacheStorage delegate) {
-            super(classLoader, cacheConfig, delegate);
-            this.delegate = delegate;
-        }
-
-        @Override
-        public HttpCacheEntry getEntry(String key) throws IOException {
-            HttpCacheEntry entry = delegate.getEntry(key);
-            return entry != null ? entry : super.getEntry(key);
+            //This field was introduced in jsonld-java version 0.12.0
+            if ((Object)JsonUtils.JSONLD_JAVA_USER_AGENT instanceof Void) {
+                throw new Error("This error will never be thrown.");
+            }
+        } catch (NoSuchFieldError th) {
+            throw new AssertionError("You have an outdated version of 
jsonld-java on the classpath. " +
+                    "Upgrade to at least version 0.12.0. See: 
https://issues.apache.org/jira/browse/ANY23-336";, th);
         }
     }
 
 
-
-
-
     public JSONLDExtractor(boolean verifyDataType, boolean stopAtFirstError) {
         super(verifyDataType, stopAtFirstError);
     }

http://git-wip-us.apache.org/repos/asf/any23/blob/ebcaaaec/core/src/test/java/org/apache/any23/extractor/rdf/JSONLDExtractorTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/any23/extractor/rdf/JSONLDExtractorTest.java 
b/core/src/test/java/org/apache/any23/extractor/rdf/JSONLDExtractorTest.java
index fcef3e4..f21e038 100644
--- a/core/src/test/java/org/apache/any23/extractor/rdf/JSONLDExtractorTest.java
+++ b/core/src/test/java/org/apache/any23/extractor/rdf/JSONLDExtractorTest.java
@@ -59,13 +59,11 @@ public class JSONLDExtractorTest {
 
   @Test
   public void testRemoteContextCaching() throws Exception {
-    Assert.assertTrue("The static members of " + JSONLDExtractor.class + " can 
now be removed!",
-            JSONLDExtractor.needsHttpClientSwap);
     DocumentLoader documentLoader = new DocumentLoader();
     final String[] urls = {"http://schema.org/";, 
"http://schema.org/docs/jsonldcontext.json"};
     for (String url : urls) {
       long start = System.currentTimeMillis();
-      for (int i = 1; i <= 10000; i++) {
+      for (int i = 1; i <= 1000; i++) {
         documentLoader.loadDocument(url);
 
         long seconds = (System.currentTimeMillis() - start) / 1000;

http://git-wip-us.apache.org/repos/asf/any23/blob/ebcaaaec/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f0f809d..516ed64 100644
--- a/pom.xml
+++ b/pom.xml
@@ -494,7 +494,7 @@
       <dependency>
         <groupId>com.github.jsonld-java</groupId>
         <artifactId>jsonld-java</artifactId>
-        <version>0.11.1</version>
+        <version>0.12.0</version>
       </dependency>
       <dependency>
         <groupId>org.semarglproject</groupId>

Reply via email to