Mercurial Hosting > luan
annotate src/luan/modules/url/LuanUrl.java @ 1085:a04da9a3e9eb
improve url delete error handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 19 Dec 2016 01:05:10 -0700 |
parents | 6a87d51ae0ed |
children | 4aab4dd3ac9c |
rev | line source |
---|---|
725
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
1 package luan.modules.url; |
722 | 2 |
3 import java.io.InputStream; | |
4 import java.io.InputStreamReader; | |
5 import java.io.OutputStream; | |
6 import java.io.Reader; | |
7 import java.io.IOException; | |
8 import java.io.UnsupportedEncodingException; | |
9 import java.net.URL; | |
10 import java.net.URLConnection; | |
11 import java.net.HttpURLConnection; | |
12 import java.net.URLEncoder; | |
13 import java.util.Map; | |
14 import java.util.HashMap; | |
15 import java.util.List; | |
16 import java.util.Base64; | |
733
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
17 import luan.Luan; |
722 | 18 import luan.LuanState; |
19 import luan.LuanTable; | |
20 import luan.LuanJavaFunction; | |
21 import luan.LuanException; | |
725
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
22 import luan.modules.IoLuan; |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
23 import luan.modules.Utils; |
722 | 24 |
25 | |
26 public final class LuanUrl extends IoLuan.LuanIn { | |
725
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
27 |
722 | 28 private static enum Method { GET, POST, DELETE } |
29 | |
30 private URL url; | |
31 private Method method = Method.GET; | |
32 private Map headers; | |
725
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
33 private String content = null; |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
34 private MultipartClient multipart = null; |
733
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
35 private int timeout = 0; |
722 | 36 |
725
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
37 public LuanUrl(LuanState luan,URL url,LuanTable options) throws LuanException { |
722 | 38 this.url = url; |
39 if( options != null ) { | |
40 Map map = options.asMap(luan); | |
41 String methodStr = getString(map,"method"); | |
42 if( methodStr != null ) { | |
43 methodStr = methodStr.toUpperCase(); | |
44 try { | |
45 this.method = Method.valueOf(methodStr); | |
46 } catch(IllegalArgumentException e) { | |
47 throw new LuanException( "invalid method: "+methodStr ); | |
48 } | |
49 } | |
723 | 50 Map headerMap = getMap(luan,map,"headers"); |
51 if( headerMap != null ) { | |
52 headers = new HashMap(); | |
53 for( Object hack : headerMap.entrySet() ) { | |
54 Map.Entry entry = (Map.Entry)hack; | |
55 String key = (String)entry.getKey(); | |
56 Object val = entry.getValue(); | |
57 String name = toHttpHeaderName(key); | |
58 if( val instanceof String ) { | |
59 headers.put(name,val); | |
60 } else { | |
61 if( !(val instanceof LuanTable) ) | |
62 throw new LuanException( "header '"+key+"' must be string or table" ); | |
63 LuanTable t = (LuanTable)val; | |
64 if( !t.isList() ) | |
65 throw new LuanException( "header '"+key+"' table must be list" ); | |
66 headers.put(name,t.asList()); | |
67 } | |
68 } | |
69 } | |
722 | 70 Map auth = getMap(luan,map,"authorization"); |
71 if( auth != null ) { | |
723 | 72 if( headers!=null && headers.containsKey("Authorization") ) |
73 throw new LuanException( "can't define authorization with header 'Authorization' defined" ); | |
722 | 74 String user = getString(auth,"user"); |
75 String password = getString(auth,"password"); | |
76 if( !auth.isEmpty() ) | |
77 throw new LuanException( "unrecognized authorization options: "+auth ); | |
78 StringBuilder sb = new StringBuilder(); | |
79 if( user != null ) | |
80 sb.append(user); | |
81 sb.append(':'); | |
82 if( password != null ) | |
83 sb.append(password); | |
84 String val = "Basic " + Base64.getEncoder().encodeToString(sb.toString().getBytes()); | |
85 if( headers == null ) | |
86 headers = new HashMap(); | |
87 headers.put("Authorization",val); | |
88 } | |
89 Map params = getMap(luan,map,"parameters"); | |
726
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
90 String enctype = getString(map,"enctype"); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
91 if( enctype != null ) { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
92 if( !enctype.equals("multipart/form-data") ) |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
93 throw new LuanException( "unrecognized enctype: "+enctype ); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
94 if( this.method!=Method.POST ) |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
95 throw new LuanException( "multipart/form-data can only be used with POST" ); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
96 if( params==null ) |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
97 throw new LuanException( "multipart/form-data requires parameters" ); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
98 if( params.isEmpty() ) |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
99 throw new LuanException( "multipart/form-data parameters can't be empty" ); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
100 multipart = new MultipartClient(params); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
101 } |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
102 else if( params != null ) { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
103 StringBuilder sb = new StringBuilder(); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
104 for( Object hack : params.entrySet() ) { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
105 Map.Entry entry = (Map.Entry)hack; |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
106 String key = (String)entry.getKey(); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
107 Object val = entry.getValue(); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
108 String keyEnc = encode(key); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
109 if( val instanceof String ) { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
110 and(sb); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
111 sb.append( keyEnc ).append( '=' ).append( encode((String)val) ); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
112 } else { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
113 if( !(val instanceof LuanTable) ) |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
114 throw new LuanException( "parameter '"+key+"' must be string or table" ); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
115 LuanTable t = (LuanTable)val; |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
116 if( !t.isList() ) |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
117 throw new LuanException( "parameter '"+key+"' table must be list" ); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
118 for( Object obj : t.asList() ) { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
119 if( !(obj instanceof String) ) |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
120 throw new LuanException( "parameter '"+key+"' values must be strings" ); |
722 | 121 and(sb); |
726
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
122 sb.append( keyEnc ).append( '=' ).append( encode((String)obj) ); |
722 | 123 } |
124 } | |
726
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
125 } |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
126 if( this.method==Method.POST ) { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
127 content = sb.toString(); |
780
6a87d51ae0ed
allow parameters for HTTP DELETE
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
128 } else { |
726
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
129 String urlS = this.url.toString(); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
130 if( urlS.indexOf('?') == -1 ) { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
131 urlS += '?'; |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
132 } else { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
133 urlS += '&'; |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
134 } |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
135 urlS += sb; |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
136 try { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
137 this.url = new URL(urlS); |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
138 } catch(IOException e) { |
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
139 throw new RuntimeException(e); |
722 | 140 } |
141 } | |
142 } | |
733
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
143 Integer timeout = getInt(map,"time_out"); |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
144 if( timeout != null ) |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
145 this.timeout = timeout; |
722 | 146 if( !map.isEmpty() ) |
147 throw new LuanException( "unrecognized options: "+map ); | |
148 } | |
149 } | |
150 | |
723 | 151 public static String toHttpHeaderName(String luanName) { |
152 luanName = luanName.toLowerCase(); | |
153 StringBuilder buf = new StringBuilder(); | |
154 boolean capitalize = true; | |
155 char[] a = luanName.toCharArray(); | |
156 for( int i=0; i<a.length; i++ ) { | |
157 char c = a[i]; | |
158 if( c == '_' || c == '-' ) { | |
159 a[i] = '-'; | |
160 capitalize = true; | |
161 } else if( capitalize ) { | |
162 a[i] = Character.toUpperCase(c); | |
163 capitalize = false; | |
164 } | |
165 } | |
166 return String.valueOf(a); | |
167 } | |
168 | |
722 | 169 private static void and(StringBuilder sb) { |
170 if( sb.length() > 0 ) | |
171 sb.append('&'); | |
172 } | |
173 | |
174 private static String encode(String s) { | |
175 try { | |
176 return URLEncoder.encode(s,"UTF-8"); | |
177 } catch(UnsupportedEncodingException e) { | |
178 throw new RuntimeException(e); | |
179 } | |
180 } | |
181 | |
182 private static String getString(Map map,String key) throws LuanException { | |
183 Object val = map.remove(key); | |
184 if( val!=null && !(val instanceof String) ) | |
185 throw new LuanException( "parameter '"+key+"' must be a string" ); | |
186 return (String)val; | |
187 } | |
188 | |
733
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
189 private static Integer getInt(Map map,String key) throws LuanException { |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
190 Object val = map.remove(key); |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
191 if( val==null ) |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
192 return null; |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
193 Integer i = Luan.asInteger(val); |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
194 if( i==null ) |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
195 throw new LuanException( "parameter '"+key+"' must be an integer" ); |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
196 return i; |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
197 } |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
198 |
722 | 199 private static LuanTable getTable(Map map,String key) throws LuanException { |
200 Object val = map.remove(key); | |
201 if( val!=null && !(val instanceof LuanTable) ) | |
202 throw new LuanException( "parameter '"+key+"' must be a table" ); | |
203 return (LuanTable)val; | |
204 } | |
205 | |
206 private static Map getMap(LuanState luan,Map map,String key) throws LuanException { | |
207 LuanTable t = getTable(map,key); | |
208 return t==null ? null : t.asMap(luan); | |
209 } | |
210 | |
725
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
211 @Override public InputStream inputStream() throws IOException, LuanException { |
722 | 212 URLConnection con = url.openConnection(); |
733
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
213 if( timeout != 0 ) { |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
214 con.setConnectTimeout(timeout); |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
215 con.setReadTimeout(timeout); |
ffbbe25dab09
add http option time_out
Franklin Schmidt <fschmidt@gmail.com>
parents:
726
diff
changeset
|
216 } |
722 | 217 if( headers != null ) { |
218 for( Object hack : headers.entrySet() ) { | |
219 Map.Entry entry = (Map.Entry)hack; | |
220 String key = (String)entry.getKey(); | |
221 Object val = entry.getValue(); | |
222 if( val instanceof String ) { | |
223 con.addRequestProperty(key,(String)val); | |
224 } else { | |
225 List list = (List)val; | |
226 for( Object obj : list ) { | |
227 con.addRequestProperty(key,(String)obj); | |
228 } | |
229 } | |
230 } | |
231 } | |
232 if( method==Method.GET ) { | |
233 return con.getInputStream(); | |
234 } | |
235 | |
236 HttpURLConnection httpCon = (HttpURLConnection)con; | |
237 | |
238 if( method==Method.DELETE ) { | |
239 httpCon.setRequestMethod("DELETE"); | |
1085
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
240 return getInputStream(httpCon); |
722 | 241 } |
242 | |
243 // POST | |
244 | |
245 // httpCon.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); | |
246 httpCon.setDoOutput(true); | |
247 httpCon.setRequestMethod("POST"); | |
248 | |
725
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
249 OutputStream out; |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
250 if( multipart != null ) { |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
251 out = multipart.write(httpCon); |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
252 } else { |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
253 byte[] post = content.getBytes(); |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
254 // httpCon.setRequestProperty("Content-Length",Integer.toString(post.length)); |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
255 out = httpCon.getOutputStream(); |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
256 out.write(post); |
a741a3a33423
add url support for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
723
diff
changeset
|
257 } |
726
14f136a4641f
use enctype for multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
725
diff
changeset
|
258 out.flush(); |
722 | 259 try { |
1085
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
260 return getInputStream(httpCon); |
722 | 261 } finally { |
262 out.close(); | |
263 } | |
264 } | |
265 | |
1085
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
266 private static InputStream getInputStream(HttpURLConnection httpCon) throws IOException, LuanException { |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
267 try { |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
268 return httpCon.getInputStream(); |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
269 } catch(IOException e) { |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
270 InputStream is = httpCon.getErrorStream(); |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
271 if( is == null ) |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
272 throw e; |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
273 Reader in = new InputStreamReader(is); |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
274 String msg = Utils.readAll(in); |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
275 in.close(); |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
276 throw new LuanException(msg,e); |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
277 } |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
278 } |
a04da9a3e9eb
improve url delete error handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
780
diff
changeset
|
279 |
722 | 280 @Override public String to_string() { |
281 return url.toString(); | |
282 } | |
283 | |
284 @Override public String to_uri_string() { | |
285 return url.toString(); | |
286 } | |
287 /* | |
288 public String post(String postS) throws IOException { | |
289 return new UrlCall(url).post(postS); | |
290 } | |
291 | |
292 @Override public LuanTable table() { | |
293 LuanTable tbl = super.table(); | |
294 try { | |
295 tbl.rawPut( "post", new LuanJavaFunction( | |
296 LuanUrl.class.getMethod( "post", String.class ), this | |
297 ) ); | |
298 } catch(NoSuchMethodException e) { | |
299 throw new RuntimeException(e); | |
300 } | |
301 return tbl; | |
302 } | |
303 */ | |
304 } |