001 package railo.commons.net.http; 002 003 import java.io.IOException; 004 import java.net.URL; 005 006 import railo.commons.io.TemporaryStream; 007 import railo.commons.io.res.Resource; 008 import railo.commons.net.http.httpclient3.HTTPEngine3Impl; 009 import railo.commons.net.http.httpclient4.HTTPEngine4Impl; 010 import railo.runtime.net.proxy.ProxyData; 011 012 public class HTTPEngine { 013 014 private static final boolean use4=true; 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 public static final int MAX_REDIRECT = 15; 033 034 035 /** 036 * Constant value for HTTP Status Code "moved Permanently 301" 037 */ 038 public static final int STATUS_REDIRECT_MOVED_PERMANENTLY=301; 039 /** 040 * Constant value for HTTP Status Code "Found 302" 041 */ 042 public static final int STATUS_REDIRECT_FOUND=302; 043 /** 044 * Constant value for HTTP Status Code "see other 303" 045 */ 046 public static final int STATUS_REDIRECT_SEE_OTHER=303; 047 048 049 050 051 public static HTTPResponse get(URL url) throws IOException { 052 if(use4) return HTTPEngine4Impl.get(url, null, null, -1,MAX_REDIRECT, null, null, null, null); 053 return HTTPEngine3Impl.get(url, null, null, -1,MAX_REDIRECT, null, null, null, null); 054 } 055 056 public static HTTPResponse post(URL url) throws IOException { 057 if(use4) return HTTPEngine4Impl.post(url, null, null, -1,MAX_REDIRECT, null, null, null, null); 058 return HTTPEngine3Impl.post(url, null, null, -1,MAX_REDIRECT, null, null, null, null); 059 } 060 061 public static HTTPResponse get(URL url, String username, String password, long timeout, int maxRedirect, 062 String charset, String useragent,ProxyData proxy, Header[] headers) throws IOException { 063 if(use4) return HTTPEngine4Impl.get(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers); 064 return HTTPEngine3Impl.get(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers); 065 } 066 067 public static HTTPResponse post(URL url, String username, String password, long timeout, int maxRedirect, 068 String charset, String useragent, ProxyData proxy, Header[] headers) throws IOException { 069 if(use4) return HTTPEngine4Impl.post(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers); 070 return HTTPEngine3Impl.post(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers); 071 } 072 073 public static HTTPResponse head(URL url, String username, String password, int timeout, int maxRedirect, 074 String charset, String useragent,ProxyData proxy, Header[] headers) throws IOException { 075 if(use4) return HTTPEngine4Impl.head(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers); 076 return HTTPEngine3Impl.head(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers); 077 } 078 079 public static HTTPResponse put(URL url, String username, String password, int timeout, int maxRedirect, 080 String mimetype,String charset, String useragent,ProxyData proxy, Header[] headers, Object body) throws IOException { 081 if(use4) return HTTPEngine4Impl.put(url, username, password, timeout, maxRedirect, mimetype,charset, useragent, proxy, headers,body); 082 return HTTPEngine3Impl.put(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers,body); 083 } 084 085 public static HTTPResponse delete(URL url, String username, String password, int timeout, int maxRedirect, 086 String charset, String useragent,ProxyData proxy, Header[] headers) throws IOException { 087 if(use4) return HTTPEngine4Impl.delete(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers); 088 return HTTPEngine3Impl.delete(url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers); 089 } 090 091 public static Header header(String name, String value) { 092 if(use4) return HTTPEngine4Impl.header(name, value); 093 return HTTPEngine3Impl.header(name, value); 094 } 095 096 public static Entity getEmptyEntity(String contentType) { 097 if(use4) return HTTPEngine4Impl.getEmptyEntity(contentType); 098 return HTTPEngine3Impl.getEmptyEntity(contentType); 099 } 100 101 public static Entity getByteArrayEntity(byte[] barr, String contentType) { 102 if(use4) return HTTPEngine4Impl.getByteArrayEntity(barr,contentType); 103 return HTTPEngine3Impl.getByteArrayEntity(barr,contentType); 104 } 105 106 public static Entity getTemporaryStreamEntity(TemporaryStream ts, String contentType) { 107 if(use4) return HTTPEngine4Impl.getTemporaryStreamEntity(ts,contentType); 108 return HTTPEngine3Impl.getTemporaryStreamEntity(ts,contentType); 109 } 110 111 public static Entity getResourceEntity(Resource res, String contentType) { 112 if(use4) return HTTPEngine4Impl.getResourceEntity(res,contentType); 113 return HTTPEngine3Impl.getResourceEntity(res,contentType); 114 } 115 116 117 }