Skip to content

Commit

Permalink
Merge branch 'release/3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed Jul 27, 2016
2 parents 451074c + 40b5385 commit 6b59d19
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# OS junk
.chkbit
.DS_Store
Thumbs.db

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<artifactId>Cantaloupe</artifactId>
<packaging>war</packaging>
<!-- needs to be kept synchronized with properties/cantaloupe.version -->
<version>3.1.1</version>
<version>3.1.2</version>
<name>Cantaloupe</name>
<url>https://medusa-project.github.io/cantaloupe/</url>
<inceptionYear>2015</inceptionYear>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<cantaloupe.version>3.1.1</cantaloupe.version>
<cantaloupe.version>3.1.2</cantaloupe.version>
<restlet.version>2.3.7</restlet.version>
</properties>

Expand Down
23 changes: 18 additions & 5 deletions src/main/java/edu/illinois/library/cantaloupe/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

public class Application {
/**
* Ostensible main application class, which is vestigial and should probably
* be eliminated.
*/
public class Application { // TODO: eliminate this

private static Logger logger = LoggerFactory.getLogger(Application.class);

Expand All @@ -17,19 +22,27 @@ public class Application {
* "SNAPSHOT" if not running from a jar.
*/
public static String getVersion() {
// We will fall back to this if we can't pull the version out of the
// jar for some reason.
String versionStr = "SNAPSHOT";

final Class clazz = Application.class;
final String className = clazz.getSimpleName() + ".class";
final URL classUrl = clazz.getResource(className);

// This could be null if there is a resource leak caused by code
// opening enough JarURLInputStreams (with URL.openStream()) and
// failing to close them.
if (classUrl != null) {
final String classPath = classUrl.toString();
if (classPath.startsWith("file")) {
final int webInfIndex = classPath.lastIndexOf("/WEB-INF");
if (webInfIndex > -1) {
String manifestPath = classPath.substring(0, webInfIndex) +
"/META-INF/MANIFEST.MF";
try {
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
final String manifestPath =
classPath.substring(0, webInfIndex) +
"/META-INF/MANIFEST.MF";
try (InputStream urlStream = new URL(manifestPath).openStream()) {
Manifest manifest = new Manifest(urlStream);
Attributes attr = manifest.getMainAttributes();
String version = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (version != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,16 @@ public ImageInfo getImageInfo() throws ProcessorException {
if (line.startsWith("Stiles=")) {
String[] parts = StringUtils.split(line, ",");
if (parts.length == 2) {
final int tileWidth = Integer.parseInt(parts[0].replaceAll("[^0-9]", ""));
final int tileHeight = Integer.parseInt(parts[1].replaceAll("[^0-9]", ""));
final int dim1 = Integer.parseInt(parts[0].replaceAll("[^0-9]", ""));
final int dim2 = Integer.parseInt(parts[1].replaceAll("[^0-9]", ""));
int tileWidth, tileHeight;
if (width > height) {
tileWidth = Math.max(dim1, dim2);
tileHeight = Math.min(dim1, dim2);
} else {
tileWidth = Math.min(dim1, dim2);
tileHeight = Math.max(dim1, dim2);
}
info.getImages().get(0).tileWidth = tileWidth;
info.getImages().get(0).tileHeight = tileHeight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ protected void doInit() throws ResourceException {
* @param opList Operation list to add the operations to.
* @param fullSize Full size of the source image.
*/
public void addNonEndpointOperations(final OperationList opList,
final Dimension fullSize) {
protected void addNonEndpointOperations(final OperationList opList,
final Dimension fullSize) {
// Redactions
try {
if (RedactionService.isEnabled()) {
List<Redaction> redactions = RedactionService.redactionsFor(
Expand All @@ -197,28 +198,52 @@ public void addNonEndpointOperations(final OperationList opList,
opList.add(redaction);
}
} else {
logger.info("Redactions are disabled ({} = false); skipping.",
RedactionService.REDACTION_ENABLED_CONFIG_KEY);
logger.debug("addNonEndpointOperations(): redactions are " +
"disabled; skipping.");
}
} catch (DelegateScriptDisabledException e) {
// no problem
logger.debug("addNonEndpointOperations(): delegate script is " +
"disabled; skipping redactions.");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}

// Watermark
try {
if (WatermarkService.isEnabled()) {
opList.add(WatermarkService.newWatermark(
opList, fullSize, getReference().toUrl(),
getRequest().getHeaders().getValuesMap(),
getCanonicalClientIpAddress(),
getRequest().getCookies().getValuesMap()));
} else {
logger.info("Watermarking is disabled ({} = false); skipping.",
WatermarkService.WATERMARK_ENABLED_CONFIG_KEY);
logger.debug("addNonEndpointOperations(): watermarking is " +
"disabled; skipping.");
}
} catch (DelegateScriptDisabledException e) {
// no problem
logger.info("Delegate script disabled; skipping non-endpoint " +
"operations.");
logger.debug("addNonEndpointOperations(): delegate script is " +
"disabled; skipping watermark.");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}

/**
* Checks the given operation list against the given image size.
*
* @param opList
* @param fullSize
* @throws EmptyPayloadException
*/
protected final void checkRequest(final OperationList opList,
final Dimension fullSize)
throws EmptyPayloadException {
final Dimension resultingSize = opList.getResultingSize(fullSize);
if (resultingSize.width < 1 || resultingSize.height < 1) {
throw new EmptyPayloadException();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package edu.illinois.library.cantaloupe.resource;

import org.restlet.data.Status;
import org.restlet.resource.ResourceException;

public class EmptyPayloadException extends ResourceException {

public EmptyPayloadException() {
super(Status.CLIENT_ERROR_BAD_REQUEST,
"The requested image has a zero-dimension.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public OutputRepresentation doGet() throws Exception {
throw new AccessDeniedException();
}

// Will throw an exception if anything is wrong.
checkRequest(ops, fullSize);

addNonEndpointOperations(ops, fullSize);

// Find out whether the processor supports that source format by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public OutputRepresentation doGet() throws Exception {
final Dimension fullSize =
getOrReadInfo(ops.getIdentifier(), processor).getSize();

// Will throw an exception if anything is wrong.
checkRequest(ops, fullSize);

if (!isAuthorized(ops, fullSize)) {
throw new AccessDeniedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class ApplicationTest {

/**
* getVersion() is only semi-testable as it will return a different value
* getVersion() is not fully testable as it will return a different value
* when the app is running from a .war.
*/
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public void testResultingWidthOrHeightIsZero() throws IOException {
assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, client.getStatus());
}

client = getClientForUriPath("/" + IMAGE + "/full/0,0/15/color.jpg");
client = getClientForUriPath("/wide.jpg/full/3,0/15/color.jpg");
try {
client.get();
fail("Expected exception");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public void testResultingWidthOrHeightIsZero() throws IOException {
assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, client.getStatus());
}

client = getClientForUriPath("/" + IMAGE + "/full/0,0/15/color.jpg");
client = getClientForUriPath("/wide.jpg/full/3,0/15/color.jpg");
try {
client.get();
fail("Expected exception");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public void testResultingWidthOrHeightIsZero() throws IOException {
assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, client.getStatus());
}

client = getClientForUriPath("/" + IMAGE + "/full/0,0/15/color.jpg");
client = getClientForUriPath("/wide.jpg/full/3,0/15/color.jpg");
try {
client.get();
fail("Expected exception");
Expand Down
9 changes: 9 additions & 0 deletions website/manual/3.1/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

<h2>What's New in <span class="version">3.1</span></h2>

<h2>3.1.2</h2>

<ul>
<li>Fixed a resource leak that would cause landing pages, error pages, and the Control Panel to become inaccessible after a long time running.</li>
<li>Fixed a bug where the watermark wouldn't be added if redactions were enabled and set to use <code>DelegateScriptStrategy</code> but the delegate script was disabled.</li>
<li>Fixed tile sizes in the IIIF Image API 2.x information response when using KakaduProcessor.</li>
<li>HTTP 400 is returned in response to a request for an image that would be zero pixels on a side, even when the zero dimension is not explicit in the request. (For example, a size of <code>4,</code> for an image that is at least five times wider than it is tall.) (Previously, it was only returned when zero pixels was explicitly requested, and the image returned for implicit zero sizes was incorrect.)</li>
</ul>

<h2>3.1.1</h2>

<ul>
Expand Down
4 changes: 4 additions & 0 deletions website/manual/3.1/upgrading.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ <h1>Upgrading</h1>

<div class="alert alert-info">If you are skipping versions, it will be necessary to work through this list upwards from the version you are currently on.</div>

<h2>From 3.1.1 to 3.1.2</h2>

<p>Nothing to do.</p>

<h2>From 3.1 to 3.1.1</h2>

<ul>
Expand Down

0 comments on commit 6b59d19

Please sign in to comment.