comparison http/src/luan/modules/http/HttpServicer.java @ 496:c65df5b25932

remove Http.session
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 16 May 2015 20:19:05 -0600
parents 598123096772
children 55f9f74f1e55
comparison
equal deleted inserted replaced
495:598123096772 496:c65df5b25932
76 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http"); 76 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http");
77 HttpServicer lib = new HttpServicer(request,response); 77 HttpServicer lib = new HttpServicer(request,response);
78 try { 78 try {
79 module.put( luan, "request", lib.requestTable() ); 79 module.put( luan, "request", lib.requestTable() );
80 module.put( luan, "response", lib.responseTable() ); 80 module.put( luan, "response", lib.responseTable() );
81 module.put( luan, "session", lib.sessionTable() );
82 /*
83 module.put( "write", new LuanJavaFunction(
84 HttpServicer.class.getMethod( "text_write", LuanState.class, new Object[0].getClass() ), lib
85 ) );
86 */
87 } catch(NoSuchMethodException e) { 81 } catch(NoSuchMethodException e) {
88 throw new RuntimeException(e); 82 throw new RuntimeException(e);
89 } 83 }
90 84
91 luan.call(fn,"<http>"); 85 luan.call(fn,"<http>");
347 HttpServletResponse.class.getMethod( "setStatus", Integer.TYPE ), response 341 HttpServletResponse.class.getMethod( "setStatus", Integer.TYPE ), response
348 ) ); 342 ) );
349 return tbl; 343 return tbl;
350 } 344 }
351 345
352 private LuanTable sessionTable() throws NoSuchMethodException {
353 LuanTable tbl = new LuanTable();
354 LuanTable attributes = new NameMeta() {
355
356 @Override Object get(String name) {
357 return request.getSession().getAttribute(name);
358 }
359
360 @Override protected Iterator keys(LuanTable tbl) {
361 return new EnumerationIterator(request.getSession().getAttributeNames());
362 }
363
364 @Override public boolean canNewindex() {
365 return true;
366 }
367
368 @Override public void __new_index(LuanState luan,LuanTable tbl,Object key,Object val) {
369 if( !(key instanceof String) )
370 throw new IllegalArgumentException("key must be string for session attributes table");
371 String name = (String)key;
372 request.getSession().setAttribute(name,val);
373 }
374
375 @Override protected String type(LuanTable tbl) {
376 return "session.attributes";
377 }
378
379 }.newTable();
380 tbl.rawPut( "attributes", attributes );
381 return tbl;
382 }
383
384 private void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { 346 private void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
385 t.rawPut( method, new LuanJavaFunction(HttpServicer.class.getMethod(method,parameterTypes),this) ); 347 t.rawPut( method, new LuanJavaFunction(HttpServicer.class.getMethod(method,parameterTypes),this) );
386 } 348 }
387 /* 349 /*
388 public void text_write(LuanState luan,Object... args) throws LuanException, IOException { 350 public void text_write(LuanState luan,Object... args) throws LuanException, IOException {