001 package railo.runtime.util; 002 003 import java.io.IOException; 004 import java.io.UnsupportedEncodingException; 005 import java.net.MalformedURLException; 006 import java.net.URL; 007 008 import org.apache.commons.httpclient.Header; 009 import org.apache.commons.httpclient.HttpMethod; 010 import org.apache.commons.httpclient.methods.RequestEntity; 011 012 import railo.runtime.exp.PageException; 013 014 public interface HTTPUtil { 015 016 /** 017 * Field <code>ACTION_POST</code> 018 */ 019 public static final short ACTION_POST=0; 020 021 /** 022 * Field <code>ACTION_GET</code> 023 */ 024 public static final short ACTION_GET=1; 025 026 /** 027 * Field <code>STATUS_OK</code> 028 */ 029 public static final int STATUS_OK=200; 030 //private static final String NO_MIMETYPE="Unable to determine MIME type of file."; 031 032 /** 033 * make a http requst to given url 034 * @param url 035 * @param username 036 * @param password 037 * @param timeout 038 * @param charset 039 * @param useragent 040 * @param proxyserver 041 * @param proxyport 042 * @param proxyuser 043 * @param proxypassword 044 * @return resulting inputstream 045 * @throws IOException 046 */ 047 public HttpMethod get(URL url, String username, String password, int timeout, 048 String charset, String useragent, 049 String proxyserver, int proxyport, String proxyuser, 050 String proxypassword, Header[] headers) throws IOException; 051 052 053 public HttpMethod put(URL url, String username, String password, int timeout, 054 String charset, String useragent, 055 String proxyserver, int proxyport, String proxyuser, 056 String proxypassword, Header[] headers, RequestEntity body) throws IOException ; 057 058 public HttpMethod delete(URL url, String username, String password, int timeout, 059 String charset, String useragent, 060 String proxyserver, int proxyport, String proxyuser, 061 String proxypassword, Header[] headers) throws IOException ; 062 063 public HttpMethod head(URL url, String username, String password, int timeout, 064 String charset, String useragent, 065 String proxyserver, int proxyport, String proxyuser, 066 String proxypassword, Header[] headers) throws IOException ; 067 068 069 public RequestEntity toRequestEntity(Object value) throws PageException; 070 071 /** 072 * cast a string to a url 073 * @param strUrl string represent a url 074 * @return url from string 075 * @throws MalformedURLException 076 */ 077 public URL toURL(String strUrl, int port) throws MalformedURLException; 078 079 080 /** 081 * cast a string to a url 082 * @param strUrl string represent a url 083 * @return url from string 084 * @throws MalformedURLException 085 */ 086 public URL toURL(String strUrl) throws MalformedURLException; 087 088 public Object toURL(HttpMethod httpMethod); 089 090 /** 091 * translate a string in the URLEncoded Format 092 * @param str String to translate 093 * @param charset charset used for translation 094 * @return encoded String 095 * @throws UnsupportedEncodingException 096 */ 097 public String encode(String str, String charset) throws UnsupportedEncodingException; 098 099 /** 100 * translate a url encoded string to a regular string 101 * @param str encoded string 102 * @param charset charset used 103 * @return raw string 104 * @throws UnsupportedEncodingException 105 */ 106 public String decode(String str, String charset) throws UnsupportedEncodingException; 107 }