GWCConfig config = gwc.getConfig();
if (!config.isDirectWMSIntegrationEnabled()) {
return (WebMap) invocation.proceed();
}
final GetMapRequest request = getRequest(invocation);
boolean tiled = request.isTiled();
if (!tiled) {
return (WebMap) invocation.proceed();
}
final StringBuilder requestMistmatchTarget = new StringBuilder();
ConveyorTile cachedTile = gwc.dispatch(request, requestMistmatchTarget);
if (cachedTile == null) {
WebMap dynamicResult = (WebMap) invocation.proceed();
dynamicResult.setResponseHeader("geowebcache-cache-result", MISS.toString());
dynamicResult.setResponseHeader("geowebcache-miss-reason",
requestMistmatchTarget.toString());
return dynamicResult;
}
checkState(cachedTile.getTileLayer() != null);
final TileLayer layer = cachedTile.getTileLayer();
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("GetMap request intercepted, serving cached content: " + request);
}
final byte[] tileBytes;
{
final Resource mapContents = cachedTile.getBlob();
if (mapContents instanceof ByteArrayResource) {
tileBytes = ((ByteArrayResource) mapContents).getContents();
} else {
ByteArrayOutputStream out = new ByteArrayOutputStream();
mapContents.transferTo(Channels.newChannel(out));
tileBytes = out.toByteArray();
}
}
// Handle Etags
final String ifNoneMatch = request.getHttpRequestHeader("If-None-Match");
final byte[] hash = MessageDigest.getInstance("MD5").digest(tileBytes);
final String etag = toHexString(hash);
if (etag.equals(ifNoneMatch)) {
// Client already has the current version
LOGGER.finer("ETag matches, returning 304");