private String mapLocation(String location) { Map<String, List<String>> mappings = site.getMappings(); String bestMatch = ""; String prefix = null; for (Iterator<Entry<String, List<String>>> iterator = mappings.entrySet().iterator(); iterator.hasNext(); ) { Entry<String, List<String>> entry = iterator.next(); List<String> candidates = entry.getValue(); for (Iterator<String> candidateIt = candidates.iterator(); candidateIt.hasNext(); ) { String candidate = candidateIt.next(); if (location.startsWith(candidate) && candidate.length() > bestMatch.length()) { bestMatch = candidate; prefix = entry.getKey(); } } } if (prefix != null) { String reverseMappedPath = prefix + location.substring(bestMatch.length()); try { URI pathlessRequestURI = new URI( request.getScheme(), null, request.getServerName(), request.getServerPort(), null, null, null); return pathlessRequestURI.toString() + reverseMappedPath; } catch (URISyntaxException t) { // best effort System.err.println(t); } } return location; }