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