Changeset 368

Show
Ignore:
Timestamp:
09/02/08 15:18:46 (4 months ago)
Author:
arneke
Message:

Improved error handling (ie. tell someone) for SeedResource?

Files:
1 modified

Legend:

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

    r360 r368  
    3030import org.restlet.data.Request; 
    3131import org.restlet.data.Response; 
     32import org.restlet.data.Status; 
    3233import org.restlet.ext.json.JsonRepresentation; 
    3334import org.restlet.resource.Representation; 
     
    9899    @Override 
    99100    public void post(Representation entity) { 
    100         log.info("Received seed request from  " 
    101                 + getRequest().getClientInfo().getAddress()); 
    102  
     101         
     102        String remoteAdr = getRequest().getClientInfo().getAddress(); 
     103         
     104        if(entity == null) { 
     105            String message = "Request from " + remoteAdr + " did not specify MIME type" 
     106                    + " of the document posted. Please specify application/xml " 
     107                    + " or application/json"; 
     108            writeError(Status.CLIENT_ERROR_BAD_REQUEST, message); 
     109        } else { 
     110            log.info("Received seed request from  " 
     111                    + getRequest().getClientInfo().getAddress()); 
     112        } 
     113         
    103114        try { 
    104115            String text = entity.getText(); 
     
    150161            TileLayerDispatcher tlDispatch = RESTDispatcher.getInstance().getTileLayerDispatcher(); 
    151162            TileLayer tl = tlDispatch.getTileLayer(rq.getLayerName()); 
     163             
    152164            if(tl != null) { 
    153165                RESTDispatcher.getInstance().getExecutor().submit(new MTSeeder(new SeedTask(rq,tl))); 
    154166            } else { 
    155                 throw new GeoWebCacheException("Unknown layer " + rq.getLayerName()); 
    156             } 
     167                writeError(Status.CLIENT_ERROR_BAD_REQUEST, "Unknown layer " + rq.getLayerName()); 
     168            } 
     169             
    157170        } catch (IOException ioex) { 
    158             log.error("Exception occured while unmarshalling SeedRequest from XML"); 
     171            writeError(Status.SERVER_ERROR_INTERNAL, ioex.getMessage()); 
    159172        } catch (GeoWebCacheException gwce) { 
    160             log.error(gwce.getMessage()); 
     173            writeError(Status.SERVER_ERROR_INTERNAL, gwce.getMessage()); 
    161174        } 
    162175    } 
     
    182195    } 
    183196 
     197    private void writeError(Status status, String message) { 
     198        log.error(message); 
     199        this.getResponse().setStatus(status, message); 
     200    } 
    184201}