Skip to content

myGrid/httpclient-jarcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
	}
    }

About

JAR-based read-only cache for Apache HTTP Cliejt

Resources

License

Stars

Watchers

Forks

Packages

No packages published