Skip to content

Commit

Permalink
#71 , #72 and #75 : This moves more configuration to XStream and make…
Browse files Browse the repository at this point in the history
…s timeout and bypassing the cache configurable

git-svn-id: http://geowebcache.org/svn/branches/1.0.x@488 e7b91dd5-889a-44ae-8e97-0abfc27e49b2
  • Loading branch information
Arne Kepp committed Jan 13, 2009
1 parent 40c0f1b commit 86e775a
Show file tree
Hide file tree
Showing 14 changed files with 571 additions and 300 deletions.
15 changes: 15 additions & 0 deletions geowebcache/src/main/java/org/geowebcache/layer/TileLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ public double[] getResolutions(SRS srs) throws GeoWebCacheException {
*/
public abstract int[] getMetaTilingFactors();


/**
* Whether clients may specify cache=false and go straight to source
*/
public abstract Boolean isCacheBypassAllowed();
public abstract void isCacheBypassAllowed(boolean allowed);

/**
* The timeout used when querying the backend server. The same value is used
* for both the connection and the data timeout, so in theory the timeout
* could be twice this value.
*/
public abstract Integer getBackendTimeout();
public abstract void setBackendTimeout(int seconds);

/**
* Provides a 2-dim array with the bounds
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private HashMap<String, TileLayer> initialize() {

Iterator<Configuration> configIter = configs.iterator();
while (configIter.hasNext()) {
Map<String, TileLayer> configLayers = null;
List<TileLayer> configLayers = null;

Configuration config = configIter.next();

Expand All @@ -118,19 +118,20 @@ private HashMap<String, TileLayer> initialize() {

if (configIdent != null) {
try {
configLayers = config.getTileLayers();
// This is used by reload as well
configLayers = config.getTileLayers(true);
} catch (GeoWebCacheException gwce) {
log.error(gwce.getMessage());
log.error("Failed to add layers from " + configIdent);
}

log.info("Adding layers from " + configIdent);
if (configLayers != null && configLayers.size() > 0) {
Iterator<Entry<String, TileLayer>> iter = configLayers
.entrySet().iterator();
Iterator<TileLayer> iter = configLayers.iterator();

while (iter.hasNext()) {
Entry<String, TileLayer> one = iter.next();
layers.put(one.getKey(), one.getValue());
TileLayer layer = iter.next();
layers.put(layer.getName(), layer);
}
} else {
log.error("Configuration " + configIdent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@
* This class is a wrapper for HTTP interaction with WMS backend
*/
public class WMSHttpHelper {
private static Log log = LogFactory
.getLog(org.geowebcache.layer.wms.WMSHttpHelper.class);

private static int HTTP_CONNECT_TIMEOUT = 120000; // 120s, in ms

private static int HTTP_READ_TIMEOUT = 120000; // 120s, in ms
private static Log log = LogFactory.getLog(org.geowebcache.layer.wms.WMSHttpHelper.class);

/**
* Used for metatiling requests
Expand Down Expand Up @@ -117,7 +112,7 @@ private static byte[] makeRequest(TileResponseReceiver tileRespRecv,
throw new GeoWebCacheException("Malformed URL: "
+ wmsrequest.toString() + " " + maue.getMessage());
}
data = connectAndCheckHeaders(tileRespRecv, wmsBackendUrl,wmsparams);
data = connectAndCheckHeaders(tileRespRecv, wmsBackendUrl, wmsparams, layer.backendTimeout);

backendTries++;
}
Expand Down Expand Up @@ -146,7 +141,9 @@ private static byte[] makeRequest(TileResponseReceiver tileRespRecv,
*/
private static byte[] connectAndCheckHeaders(
TileResponseReceiver tileRespRecv, URL wmsBackendUrl,
WMSParameters wmsparams) throws GeoWebCacheException {
WMSParameters wmsparams, int backendTimeout)
throws GeoWebCacheException {

byte[] ret = null;
HttpURLConnection wmsBackendCon = null;
int responseCode = -1;
Expand All @@ -155,8 +152,8 @@ private static byte[] connectAndCheckHeaders(
try { // finally
try {
wmsBackendCon = (HttpURLConnection) wmsBackendUrl.openConnection();
wmsBackendCon.setConnectTimeout(HTTP_CONNECT_TIMEOUT);
wmsBackendCon.setReadTimeout(HTTP_READ_TIMEOUT);
wmsBackendCon.setConnectTimeout(backendTimeout * 1000);
wmsBackendCon.setReadTimeout(backendTimeout * 1000);

responseCode = wmsBackendCon.getResponseCode();
responseLength = wmsBackendCon.getContentLength();
Expand Down
21 changes: 21 additions & 0 deletions geowebcache/src/main/java/org/geowebcache/layer/wms/WMSLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public class WMSLayer extends TileLayer {
private int expireCache = -1;

private int expireClients = -1;

protected Integer backendTimeout;

protected Boolean cacheBypassAllowed;

private transient int curWmsURL;

Expand Down Expand Up @@ -924,6 +928,22 @@ public String[] getWMSurl() {
// this.height = h;
//}

public Boolean isCacheBypassAllowed() {
return cacheBypassAllowed;
}

public void isCacheBypassAllowed(boolean allowed) {
cacheBypassAllowed = Boolean.valueOf(allowed);
}

public Integer getBackendTimeout() {
return backendTimeout;
}

public void setBackendTimeout(int seconds) {
backendTimeout = seconds;
}

public void setVersion(String version) {
this.version = version;
}
Expand All @@ -948,4 +968,5 @@ public Tile getNoncachedTile(Tile tile, boolean requestTiled)

return tile;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,7 @@ public void post(Representation entity) {

// The layer we are posting to is null, so we need to create a new one
if(currentLayer == null){
boolean tryCreate = false;
try {
tryCreate = xmlConfig.createLayer(tileLayer);
} catch (GeoWebCacheException gwce) {
// Not much we can do
log.error(gwce.getMessage());
}

if (tryCreate) {
if (xmlConfig.addLayer(tileLayer)) {
log.info("Added layer : " + tileLayer.getName());
getResponse().setStatus(Status.SUCCESS_OK);
} else {
Expand All @@ -342,12 +334,9 @@ public void post(Representation entity) {
} else {
//the layer we are posting to is not null, so we are trying to modify it
boolean trySave = false;
try {
trySave = xmlConfig.modifyLayer(currentLayer.getName(), tileLayer);
} catch (GeoWebCacheException gwce) {
// Not much we can do
log.error(gwce.getMessage());
}

trySave = xmlConfig.modifyLayer(tileLayer);

if (trySave) {
log.info("Overwrote layer : " + currentLayer.getName()
+ " with new layer : " + tileLayer.getName());
Expand Down Expand Up @@ -384,10 +373,11 @@ public void delete() {
return;
}

log.info("Received DELETE request for resource "
+ currentLayer.getName());
log.info("Received DELETE request for resource " + currentLayer.getName());

tlDispatcher.getLayers().remove(currentLayer.getName());
if (xmlConfig.deleteLayer(currentLayer.getName())) {

if (xmlConfig.deleteLayer(currentLayer)) {
log.info("Deleted layer : " + currentLayer.getName());
getResponse().setStatus(Status.SUCCESS_OK);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,22 @@ public Tile getNoncachedTile(Tile tile, boolean requestTiled)
return null;
}

@Override
public Boolean isCacheBypassAllowed() {
return false;
}

@Override
public void isCacheBypassAllowed(boolean allowed) {
}

@Override
public Integer getBackendTimeout() {
return null;
}

@Override
public void setBackendTimeout(int seconds) {
}

}
111 changes: 59 additions & 52 deletions geowebcache/src/main/java/org/geowebcache/service/wms/WMSRequests.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,76 +156,83 @@ private static String getCapabilitiesFooter() throws GeoWebCacheException {
* @return The original WMS capabilities document prior to processing
* @throws GeoWebCacheException
*/
static synchronized String fetchOriginalWMSCapabilitiesDocument() throws GeoWebCacheException {
static synchronized String fetchOriginalWMSCapabilitiesDocument()
throws GeoWebCacheException {
if (getCapsStr != null) {
return getCapsStr;
}
StringBuffer buf = new StringBuffer();

if (getCapConfigs == null) {
throw new GeoWebCacheException("No configuration object available" +
" to use for WMS Capabilities");
throw new GeoWebCacheException("No configuration object available"
+ " to use for WMS Capabilities");
}

Iterator<Configuration> configIter = getCapConfigs.iterator();

CONFIG: while (configIter.hasNext()) {
Map<String, TileLayer> configLayers = null;
List<TileLayer> configLayers = null;
Configuration config = configIter.next();
try {
configLayers = config.getTileLayers();
configLayers = config.getTileLayers(false);
} catch (GeoWebCacheException gwce) {
log.error(gwce.getMessage());
log.error("Failed to add layers from "+ config.getIdentifier());
log.error("Failed to add layers from " + config.getIdentifier());
}

Iterator<TileLayer> iter = null;

if (configLayers != null) {
iter = configLayers.iterator();
}
if (configLayers != null && configLayers.size() > 0) {
for (TileLayer layer : configLayers.values()) {
if (!(layer instanceof WMSLayer)) {
continue; // skip!

while (iter != null && iter.hasNext()) {
TileLayer layer = iter.next();
WMSLayer wmsLayer;

if (!(layer instanceof WMSLayer)) {
continue;
} else {
wmsLayer = (WMSLayer) layer;
}

String url = wmsLayer.getWMSurl()[0];
InputStream input = null;
try {
URL capabilitiesURL = new URL(
url + "?REQUEST=GetCapabilities&SERVICE=WMS&VESION=1.1.0");
URLConnection connection = capabilitiesURL.openConnection();
input = connection.getInputStream();
InputStreamReader reader = new InputStreamReader(input);
BufferedReader process = new BufferedReader(reader);

buf = new StringBuffer();
String line;
while ((line = process.readLine()) != null) {
buf.append(line);
buf.append("\n");
}
if (buf.length() != 0) {
break CONFIG; // we managed to read a capabilities into buf
}
WMSLayer wmsLayer = (WMSLayer) layer;
for (String url : wmsLayer.getWMSurl()) {
InputStream input = null;
/*
* // TODO only use the parts of the capabilities file that
* // are mentioned in our configuration!
*
* WebMapServer wms = new WebMapServer(capabilitiesURL);
* WMSCapabilities capabilities = wms.getCapabilities();
*/
} catch (Throwable notConnected) {
// continue WMSURL
} finally {
if (input != null) {
try {
URL capabilitiesURL = new URL(
url+ "?REQUEST=GetCapabilities&SERVICE=WMS&VESION=1.1.0");
URLConnection connection = capabilitiesURL.openConnection();
input = connection.getInputStream();
InputStreamReader reader = new InputStreamReader(input);
BufferedReader process = new BufferedReader(reader);

buf = new StringBuffer();
String line;
while ((line = process.readLine()) != null) {
buf.append(line);
buf.append("\n");
}
if (buf.length() != 0) {
break CONFIG; // we managed to read a
// capabilities into buf
}
/*
* // TODO only use the parts of the capabilities
* file that // are mentioned in our configuration!
*
* WebMapServer wms = new
* WebMapServer(capabilitiesURL); WMSCapabilities
* capabilities = wms.getCapabilities();
*/
} catch (Throwable notConnected) {
// continue WMSURL
} finally {
if(input != null) {
try {
input.close();
} catch (IOException ioe) {
// Do nothing.
}
}
input.close();
} catch (IOException ioe) {
// Do nothing.
}
}
}
} else {
log.error("Configuration " + config.getIdentifier()
+ " contained no layers.");
}
}
getCapsStr = buf.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
*/
package org.geowebcache.util;

import java.util.Map;
import java.util.List;

import org.geowebcache.GeoWebCacheException;
import org.geowebcache.layer.TileLayer;

public interface Configuration {

public Map<String,TileLayer> getTileLayers() throws GeoWebCacheException;
public List<TileLayer> getTileLayers(boolean reload) throws GeoWebCacheException;
public String getIdentifier() throws GeoWebCacheException;
}
Loading

0 comments on commit 86e775a

Please sign in to comment.