Skip to content

Commit

Permalink
Merge branch 'release/1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed Nov 7, 2015
2 parents 9593037 + b0c2a74 commit a3ffe51
Show file tree
Hide file tree
Showing 46 changed files with 1,286 additions and 214 deletions.
21 changes: 20 additions & 1 deletion cantaloupe.properties.sample
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Java2dProcessor.tif.reader = TIFFImageReader
###

# Optional; overrides the PATH
KakaduProcessor.path_to_binaries = /usr/local/bin
#KakaduProcessor.path_to_binaries = /usr/local/bin

# Due to a quirk of kdu_expand, you will need to create a symbolic link to
# /dev/stdout somewhere called `stdout.ppm`, like this:
Expand All @@ -165,6 +165,9 @@ KakaduProcessor.post_processor = java2d
# CACHING
###############

# Whether to enable the response Cache-Control header.
cache.client.enabled = true

# Customize the response Cache-Control header. (This may be overridden by
# proxies.) Comment out to disable the Cache-Control header.
cache.client.max_age = 2592000
Expand Down Expand Up @@ -192,6 +195,22 @@ FilesystemCache.pathname = /var/cache/cantaloupe
# blank or 0 for "forever"
FilesystemCache.ttl_seconds = 2592000

###
# JdbcCache
###

JdbcCache.connection_string = jdbc:postgresql://localhost:5432/cantaloupe
JdbcCache.user = alexd
JdbcCache.password =

# These will be created automatically.
JdbcCache.image_table = image_cache
JdbcCache.info_table = info_cache

# Time before a cached image becomes stale and needs to be reloaded. Set to
# blank or 0 for "forever"
JdbcCache.ttl_seconds = 2592000

###############
# LOGGING
###############
Expand Down
12 changes: 10 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<groupId>edu.illinois.library.cantaloupe</groupId>
<artifactId>Cantaloupe</artifactId>
<packaging>jar</packaging>
<version>1.0.1</version>
<version>1.1</version>
<name>Cantaloupe</name>
<url>https://medusa-project.github.io/cantaloupe/</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<cantaloupe.version>1.0.1</cantaloupe.version>
<cantaloupe.version>1.1</cantaloupe.version>
<commons-io.version>2.4</commons-io.version>
<commons-lang3.version>3.4</commons-lang3.version>
<h2.version>1.4.190</h2.version>
Expand Down Expand Up @@ -98,6 +98,7 @@
<artifactId>janino</artifactId>
<version>${janino.version}</version>
</dependency>
<!-- Used by GraphicsMagickProcessor and ImageMagickProcessor -->
<dependency>
<groupId>org.im4java</groupId>
<artifactId>im4java</artifactId>
Expand All @@ -113,11 +114,18 @@
<artifactId>org.restlet.ext.jackson</artifactId>
<version>${restlet.version}</version>
</dependency>
<!-- use the Simple HTTP server instead of the default Sun server -->
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet.ext.simple</artifactId>
<version>${restlet.version}</version>
</dependency>
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet.ext.slf4j</artifactId>
<version>${restlet.version}</version>
</dependency>
<!-- Provides Velocity for the landing and error page templates -->
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet.ext.velocity</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.restlet.ext.velocity.TemplateRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Directory;
import org.restlet.resource.ResourceException;
import org.restlet.routing.Redirector;
import org.restlet.routing.Router;
import org.restlet.routing.Template;
Expand Down Expand Up @@ -106,16 +107,19 @@ public Status getStatus(Throwable t, Request request,
public Status toStatus(Throwable t, Request request,
Response response) {
Status status;
Throwable cause = t.getCause();
if (cause instanceof IllegalArgumentException ||
cause instanceof UnsupportedEncodingException ||
cause instanceof UnsupportedOutputFormatException) {
t = (t.getCause() != null) ? t.getCause() : t;

if (t instanceof ResourceException) {
status = ((ResourceException) t).getStatus();
} else if (t instanceof IllegalArgumentException ||
t instanceof UnsupportedEncodingException ||
t instanceof UnsupportedOutputFormatException) {
status = new Status(Status.CLIENT_ERROR_BAD_REQUEST, t);
} else if (cause instanceof UnsupportedSourceFormatException) {
} else if (t instanceof UnsupportedSourceFormatException) {
status = new Status(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE, t);
} else if (cause instanceof FileNotFoundException) {
} else if (t instanceof FileNotFoundException) {
status = new Status(Status.CLIENT_ERROR_NOT_FOUND, t);
} else if (cause instanceof AccessDeniedException) {
} else if (t instanceof AccessDeniedException) {
status = new Status(Status.CLIENT_ERROR_FORBIDDEN, t);
} else {
status = new Status(Status.SERVER_ERROR_INTERNAL, t);
Expand All @@ -136,7 +140,7 @@ public ImageServerApplication() {
* @see <a href="http://iiif.io/api/image/2.0/#uri-syntax">URI Syntax</a>
*/
@Override
public synchronized Restlet createInboundRoot() {
public Restlet createInboundRoot() {
final Router router = new Router(getContext());
router.setDefaultMatchingMode(Template.MODE_EQUALS);

Expand Down
20 changes: 14 additions & 6 deletions src/main/java/edu/illinois/library/cantaloupe/cache/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

/**
* Interface to be implemented by all caches. Instances will be shared
* Singletons.
* Singletons, so must be thread-safe.
*/
public interface Cache {

/**
* Deletes the entire cache contents. Must be thread-safe.
* Deletes the entire cache contents.
*
* @throws IOException
*/
Expand All @@ -38,6 +38,11 @@ public interface Cache {
void flushExpired() throws IOException;

/**
* <p>Returns an InputStream corresponding to the given parameters.</p>
*
* <p>If an image corresponding to the given parameters exists in the
* cache but is expired, implementations should delete it.</p>
*
* @param params IIIF request parameters
* @return An input stream corresponding to the given parameters, or null
* if a non-expired image corresponding to the given parameters does not
Expand All @@ -46,18 +51,21 @@ public interface Cache {
InputStream getImageInputStream(Parameters params);

/**
* Reads cached dimension information.
* <p>Reads cached dimension information.</p>
*
* <p>If a dimension corresponding to the given parameters exists in the
* cache but is expired, implementations should delete it.</p>
*
* @param identifier IIIF identifier
* @return Dimension corresponding to the given identifier, or null if a
* @return Dimension corresponding to the given identifier, or null if no
* non-expired dimension exists in the cache.
*/
Dimension getDimension(Identifier identifier) throws IOException;

/**
* @param params IIIF request parameters
* @return OutputStream pointed at the cache to which an image
* corresponding to the supplied parameters can be written.
* @return OutputStream to which an image corresponding to the supplied
* parameters can be written.
* @throws IOException
*/
OutputStream getImageOutputStream(Parameters params) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,11 @@ public InputStream getImageInputStream(Parameters params) {
@Override
public OutputStream getImageOutputStream(Parameters params)
throws IOException { // TODO: make this work better concurrently
if (getImageInputStream(params) == null) {
logger.debug("Miss; caching {}", params);
File cacheFile = getCachedImageFile(params);
cacheFile.getParentFile().mkdirs();
cacheFile.createNewFile();
return new FileOutputStream(cacheFile);
}
return null;
logger.debug("Miss; caching {}", params);
File cacheFile = getCachedImageFile(params);
cacheFile.getParentFile().mkdirs();
cacheFile.createNewFile();
return new FileOutputStream(cacheFile);
}

/**
Expand Down
Loading

0 comments on commit a3ffe51

Please sign in to comment.