Changeset 320

Show
Ignore:
Timestamp:
08/14/08 19:28:33 (5 months ago)
Author:
arneke
Message:

Numerous bugfixes for proper lazy initialization and so that GWC again can work with GetCapabilitiesConfiguration?. Less verbose reporting for invalid requests from clients.

Location:
trunk/geowebcache/src/main
Files:
1 added
14 modified

Legend:

Unmodified
Added
Removed
  • trunk/geowebcache/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java

    r310 r320  
    3030import org.apache.commons.logging.LogFactory; 
    3131import org.geowebcache.demo.Demo; 
     32import org.geowebcache.layer.BadTileException; 
    3233import org.geowebcache.layer.TileLayer; 
    3334import org.geowebcache.layer.TileLayerDispatcher; 
     
    142143        } catch (Exception e) { 
    143144            // e.printStackTrace(); 
    144             log.error(e.getMessage()+ " " + request.getRequestURL().toString()); 
     145            if(! (e instanceof BadTileException) || log.isDebugEnabled()) { 
     146                log.error(e.getMessage()+ " " + request.getRequestURL().toString()); 
     147            } 
     148             
    145149            writeError(response, 400, e.getMessage()); 
    146150            if(! (e instanceof GeoWebCacheException)  
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/Grid.java

    r315 r320  
    3232    private SRS projection = null; 
    3333 
     34    public Grid(SRS projection, BBOX bounds, BBOX gridBounds) { 
     35        this.projection = projection; 
     36        this.bounds = bounds; 
     37        this.gridbounds = gridBounds; 
     38    } 
     39     
    3440    /** 
    3541     * method will set the bounds of the layer for this grid from a BBOX  
     
    4450     */ 
    4551    public void setBounds(String bounds) { 
    46  
    4752        this.bounds = new BBOX(bounds); 
    4853    } 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/TileLayer.java

    r301 r320  
    3939 
    4040    protected List<Grid> grids; 
     41     
     42    // Styles? 
     43     
     44    // Metatiling? 
    4145 
    4246    /** 
     
    98102     * location and so forth. 
    99103     */ 
    100     public abstract Boolean initialize(); 
     104    protected abstract Boolean initialize(); 
    101105 
    102106    /** 
     
    288292     */ 
    289293    public abstract int[] getGridLocForBounds(int srsIdx, BBOX bounds) 
    290             throws GeoWebCacheException; 
     294            throws BadTileException; 
    291295 
    292296    /** 
     
    392396    public abstract void setExpirationHeader(HttpServletResponse response); 
    393397 
    394     public abstract void lazyLayerInitialization(CacheFactory cf); 
     398    //public abstract void lazyLayerInitialization(CacheFactory cf); 
     399     
     400    public abstract void setCacheFactory(CacheFactory cacheFactory); 
    395401} 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/wms/WMSLayer.java

    r318 r320  
    2121import java.io.IOException; 
    2222import java.io.OutputStream; 
     23import java.util.Arrays; 
    2324import java.util.HashMap; 
    2425import java.util.List; 
     
    3738import org.geowebcache.cache.CacheFactory; 
    3839import org.geowebcache.cache.CacheKey; 
     40import org.geowebcache.layer.BadTileException; 
    3941import org.geowebcache.layer.GridLocObj; 
    4042import org.geowebcache.layer.SRS; 
    4143import org.geowebcache.layer.TileLayer; 
    4244import org.geowebcache.layer.Grid; 
     45import org.geowebcache.mime.ErrorMime; 
    4346import org.geowebcache.mime.ImageMime; 
    4447import org.geowebcache.mime.MimeException; 
     
    9093    private transient int curWmsURL; 
    9194 
    92     private transient String wmsLayers; 
     95    //private transient String wmsLayers; 
    9396 
    9497    private transient String wmsStyles; 
    9598 
    96     private transient WMSParameters wmsparams; 
     99    //private transient WMSParameters wmsparams; 
    97100 
    98101    private transient boolean saveExpirationHeaders; 
     
    128131    private static transient Log log; 
    129132 
    130     public WMSLayer(String layerName, CacheFactory cacheFactory) 
    131             throws GeoWebCacheException { 
     133    //public WMSLayer(String layerName, CacheFactory cacheFactory) 
     134    //        throws GeoWebCacheException { 
     135    //    name = layerName; 
     136    //    initCacheFactory = cacheFactory; 
     137    //    log = LogFactory.getLog(org.geowebcache.layer.wms.WMSLayer.class); 
     138    //} 
     139     
     140    public WMSLayer(String layerName, CacheFactory cacheFactory, 
     141            String wmsURL, List<String> mimeFormats, 
     142            List<Grid> grids, int[] metaWidthHeight) { 
     143      
    132144        name = layerName; 
    133145        initCacheFactory = cacheFactory; 
    134     } 
    135      
    136     public void lazyLayerInitialization(CacheFactory cf) { 
    137         zoomStart = 0; 
    138         zoomStop = 20; 
    139         request = "GetMap"; 
    140         curWmsURL = 0; 
    141         wmsLayers = "topp:states"; 
    142         saveExpirationHeaders = false; 
     146        this.WMSurl = wmsURL; 
     147        super.mimeFormats = mimeFormats; 
     148        super.grids = grids; 
     149        this.metaWidthHeight = metaWidthHeight; 
    143150        expireClients = GWCVars.CACHE_USE_WMS_BACKEND_VALUE; 
    144151        expireCache = GWCVars.CACHE_NEVER_EXPIRE; 
    145         layerLock = new ReentrantLock(); 
    146         layerLocked = false; 
    147         layerLockedCond = layerLock.newCondition(); 
    148         procQueue = new HashMap<GridLocObj, Boolean>(); 
    149         cacheLockWait = -1; 
    150         log = LogFactory.getLog(org.geowebcache.layer.wms.WMSLayer.class); 
    151         initCacheFactory = cf; 
    152          
    153         isInitialized(); 
    154              
    155     } 
     152    } 
     153     
     154    public void setCacheFactory(CacheFactory cacheFactory) { 
     155        initCacheFactory = cacheFactory; 
     156        //log = LogFactory.getLog(org.geowebcache.layer.wms.WMSLayer.class); 
     157    } 
     158     
     159//    private void lazyLayerInitialization() { 
     160//        width = 256; 
     161//        height = 256; 
     162//        version = "1.1.0"; 
     163//        transparent = true; 
     164//        zoomStart = 0; 
     165//        zoomStop = 20; 
     166//        request = "GetMap"; 
     167//        errormime = ErrorMime.vnd_ogc_se_inimage.getMimeType(); 
     168//        curWmsURL = 0; 
     169//        wmsLayers = "topp:states"; 
     170//        saveExpirationHeaders = false; 
     171//        expireClients = GWCVars.CACHE_USE_WMS_BACKEND_VALUE; 
     172//        expireCache = GWCVars.CACHE_NEVER_EXPIRE; 
     173//        layerLock = new ReentrantLock(); 
     174//        layerLocked = false; 
     175//        layerLockedCond = layerLock.newCondition(); 
     176//        procQueue = new HashMap<GridLocObj, Boolean>(); 
     177//        cacheLockWait = -1; 
     178//        //initCacheFactory = cf;             
     179//    } 
    156180 
    157181    public Boolean isInitialized() { 
     
    168192    } 
    169193 
    170     public Boolean initialize() { 
     194    protected Boolean initialize() { 
     195         
     196        //lazyLayerInitialization(); 
     197        log = LogFactory.getLog(org.geowebcache.layer.wms.WMSLayer.class); 
     198        curWmsURL = 0; 
     199        zoomStart = 0; 
     200        zoomStop = 20; 
     201        request = "GetMap"; 
     202        errormime = ErrorMime.vnd_ogc_se_inimage.getMimeType(); 
     203        width = 256; 
     204        height = 256; 
     205        version = "1.1.0"; 
     206        transparent = true; 
     207        saveExpirationHeaders = false; 
     208        layerLock = new ReentrantLock(); 
     209        layerLockedCond = layerLock.newCondition(); 
     210        procQueue = new HashMap<GridLocObj, Boolean>(); 
     211         
     212         
    171213        try { 
    172             setParametersFromProperties(initCacheFactory); 
     214            initParameters(); 
    173215        } catch (GeoWebCacheException gwce) { 
    174216            log.error(gwce.getMessage()); 
     
    419461        } 
    420462    } 
     463     
     464    public void setTileIndexHeader(Tile tile) { 
     465        tile.servletResp.addHeader("geowebcache-tile-index", Arrays.toString(tile.getTileIndex())); 
     466    } 
    421467 
    422468    /** 
     
    446492            } 
    447493 
    448             Tile tile = new Tile(this, tileProto.getSRS(), gridPos, tileProto 
    449                     .getMimeType(), metaTile.getStatus(), out.toByteArray()); 
     494            Tile tile = new Tile(this, tileProto.getSRS(), gridPos, 
     495                    tileProto.getMimeType(), metaTile.getStatus(), out.toByteArray()); 
    450496            tile.setTileLayer(this); 
    451497            cache.set(this.cacheKey, tile, expireCache); 
     
    508554            this.setExpirationHeader(tile.servletResp); 
    509555        } 
     556         
     557        setTileIndexHeader(tile); 
     558         
    510559        return tile; 
    511560    } 
     
    516565     * @throws CacheException 
    517566     */ 
    518     private void setParametersFromProperties(CacheFactory cacheFactory) 
    519             throws GeoWebCacheException { 
     567    private void initParameters() throws GeoWebCacheException { 
    520568        // everything that happens in profile construction should happen here 
    521569 
     
    553601                maxTileWidth[index] = 20037508.34 * 2; 
    554602                maxTileHeight[index] = 20037508.34 * 2; 
    555                 log 
    556                         .error("GeoWebCache only handles EPSG:4326 and EPSG:900913!"); 
     603                log.error("GeoWebCache only handles EPSG:4326 and EPSG:900913!"); 
    557604                throw new GeoWebCacheException( 
    558605                        "GeoWebCache only handles EPSG:4326 and EPSG:900913!"); 
     
    571618        // Cache and CacheKey 
    572619 
    573         cache = cacheFactory.getDefaultCache(); 
     620        cache = initCacheFactory.getDefaultCache(); 
     621         
    574622        if (cache == null) { 
    575623            throw new GeoWebCacheException("Unable to get default cache from cacheFactory in WMSLayer."); 
    576624        } 
    577625 
    578         cacheKey = cacheFactory.getCacheKeyFactory().getCacheKey(cache.getDefaultKeyBeanId()); 
     626        cacheKey = initCacheFactory.getCacheKeyFactory().getCacheKey(cache.getDefaultKeyBeanId()); 
     627         
    579628        String sanitizedName = name.replace(':', '_'); 
     629         
    580630        cachePrefix = cache.getDefaultPrefix(sanitizedName); 
     631         
    581632        log.warn("cachePrefix not defined for layer " + name 
    582                 + ", using default prefifx and name instead: " + cachePrefix); 
     633                + ", using default prefix and name instead: " + cachePrefix); 
    583634 
    584635        // Initialize the cache 
    585636        cache.setUp(cachePrefix); 
    586  
    587637    } 
    588638 
     
    640690 
    641691    public WMSParameters getWMSParamTemplate() { 
    642         wmsparams = new WMSParameters(); 
     692        WMSParameters wmsparams = new WMSParameters(); 
    643693        wmsparams.setRequest(request); 
    644694        wmsparams.setVersion(version); 
     
    698748 
    699749    public int[] getGridLocForBounds(int srsIdx, BBOX tileBounds) 
    700             throws ServiceException { 
     750            throws BadTileException { 
    701751        return gridCalc[srsIdx].gridLocation(tileBounds); 
    702752    } 
  • trunk/geowebcache/src/main/java/org/geowebcache/service/kml/KMLDebugGridLayer.java

    r317 r320  
    3131import org.geowebcache.cache.CacheException; 
    3232import org.geowebcache.cache.CacheKey; 
     33import org.geowebcache.layer.BadTileException; 
    3334import org.geowebcache.layer.SRS; 
    3435import org.geowebcache.layer.TileLayer; 
     
    143144 
    144145    public int[] getGridLocForBounds(int srsIdx, BBOX bounds) 
    145             throws GeoWebCacheException { 
     146            throws BadTileException { 
    146147        // TODO Auto-generated method stub 
    147148        //log.warn("getGridLocForBounds(int srsIdx, BBOX bounds)"); 
     
    466467    } 
    467468 
     469 
     470 
     471    @Override 
     472    public void setCacheFactory(CacheFactory cacheFactory) { 
     473        // TODO Auto-generated method stub 
     474         
     475    } 
     476 
    468477} 
  • trunk/geowebcache/src/main/java/org/geowebcache/service/kml/KMLService.java

    r317 r320  
    169169                        "No layer provided, request parsed to: " + tile.getLayerId()); 
    170170            } else if(! layer.isInitialized()){ 
    171                 layer.initialize(); 
     171                // ? 
    172172            } 
    173173        } 
  • trunk/geowebcache/src/main/java/org/geowebcache/service/wms/WMSService.java

    r301 r320  
    106106 
    107107        int[] tileIndex = tileLayer.getGridLocForBounds(srsIdx, bbox); 
    108  
     108         
    109109        // String strOrigin = wmsParams.getOrigin(); 
    110110        // if (strOrigin != null) { 
     
    163163            TileLayer tl = iter.next(); 
    164164            if (!tl.isInitialized()) { 
    165                 tl.initialize(); 
     165                // ooops ? (Always returns true :) ) 
    166166            } 
    167167            xml += getTileSets(tl); 
  • trunk/geowebcache/src/main/java/org/geowebcache/util/GeoServerConfiguration.java

    r243 r320  
    4040                GeoServerConfiguration.getSystemVar( 
    4141                        cacheFactory.getWebAppContext(), GEOSERVER_WMS_URL), 
    42                 mimeTypes,  
    43                 metaTiling, 
    44                 GeoServerConfiguration.getSystemVar( 
     42                        mimeTypes,  
     43                        metaTiling, 
     44                        GeoServerConfiguration.getSystemVar( 
    4545                        cacheFactory.getWebAppContext(), GEOWEBCACHE_VENDOR_PARAMS) 
    4646            ); 
     
    5252                GeoServerConfiguration.getSystemVar( 
    5353                        cacheFactory.getWebAppContext(), GEOSERVER_WMS_URL), 
    54                 mimeTypes,  
    55                 metaTiling, 
    56                 vendorParams 
     54                        mimeTypes,  
     55                        metaTiling, 
     56                        vendorParams 
    5757            ); 
    5858    }   
  • trunk/geowebcache/src/main/java/org/geowebcache/util/GetCapabilitiesConfiguration.java

    r318 r320  
    2020import java.io.IOException; 
    2121import java.net.URL; 
     22import java.util.ArrayList; 
    2223import java.util.HashMap; 
    2324import java.util.Iterator; 
     
    3536import org.geowebcache.GeoWebCacheException; 
    3637import org.geowebcache.cache.CacheFactory; 
     38import org.geowebcache.layer.Grid; 
     39import org.geowebcache.layer.SRS; 
    3740import org.geowebcache.layer.TileLayer; 
    3841import org.geowebcache.layer.wms.WMSLayer; 
     42import org.geowebcache.util.wms.BBOX; 
    3943 
    4044public class GetCapabilitiesConfiguration implements Configuration { 
     
    161165                double maxY = layer.getLatLonBoundingBox().getMaxY(); 
    162166 
    163                 String bbox4326Str = Double.toString(minX) + "," 
    164                         + Double.toString(minY) + "," + Double.toString(maxX) 
    165                         + "," + Double.toString(maxY); 
    166  
     167                BBOX bounds4326 = new BBOX(minX,minY,maxX,maxX); 
    167168                 
    168169                log.info("Found layer: " + layer.getName() 
    169                         + " with LatLon bbox " + bbox4326Str); 
     170                        + " with LatLon bbox " + bounds4326.toString()); 
    170171                 
    171                 String bbox900913Str =  
    172                     Double.toString(longToSphericalMercatorX(minX)) + "," 
    173                     + Double.toString(latToSphericalMercatorY(minY)) + ","  
    174                     + Double.toString(longToSphericalMercatorX(maxX)) + "," 
    175                     + Double.toString(latToSphericalMercatorY(maxY)); 
    176  
     172                BBOX bounds900913 = new BBOX( 
     173                        longToSphericalMercatorX(minX), 
     174                        latToSphericalMercatorY(minY), 
     175                        longToSphericalMercatorX(maxX), 
     176                        latToSphericalMercatorY(maxY)); 
     177                
    177178                WMSLayer wmsLayer = null; 
    178179                try { 
    179                     wmsLayer = getLayer(name, wmsUrl, bbox4326Str,  
    180                             bbox900913Str, stylesStr); 
     180                    wmsLayer = getLayer(name, wmsUrl, bounds4326,  
     181                            bounds900913, stylesStr); 
    181182                } catch (GeoWebCacheException gwc) { 
    182183                    log.error("Error creating " + layer.getName() + ": " 
     
    194195 
    195196    private WMSLayer getLayer(String name, String wmsurl,  
    196             String bbox4326Str, String bbox900913Str, String stylesStr) 
     197            BBOX bounds4326, BBOX bounds900913, String stylesStr) 
    197198            throws GeoWebCacheException { 
    198 //        Properties props = new Properties(); 
    199 //        props.setProperty(WMSLayer.WMS_URL, wmsurl); 
    200 //        props.setProperty(WMSLayer.WMS_SRS, "EPSG:4326;EPSG:900913"); 
    201 //        props.setProperty(WMSLayer.WMS_BBOX,  
    202 //                bbox4326Str +";"+ bbox900913Str); 
    203 //        props.setProperty(WMSLayer.WMS_STYLES, stylesStr); 
    204 //        props.setProperty(WMSLayer.WMS_TRANSPARENT, "true"); 
    205 // 
    206 //        if (this.mimeTypes == null || this.mimeTypes.length() == 0) { 
    207 //            props.setProperty(WMSLayer.WMS_MIMETYPES, "image/png,image/jpeg"); 
    208 //        } else { 
    209 //            props.setProperty(WMSLayer.WMS_MIMETYPES, this.mimeTypes); 
    210 //        } 
    211 //        log.debug("Creating new layer " + name + " with properties: " 
    212 //                + props.toString()); 
    213 // 
    214 //        if (this.metaTiling == null || this.metaTiling.length() == 0) { 
    215 //            props.setProperty(WMSLayer.WMS_METATILING, "3x3"); 
    216 //        } else { 
    217 //            props.setProperty(WMSLayer.WMS_METATILING, metaTiling); 
    218 //        } 
    219 //         
    220 //        if (this.vendorParameters != null) { 
    221 //            props.setProperty(WMSLayer.WMS_VENDOR_PARAMS, vendorParameters); 
    222 //        } 
    223          
    224         //temporary hack 
    225          
    226         WMSLayer layer = null; //new WMSLayer(name, props, this.cacheFactory); 
    227  
    228         return layer; 
     199         
     200        List<Grid> grids = new ArrayList<Grid>(2); 
     201        grids.add(new Grid(SRS.getEPSG4326(), bounds4326, BBOX.world4326)); 
     202        grids.add(new Grid(SRS.getEPSG900913(), bounds900913, BBOX.world900913)); 
     203         
     204        List<String> mimeFormats = new ArrayList<String>(3); 
     205        mimeFormats.add("image/png"); 
     206        mimeFormats.add("image/png8"); 
     207        mimeFormats.add("image/jpeg"); 
     208         
     209        int[] metaWidthHeight = {4,4}; 
     210        // TODO We're dropping the styles now... 
     211        return new WMSLayer(name, this.cacheFactory, 
     212                wmsurl, mimeFormats, grids, metaWidthHeight); 
    229213    } 
    230214 
  • trunk/geowebcache/src/main/java/org/geowebcache/util/XMLConfiguration.java

    r317 r320  
    113113                    result = (WMSLayer) xs.unmarshal(new DomReader( 
    114114                            (Element) allLayerNodes.item(i))); 
    115                 result.lazyLayerInitialization(this.getCacheFactory()); 
     115                result.setCacheFactory(this.cacheFactory); 
    116116                layers.put(result.getName(), result); 
    117117            } 
  • trunk/geowebcache/src/main/java/org/geowebcache/util/wms/BBOX.java

    r317 r320  
    3232    private static double equalityThreshold = 0.03; 
    3333 
     34    public static final BBOX world4326 =  
     35        new BBOX(-180.0,-90.0,180.0,90.0); 
     36     
     37    public static final BBOX world900913 =  
     38        new BBOX(-20037508.34,-20037508.34,20037508.34,20037508.34); 
     39     
    3440    // minx, miny, maxx, maxy 
    3541    public double[] coords = new double[4]; 
  • trunk/geowebcache/src/main/java/org/geowebcache/util/wms/GridCalculator.java

    r221 r320  
    1717package org.geowebcache.util.wms; 
    1818 
     19import java.util.Arrays; 
     20 
    1921import org.apache.commons.logging.Log; 
    2022import org.apache.commons.logging.LogFactory; 
    2123import org.geowebcache.GeoWebCacheException; 
     24import org.geowebcache.layer.BadTileException; 
    2225import org.geowebcache.service.ServiceException; 
    2326 
     
    103106        //  " tileWidth: " + tileWidth); 
    104107 
     108        double[] rawNumber = new double[4]; 
     109         
    105110        for (int level = 0; level <= zoomStop; level++) { 
    106111            //System.out.println("--- Level "+level+"----"); 
     112             
     113             
    107114            // Min X 
    108             gridLevels[level][0] = (int) Math 
    109                     .floor((layerBounds.coords[0] - gridBounds.coords[0]) 
    110                             / tileWidth); 
     115            rawNumber[0] = (layerBounds.coords[0] - gridBounds.coords[0]) / tileWidth; 
     116            gridLevels[level][0] = (int) Math.floor(rawNumber[0]); 
     117             
    111118            // Min Y 
    112             gridLevels[level][1] = (int) Math 
    113                     .floor((layerBounds.coords[1] - gridBounds.coords[1]) 
    114                             / tileHeight); 
     119            rawNumber[1] = (layerBounds.coords[1] - gridBounds.coords[1]) / tileHeight; 
     120            gridLevels[level][1] = (int) Math.floor(rawNumber[1]); 
     121             
     122            // The gridbounds are defined as inclusive, so they actually cover + 1  
     123            // compared to the bottom left coordinate -> use floor() 
     124             
    115125            // Max X 
    116             gridLevels[level][2] = (int) Math 
    117                     .ceil((layerBounds.coords[2] - gridBounds.coords[0]) 
    118                             / tileWidth) - 1