/** * @param realpath path to this servlet's dir in webapps (typically nding in WEB-INF) * @param which parameter name to check: typically a relative path * @param dfalt for parameter * @return The absolute path froom the which directory(ending in '/'). */ private String getCachedString(String realpath, String which, String dfalt) { String dir = getInitParameter(which); if(dir == null) dir = dfalt; if(HTTPUtil.isAbsolutePath(dir)) dir = HTTPUtil.canonicalpath(dir); else dir = HTTPUtil.relpath(dir); dir = HTTPUtil.canonjoin(realpath,dir); if (!dir.endsWith("/")) dir += "/"; return (dir); }
protected TestCase(String filename, boolean overwrite, String target) { super(null); this.filename = HTTPUtil.canonicalpath(filename); this.status = ""; this.overwrite = overwrite; this.target = HTTPUtil.canonicalpath(HTTPUtil.nullify(target)); try { this.file = HTTPUtil.readbinaryfile(new File(filename)); } catch (IOException ioe) { throw new IllegalArgumentException(ioe); } }
/** * Convert path to add a leading '/'; assumes canonical. * * @param path convert this path * @return absolute version */ static public String abspath(String path) { if(path == null) return "/"; StringBuilder b = new StringBuilder(path); canonicalpath(b); if(b.charAt(0) == '/') b.deleteCharAt(0); if(b.charAt(0) != '/' || !hasDriveLetter(b)) b.insert(0, '/'); return b.toString(); }
static String getCanonicalURL(String legalurl) { if(legalurl == null) return null; int index = legalurl.indexOf('?'); if(index >= 0) legalurl = legalurl.substring(0, index); // remove any trailing extension //index = legalurl.lastIndexOf('.'); //if(index >= 0) legalurl = legalurl.substring(0,index); return HTTPUtil.canonicalpath(legalurl); }
static AuthScope uriToAuthScope(String surl) throws HTTPException { try { URI uri = HTTPUtil.parseToURI(surl); return uriToAuthScope(uri); } catch (URISyntaxException e) { throw new HTTPException(e); } }
URI uri; try { uri = HTTPUtil.parseToURI(proxyurl); } catch (URISyntaxException e) { throw new IllegalArgumentException("Bad proxy URL: " + proxyurl); String[] pieces = upw.split("[:]"); if(pieces.length == 2 && HTTPUtil.nullify(pieces[0]) != null && HTTPUtil.nullify(pieces[1]) != null) { user = pieces[0]; pwd = pieces[1];
url = HTTPUtil.nullify(url); if(url == null && session != null) url = session.getSessionURI(); this.userinfo = HTTPUtil.nullify(this.methodurl.getUserInfo()); if(this.userinfo != null) { if(!TESTING) this.methodurl = HTTPUtil.uriExclude(this.methodurl, HTTPUtil.URIPart.USERINFO);
static public byte[] readbinaryfile(File f) throws IOException { try (FileInputStream fis = new FileInputStream(f)) { return readbinaryfile(fis); } }
public Map<String, String> getReply() { // Compute expected reply String replytarget = this.target; replytarget = HTTPUtil.canonjoin(downloaddir, replytarget); if(replytarget == null) replytarget = ""; Map<String, String> map = new HashMap<String, String>(); map.put("download", replytarget); return map; }
static synchronized public void setGlobalCompression(String compressors) { if(globalsettings.get(Prop.COMPRESSION) != null) removeGlobalCompression(); String compresslist = checkCompressors(compressors); if(HTTPUtil.nullify(compresslist) == null) throw new IllegalArgumentException("Bad compressors: " + compressors); globalsettings.put(Prop.COMPRESSION, compresslist); HttpResponseInterceptor hrsi; if(compresslist.contains("gzip")) { hrsi = new GZIPResponseInterceptor(); rspintercepts.add(hrsi); } if(compresslist.contains("deflate")) { hrsi = new DeflateResponseInterceptor(); rspintercepts.add(hrsi); } }
/** * @param path to test * @return true if path is absolute */ static public boolean isAbsolutePath(String path) { return (path != null && path.length() > 0 && (path.charAt(0) == '/' || hasDriveLetter(path))); }
public Map<Prop, Object> mergedSettings() { Map<Prop, Object> merged; synchronized (this) {// keep coverity happy //Merge Settings; merged = HTTPUtil.merge(globalsettings, localsettings); } return Collections.unmodifiableMap(merged); }
attach3file = HTTPUtil.fillTempFile("attach3.txt", ATTACHTEXT); attach3file.deleteOnExit();
/** * Convert path to use '/' consistently and * to remove any trailing '/' * * @param path convert this path * @return canonicalized version */ static public String canonicalpath(String path) { if(path == null) return null; StringBuilder b = new StringBuilder(path); canonicalpath(b); return b.toString(); }
URI u = null; try { u = HTTPUtil.parseToURI(surl); } catch (URISyntaxException e) { return null;
byte[] tmp = HTTPUtil.readbinaryfile((InputStream) field.value); body = new ByteArrayBody(tmp, field.name); } catch (IOException ioe) {
static public void canonicalpath(StringBuilder s) { if(s == null || s.length() == 0) return; int index = 0; // "\\" -> "/" for(; ; ) { index = s.indexOf("\\", index); if(index < 0) break; s.replace(index, index + 1, "/"); } boolean isabs = (s.charAt(0) == '/'); // remember for(; ; ) { // kill any leading '/'s if(s.length() == 0 || s.charAt(0) != '/') break; s.deleteCharAt(0); } // Do we have drive letter? boolean hasdrive = hasDriveLetter(s); if(hasdrive) s.setCharAt(0, Character.toLowerCase(s.charAt(0))); while(s.length() > 0 && s.charAt(s.length() - 1) == '/') { s.deleteCharAt(s.length() - 1); // kill any trailing '/'s } // Add back leading '/', if any if(!hasdrive && isabs) s.insert(0, '/'); }
prefix = HTTPUtil.canonicalpath(prefix); suffix = HTTPUtil.canonicalpath(suffix); StringBuilder result = new StringBuilder(); result.append(prefix);
escapedURI = HTTPUtil.parseToURI(url); } catch (URISyntaxException e) { throw new RuntimeException(e);
/** * Convert path to remove any leading '/' or drive letter assumes canonical. * * @param path convert this path * @return relatived version */ static public String relpath(String path) { if(path == null) return null; StringBuilder b = new StringBuilder(path); canonicalpath(b); if(b.length() > 0) { if(b.charAt(0) == '/') b.deleteCharAt(0); if(hasDriveLetter(b)) b.delete(0, 2); } return b.toString(); }