Changeset 376

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

Cleaning up, removing servletPrefix

Location:
trunk/geowebcache/src/main
Files:
3 removed
1 modified

Legend:

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

    r370 r376  
    4949 
    5050    public static final String TYPE_SERVICE = "service"; 
    51  
    52     //public static final String TYPE_SEED = "seed"; 
    53  
     51     
    5452    public static final String TYPE_TRUNCATE = "truncate"; 
    5553     
     
    5755     
    5856    public static final String TYPE_DEMO = "demo"; 
    59      
    60     //WebApplicationContext context = null; 
    61  
    62     private String servletPrefix = null; 
    6357 
    6458    private TileLayerDispatcher tileLayerDispatcher = null; 
     
    9185     */ 
    9286    public void setServletPrefix(String servletPrefix) { 
    93         this.servletPrefix = servletPrefix; 
     87        //this.servletPrefix = servletPrefix; 
     88        log.warn("Ignored setServletPrefix("+servletPrefix+")"); 
    9489    } 
    9590 
     
    141136            HttpServletResponse response) throws Exception { 
    142137 
    143         //context = (WebApplicationContext) getApplicationContext(); 
    144  
    145138        // Break the request into components, {type, service name} 
    146139        String[] requestComps = null; 
    147140        try { 
    148             requestComps = parseRequest(request.getRequestURI()); 
     141            String normalizedURI = request.getRequestURI().replaceFirst(request.getContextPath(), ""); 
     142            requestComps = parseRequest(normalizedURI); 
     143            //requestComps = parseRequest(request.getRequestURI()); 
    149144        } catch (GeoWebCacheException gwce) { 
    150145            writeError(response, 400, gwce.getMessage()); 
     
    160155                handleDemoRequest(requestComps[1],request, response);    
    161156            } else { 
    162                 writeError(response, 404, "Unknow path: " + requestComps[0]); 
     157                writeError(response, 404, "Unknown path: " + requestComps[0]); 
    163158            } 
    164159        } catch (Exception e) { 
     
    187182        String[] retStrs = new String[2]; 
    188183        String[] splitStr = servletPath.split("/"); 
    189         // This string should start with / , so the first hit will be "" 
    190  
    191         if (servletPrefix != null) { 
    192             if (log.isDebugEnabled()) { 
    193                 if (splitStr[0].equals(servletPrefix)) { 
    194                     log.info("Matched servlet prefix " + servletPrefix 
    195                             + " to request"); 
    196                 } else { 
    197                     log.error("Servlet prefix " + servletPrefix 
    198                             + " does not match " + splitStr[0]); 
    199                 } 
    200             } 
    201             if (splitStr.length < 4) { 
    202                 throw new GeoWebCacheException("Unable to parse " + servletPath 
    203                         + " given prefix " + servletPrefix); 
    204             } 
    205             retStrs[0] = splitStr[3]; 
    206             if(splitStr.length > 4) { 
    207                 retStrs[1] = splitStr[4]; 
    208             } 
    209         } else { 
    210             if (splitStr.length < 3) { 
    211                 throw new GeoWebCacheException("Unable to parse " + servletPath); 
    212             } 
    213             if (splitStr.length == 3) { 
    214                 retStrs[0] = splitStr[2]; 
    215             } else { 
    216                 retStrs[0] = splitStr[2]; 
    217                 retStrs[1] = splitStr[3]; 
    218             } 
     184         
     185        retStrs[0] = splitStr[1]; 
     186        if(splitStr.length > 2) { 
     187            retStrs[1] = splitStr[2]; 
    219188        } 
    220189        return retStrs; 
     
    313282        Service service = (Service) services.get(serviceStr); 
    314283        if (service == null) { 
     284            if(serviceStr == null || serviceStr.length() == 0) { 
     285                serviceStr = ", try service/<name of service>"; 
     286            } else { 
     287                serviceStr = " \""+ serviceStr + "\""; 
     288            } 
    315289            throw new GeoWebCacheException( 
    316                     "Unable to find handler for service " + serviceStr); 
     290                    "Unable to find handler for service" + serviceStr); 
    317291        } 
    318292        return service; 
     
    330304     *            the actual error message, human readable 
    331305     */ 
    332     private void writeError(HttpServletResponse response, int httpCode, 
     306    private static void writeError(HttpServletResponse response, int httpCode, 
    333307            String errorMsg) { 
    334308 
    335         response.setContentType("text/plain"); 
     309        response.setContentType("text/html"); 
    336310        response.setStatus(httpCode); 
    337311 
     
    342316        log.debug(errorMsg); 
    343317 
     318        errorMsg =  
     319                "<html><body>\n" 
     320                +"<a id=\"logo\" href=\"http://geowebcache.org\">"  
     321                +"<img src=\"http://geowebcache.org/trac/chrome/site/geowebcache_logo.png\"" 
     322                +"height=\"100\" width=\"353\" border=\"0\"/>" 
     323                +"</a>\n" 
     324                +"<h4>"+httpCode+": "+errorMsg+"</h4>" 
     325                +"</body></html>\n"; 
     326         
    344327        try { 
    345328            OutputStream os = response.getOutputStream();