Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.45 KB

README.md

File metadata and controls

54 lines (40 loc) · 1.45 KB

httpclient-jarcache

httpclient-jarcache is a HttpCacheStorage provider for Apache HTTPClient that allows you to provide a 'warm' cache backed by resources bundled in a JAR file.

This allows for usage of libraries depending on Apache HTTP Client, but bypassing any network connectivity requirement when selected resources can be provided from the classpath.

This library was primarily developed for use with the JSONLD-Java library, but can be used with any library that allows control of which HttpClient instance is to be used.

Mapping of resources to classpath

The JarCacheStorage reads /jarcache.json from the classpath, which structure should mimic:

[
	{
		"Content-Location": "http://nonexisting.example.com/",
		"X-Classpath": "helloworld.html",
		"Content-Type": "text/html"
	},
	{
		"Content-Location": "http://nonexisting.example.com/other.jpg",
		"X-Classpath": "folder/other.jpeg",
		"Content-Type": "image/jpeg"
	}
]

Usage with JSONLD-Java

public class MyExample { 

    static {
	JarCacheStorage cacheStorage = new JarCacheStorage(
			MyExample.class.getClassLoader());
	synchronized (DocumentLoader.class) {
		HttpClient oldHttpClient = DocumentLoader.getHttpClient();
		CachingHttpClient wrappedHttpClient = new CachingHttpClient(
				oldHttpClient, cacheStorage, cacheStorage.getCacheConfig());
		DocumentLoader.setHttpClient(wrappedHttpClient);
	}
    }