Changeset 338

Show
Ignore:
Timestamp:
08/21/08 15:25:34 (3 months ago)
Author:
arneke
Message:

Tons of minor tweaks and fixes. Separated out the XStream stuff a bit more. Cleaned up dependencies.

Location:
trunk/geowebcache
Files:
21 modified

Legend:

Unmodified
Added
Removed
  • trunk/geowebcache/pom.xml

    r328 r338  
    180180      <version>${spring.version}</version> 
    181181    </dependency> 
     182    <!-- This is for Acegi --> 
     183    <dependency> 
     184      <groupId>org.springframework</groupId> 
     185      <artifactId>spring-jdbc</artifactId> 
     186      <version>${spring.version}</version> 
     187    </dependency> 
     188 
     189 
     190 
    182191     
    183192    <!--  Jetty starter dependencies --> 
     
    271280      <artifactId>acegi-security</artifactId> 
    272281      <version>${acegi.version}</version> 
    273     </dependency> 
    274  
     282      <exclusions> 
     283        <exclusion> 
     284          <groupId>org.springframework</groupId> 
     285          <artifactId>spring-remoting</artifactId> 
     286        </exclusion> 
     287        <exclusion> 
     288          <groupId>org.springframework</groupId> 
     289          <artifactId>spring-jdbc</artifactId> 
     290        </exclusion> 
     291        <exclusion> 
     292          <groupId>org.springframework</groupId> 
     293          <artifactId>spring-support</artifactId> 
     294        </exclusion> 
     295      </exclusions> 
     296    </dependency> 
     297     
    275298    <dependency> 
    276299      <groupId>org.codehaus.jettison</groupId> 
     
    321344      </plugin> 
    322345 
    323  
    324       <!-- plugin> 
     346      <!-- 
     347      <plugin> 
    325348           <artifactId>maven-war-plugin</artifactId> 
    326349           <executions> 
     
    332355             </execution> 
    333356           </executions> 
    334       </plugin --> 
    335        
     357      </plugin> 
     358      --> 
    336359      <plugin> 
    337360        <artifactId>maven-source-plugin</artifactId> 
  • trunk/geowebcache/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java

    r337 r338  
    203203                        + " given prefix " + servletPrefix); 
    204204            } 
    205             retStrs[0] = new String(splitStr[3]); 
     205            retStrs[0] = splitStr[3]; 
    206206            if(splitStr.length > 4) { 
    207                 retStrs[1] = new String(splitStr[4]); 
     207                retStrs[1] = splitStr[4]; 
    208208            } 
    209209        } else { 
     
    212212            } 
    213213            if (splitStr.length == 3) { 
    214                 retStrs[0] = new String(splitStr[2]); 
     214                retStrs[0] = splitStr[2]; 
    215215            } else { 
    216                 retStrs[0] = new String(splitStr[2]); 
    217                 retStrs[1] = new String(splitStr[3]); 
     216                retStrs[0] = splitStr[2]; 
     217                retStrs[1] = splitStr[3]; 
    218218            } 
    219219        } 
  • trunk/geowebcache/src/main/java/org/geowebcache/RESTDispatcher.java

    r335 r338  
    2929 
    3030import org.geowebcache.layer.TileLayer; 
     31import org.geowebcache.layer.TileLayerDispatcher; 
    3132import org.geowebcache.layer.TileLayerResource; 
    3233import org.geowebcache.util.XMLConfiguration; 
     
    5455    private static final int THREAD_NUMBER = 10; 
    5556     
    56     private static XMLConfiguration config; 
     57    private static XMLConfiguration xmlConfig; 
     58     
     59    private static TileLayerDispatcher tlDispatcher; 
    5760     
    5861    private static ThreadPoolExecutor tpe =  
     
    6164    private static Map<String, TileLayer> layers = null; 
    6265     
    63  
    6466    ServletConverter myConverter; 
    6567 
    6668    private Router myRouter; 
    6769 
    68     private static Log log = LogFactory 
    69             .getLog(org.geowebcache.RESTDispatcher.class); 
     70    private static Log log = LogFactory.getLog(org.geowebcache.RESTDispatcher.class); 
    7071 
    7172    /** 
     
    7475     * @param c - an XMLConfiguration 
    7576     */ 
    76     public RESTDispatcher(XMLConfiguration c) { 
     77    public RESTDispatcher(TileLayerDispatcher tlDispatcher, XMLConfiguration xmlConfig) { 
    7778        super(); 
    7879        setSupportedMethods(new String[] {  
    7980                METHOD_GET, METHOD_POST, METHOD_DELETE }); 
    8081         
    81         RESTDispatcher.config = c; 
     82        RESTDispatcher.xmlConfig = xmlConfig; 
     83        RESTDispatcher.tlDispatcher = tlDispatcher; 
    8284         
    8385        // constructor arguments(in order) int corePoolSize, int maximumPoolSize, 
     
    111113 
    112114        try { 
    113             layers = (HashMap<String, TileLayer>) config.getTileLayers(); 
     115            //layers = (HashMap<String, TileLayer>) xmlConfig.getTileLayers(); 
     116            layers = (HashMap<String, TileLayer>) tlDispatcher.getLayers(); 
    114117            myConverter.service(request, response); 
    115         } 
    116  
    117         catch (GeoWebCacheException gwce) { 
    118             System.out.println(gwce.getMessage()); 
     118        //} 
     119        //catch (GeoWebCacheException gwce) { 
     120        //    System.out.println(gwce.getMessage()); 
    119121        } catch (ServletException se) { 
    120122            System.out.println(se.getMessage()); 
     
    155157     */ 
    156158    public static XMLConfiguration getConfig() { 
    157         return config; 
     159        return xmlConfig; 
    158160    } 
    159161     
  • trunk/geowebcache/src/main/java/org/geowebcache/cache/CacheFactory.java

    r204 r338  
    2121import java.util.Iterator; 
    2222import java.util.Map; 
     23import java.util.Map.Entry; 
    2324 
    2425import org.apache.commons.logging.Log; 
     
    8485     */ 
    8586    private void loadCaches() { 
    86         Map cacheBeans = context.getBeansOfType(Cache.class); 
    87         Iterator<String> beanIter = cacheBeans.keySet().iterator(); 
    88  
     87        Map<String,Cache> cacheBeans = context.getBeansOfType(Cache.class); 
     88        Iterator<Entry<String,Cache>> beanIter = cacheBeans.entrySet().iterator(); 
     89         
    8990        caches = new HashMap<String,Cache>(); 
     91         
    9092        while(beanIter.hasNext()) { 
    91             String beanId = beanIter.next(); 
    92             Cache aCache = (Cache) cacheBeans.get(beanId); 
    93             caches.put(beanId, aCache); 
    94             log.debug("Added bean for " + beanId); 
     93            Entry<String,Cache> entry = beanIter.next(); 
     94            caches.put(entry.getKey(), entry.getValue()); 
     95            log.debug("Added cache bean for " + entry.getValue().getClass().toString()); 
    9596        } 
    9697    } 
  • trunk/geowebcache/src/main/java/org/geowebcache/cache/CacheKeyFactory.java

    r203 r338  
    2121import java.util.Iterator; 
    2222import java.util.Map; 
     23import java.util.Map.Entry; 
    2324 
    2425import org.apache.commons.logging.Log; 
     
    4950         
    5051    private void loadCacheKeys() { 
    51         Map cacheBeans = context.getBeansOfType(CacheKey.class); 
    52         Iterator beanIter = cacheBeans.keySet().iterator(); 
     52        Map<String,CacheKey> cacheBeans = context.getBeansOfType(CacheKey.class); 
     53        Iterator<Entry<String,CacheKey>> beanIter = cacheBeans.entrySet().iterator(); 
    5354         
    5455        cacheKeys = new HashMap<String,CacheKey>(); 
     56         
    5557        while(beanIter.hasNext()) { 
    56                 String beanId = (String) beanIter.next(); 
    57             CacheKey aCacheKey = (CacheKey) cacheBeans.get(beanId); 
    58             cacheKeys.put(beanId, aCacheKey); 
     58            Entry<String,CacheKey> entry = beanIter.next(); 
     59            cacheKeys.put(entry.getKey(), entry.getValue()); 
     60            log.debug("Added cache key bean for " + entry.getValue().getClass().toString()); 
    5961        } 
    6062    } 
  • trunk/geowebcache/src/main/java/org/geowebcache/cache/file/FileCache.java

    r317 r338  
    204204            for (int j = 0; j < typeStrs.length && defaultCachePrefix == null; j++) { 
    205205                String value = null; 
    206                 String varStr = new String(varStrs[i]); 
     206                String varStr = varStrs[i]; 
    207207                String typeStr = typeStrs[j]; 
    208208 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/GridCalculator.java

    r337 r338  
    2626 
    2727    // We may want to change this later 
    28     private static final int TILEPIXELS = 256; 
     28    public static final int TILEPIXELS = 256; 
    2929     
    3030    //private BBOX gridBounds = null; 
    3131    private Grid grid; 
    3232     
    33     public final static double[] RESOLUTIONS4326 =  
     33    // The following are created to save memory.  
     34    // Note that they can be modified by external code -> not 100% safe! 
     35    protected final static double[] RESOLUTIONS4326 =  
    3436        GridCalculator.getResolutionArray(180.0, TILEPIXELS, 26); 
    3537     
    36     public final static double[] RESOLUTIONS900913 =  
     38    protected final static double[] RESOLUTIONS900913 =  
    3739        GridCalculator.getResolutionArray(20037508.34*2,TILEPIXELS, 26); 
    3840     
     
    248250 
    249251        // Get the bounds 
    250         BBOX layerBounds = grid.bounds; 
     252        //BBOX layerBounds = grid.bounds; 
    251253        BBOX gridBounds = grid.gridBounds; 
    252254         
     
    499501         
    500502        while (low <= high) { 
    501             int mid = (low + high) / 2; 
     503            int mid = (low + high) >>> 1; 
    502504             
    503505            if(resolutions[mid] > reqUpper) { 
     
    528530    } 
    529531     
     532    public static double[] get900913Resolutions() { 
     533        return GridCalculator.RESOLUTIONS900913; 
     534    } 
     535     
     536    public static double[] get4326Resolutions() { 
     537        return GridCalculator.RESOLUTIONS4326; 
     538    } 
     539     
    530540} 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/TileLayer.java

    r337 r338  
    4242     
    4343    // Styles? 
    44      
    45     // Metatiling? 
    4644 
    4745    /** 
     
    203201     * @return the array of supported projections 
    204202     */ 
    205     public SRS[] getProjections() { 
    206         return (SRS[]) this.grids.keySet().toArray(); 
    207     } 
     203    //public SRS[] getProjections() { 
     204    //    return (SRS[]) this.grids.keySet().toArray(); 
     205    //} 
    208206 
    209207     
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/TileLayerResource.java

    r335 r338  
    2323import org.apache.commons.logging.LogFactory; 
    2424 
    25 import com.thoughtworks.xstream.*; 
     25//import com.thoughtworks.xstream.*; 
     26import com.thoughtworks.xstream.XStream; 
    2627import com.thoughtworks.xstream.io.HierarchicalStreamDriver; 
    2728import com.thoughtworks.xstream.io.HierarchicalStreamReader; 
     
    3536import org.json.JSONException; 
    3637import org.restlet.ext.json.JsonRepresentation; 
     38import org.springframework.beans.BeansException; 
     39import org.springframework.context.ApplicationContext; 
     40import org.springframework.context.ApplicationContextAware; 
     41import org.springframework.web.context.WebApplicationContext; 
    3742 
    3843import org.geowebcache.layer.wms.WMSLayer; 
     44import org.geowebcache.util.XMLConfiguration; 
    3945import org.geowebcache.GeoWebCacheException; 
    4046import org.geowebcache.RESTDispatcher; 
     
    5359public class TileLayerResource extends Resource { 
    5460    private TileLayer currentLayer = null; 
    55  
    56     private static Log log = LogFactory 
    57             .getLog(org.geowebcache.layer.TileLayerResource.class); 
     61     
     62    private static Log log = LogFactory.getLog(org.geowebcache.layer.TileLayerResource.class); 
    5863 
    5964    /** 
     
    126131     */ 
    127132    public DomRepresentation getDomRepresentationAsListOfLayers() { 
    128         XStream xs = RESTDispatcher.getConfig().getConfiguredXStream(new XStream()); 
     133        XStream xs = XMLConfiguration.getConfiguredXStream(new XStream()); 
    129134         
    130135        StringBuffer buf = new StringBuffer(); 
     
    179184     */ 
    180185    public DomRepresentation getXMLRepresentation(TileLayer layer) { 
    181         XStream xs = RESTDispatcher.getConfig().getConfiguredXStream(new XStream()); 
     186        XStream xs = XMLConfiguration.getConfiguredXStream(new XStream()); 
    182187        String xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + xs.toXML(layer); 
    183188         
     
    211216    public JsonRepresentation getJsonRepresentation(TileLayer layer) { 
    212217        JsonRepresentation rep = null; 
    213         try {             
    214             XStream xs = RESTDispatcher.getConfig().getConfiguredXStream(new XStream(new JsonHierarchicalStreamDriver())); 
     218        try { 
     219            XStream xs = XMLConfiguration.getConfiguredXStream( 
     220                    new XStream(new JsonHierarchicalStreamDriver())); 
    215221            JSONObject obj = new JSONObject(xs.toXML(layer)); 
    216222            rep = new JsonRepresentation(obj); 
     
    231237                + getRequest().getHostRef().getHostIdentifier()); 
    232238        try{ 
    233             String xmlText = entity.getText();       
    234             XStream xs = RESTDispatcher.getConfig().getConfiguredXStream(new XStream(new DomDriver())); 
     239            String xmlText = entity.getText(); 
     240            XStream xs = XMLConfiguration.getConfiguredXStream(new XStream(new DomDriver())); 
     241            //XStream xs = RESTDispatcher.getConfig().getConfiguredXStream(); 
    235242            TileLayer tileLayer = null; 
    236243            if(entity.getMediaType().equals(MediaType.APPLICATION_XML)){ 
     
    239246             
    240247            /** 
    241              * deserializing a json string is more complicated. XStream does not natively 
    242              * support it. Rather it uses a JettisonMappedXmlDriver to convert to intermediate xml 
     248             * Deserializing a JSON string is more complicated. XStream does not natively 
     249             * support it. Rather it uses a JettisonMappedXmlDriver to convert to intermediate XML 
    243250             * and then deserializes that into the desired object. At this time, there is a known issue  
    244              * with the Jettison driver involving elements that come after an array in the json string.  
     251             * with the Jettison driver involving elements that come after an array in the JSON string.  
    245252             *  
    246253             * http://jira.codehaus.org/browse/JETTISON-48 
    247254             *  
    248              * The code below is a hack: it treats the json string as text, then converts it to the intermediate 
    249              * xml and then deserializes that into the tileLayer object.  
    250              *  
    251              *  
     255             * The code below is a hack: it treats the json string as text, then converts it to the  
     256             * intermediate XML and then deserializes that into the tileLayer object.  
    252257             */ 
    253258            else if(entity.getMediaType().equals(MediaType.APPLICATION_JSON)){ 
     
    294299                } 
    295300                if (trySave) { 
    296                     log.info("Overwrote layer : " + currentLayer.getName() + " with new layer : " + tileLayer.getName()); 
     301                    log.info("Overwrote layer : " + currentLayer.getName()  
     302                            + " with new layer : " + tileLayer.getName()); 
    297303                    getResponse().setStatus(Status.SUCCESS_OK); 
    298304                } else { 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/wms/WMSHttpHelper.java

    r337 r338  
    2929import org.geowebcache.GeoWebCacheException; 
    3030import org.geowebcache.layer.Grid; 
     31import org.geowebcache.layer.GridCalculator; 
    3132import org.geowebcache.layer.TileResponseReceiver; 
    3233import org.geowebcache.mime.ErrorMime; 
     
    7576        wmsparams.setFormat(tile.getMimeType().getFormat()); 
    7677        wmsparams.setSrs(tile.getSRS()); 
    77         wmsparams.setWidth(layer.getWidth()); 
    78         wmsparams.setHeight(layer.getHeight()); 
     78        wmsparams.setWidth(GridCalculator.TILEPIXELS); 
     79        wmsparams.setHeight(GridCalculator.TILEPIXELS); 
    7980        Grid grid = layer.getGrid(tile.getSRS()); 
    8081         
     
    183184                    byte[] error = new byte[2048]; 
    184185                    try { 
    185                         wmsBackendCon.getInputStream().read(error); 
     186                        int readLength = 0; 
     187                        int readAccu = 0; 
     188                        while(readLength > -1 && readAccu < error.length) { 
     189                            int left = error.length - readAccu; 
     190                            readLength = wmsBackendCon.getInputStream().read(error,readAccu, left); 
     191                            readAccu += readLength; 
     192                        } 
    186193                    } catch (IOException ioe) { 
    187194                        // Do nothing 
     
    211218                        int readLength = 0; 
    212219                        int readAccu = 0; 
    213                         int left = responseLength; 
    214                         while(readLength > -1 && left > 0) { 
     220                        while(readLength > -1 && readAccu < responseLength) { 
     221                            int left = responseLength - readAccu; 
    215222                            readLength = wmsBackendCon.getInputStream().read(ret,readAccu,left); 
    216223                            readAccu += readLength; 
    217                             left -= readLength; 
    218224                        } 
    219225                        if (readAccu != responseLength) { 
    220226                            tileRespRecv.setError(); 
    221227                            throw new GeoWebCacheException( 
    222                                     "Responseheader advertised " 
    223                                             + responseLength 
    224                                             + " bytes, but only received " 
    225                                             + readLength + " from " 
    226                                             + wmsBackendUrl.toString()); 
     228                                    "Responseheader advertised "+ responseLength 
     229                                    + " bytes, but only received " + readLength  
     230                                    + " from " + wmsBackendUrl.toString()); 
    227231                        } 
    228232                    } 
  • trunk/geowebcache/src/main/java/org/geowebcache/layer/wms/WMSLayer.java

    r337 r338  
    3939import org.geowebcache.cache.CacheFactory; 
    4040import org.geowebcache.cache.CacheKey; 
    41 import org.geowebcache.layer.BadTileException; 
    4241import org.geowebcache.layer.GridLocObj; 
    4342import org.geowebcache.layer.SRS; 
     
    4847import org.geowebcache.mime.MimeException; 
    4948import org.geowebcache.mime.MimeType; 
    50 import org.geowebcache.service.ServiceException; 
    5149import org.geowebcache.service.wms.WMSParameters; 
    5250import org.geowebcache.tile.Tile; 
     
    6462    private String errormime; 
    6563 
    66     private int width; 
    67  
    68     private int height; 
     64    //private int width; 
     65 
     66    //private int height; 
    6967 
    7068    private String version; 
     
    7472    private boolean transparent; 
    7573 
    76     private boolean debugheaders; 
     74    //private boolean debugheaders; 
    7775 
    7876    //protected transient GridCalculator[] gridCalc; 
     
    200198        log = LogFactory.getLog(org.geowebcache.layer.wms.WMSLayer.class); 
    201199        curWmsURL = 0; 
     200         
     201        // The following is currently hardcoded in the grid objects 
    202202        //zoomStart = 0; 
    203203        //zoomStop = 20; 
     204        //width = 256; 
     205        //height = 256; 
     206         
    204207        request = "GetMap"; 
    205208        errormime = ErrorMime.vnd_ogc_se_inimage.getMimeType(); 
    206         width = 256; 
    207         height = 256; 
    208209        version = "1.1.0"; 
    209210        transparent = true; 
     
    338339            } 
    339340 
    340             metaTile.createTiles(width, height, useJAI); 
     341            metaTile.createTiles(GridCalculator.TILEPIXELS, GridCalculator.TILEPIXELS, useJAI); 
    341342 
    342343            int[][] gridPositions = metaTile.getTilesGridPositions(); 
     
    901902    } 
    902903 
    903     public int getWidth() { 
    904         return this.width; 
    905     } 
    906  
    907     public int getHeight() { 
    908         return this.height; 
    909     } 
     904    //public int getWidth() { 
     905    //    return this.width; 
     906    //} 
     907 
     908    <