- Revision
- 95
- Author
- mward
- Date
- 2007-05-28 00:22:09 -0500 (Mon, 28 May 2007)
Log Message
wrapping request and session in Waffle::WebContext so that they behave like normal ruby Hash instance
Modified Paths
Diff
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/DefaultActionMethodResponseHandler.java (94 => 95)
--- trunk/core/src/main/java/org/codehaus/waffle/action/DefaultActionMethodResponseHandler.java 2007-05-27 21:46:13 UTC (rev 94) +++ trunk/core/src/main/java/org/codehaus/waffle/action/DefaultActionMethodResponseHandler.java 2007-05-28 05:22:09 UTC (rev 95) @@ -54,6 +54,7 @@ viewDispatcher.dispatch(request, response, view); } else if (returnValue instanceof Exception) { Exception exception = (Exception) returnValue; + // todo log this occurance response.setStatus(HttpServletResponse.SC_BAD_REQUEST); handleResponse(response, exception.getMessage()); } else {
Modified: trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java (94 => 95)
--- trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java 2007-05-27 21:46:13 UTC (rev 94) +++ trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java 2007-05-28 05:22:09 UTC (rev 95) @@ -23,9 +23,9 @@ Ruby runtime = rubyObject.getRuntime(); // inject following onto the controller - JavaEmbedUtils.invokeMethod(runtime, rubyObject, "request=", new HttpServletRequest[] {request}, Object.class); JavaEmbedUtils.invokeMethod(runtime, rubyObject, "response=", new HttpServletResponse[] {response}, Object.class); - JavaEmbedUtils.invokeMethod(runtime, rubyObject, "session=", new HttpSession[] {request.getSession(false)}, Object.class); + JavaEmbedUtils.invokeMethod(runtime, rubyObject, "__set_request", new IRubyObject[] {JavaEmbedUtils.javaToRuby(runtime, request)}, Object.class); + JavaEmbedUtils.invokeMethod(runtime, rubyObject, "__set_session", new HttpSession[] {request.getSession(false)}, Object.class); // inspect rubyObject instance variables ... resolve values from (params, req, session, application) ... and set them onto the instance
Modified: trunk/core/src/main/ruby/waffle.rb (94 => 95)
--- trunk/core/src/main/ruby/waffle.rb 2007-05-27 21:46:13 UTC (rev 94) +++ trunk/core/src/main/ruby/waffle.rb 2007-05-28 05:22:09 UTC (rev 95) @@ -1,20 +1,66 @@ # This is still a work in progress module Waffle + + ## + # This is a generic class for making HttpServletRequest's, HttpSession's and ServletContext's to act like Hash's + class WebContext < Hash + + def initialize(context) + @__context = context + attribute_names = @__context.get_attribute_names + + while(attribute_names.hasMoreElements) + name = attribute_names.nextElement + + self[name.to_s] = @__context.get_attribute(name) if name.is_a? Symbol + self[name] = @__context.get_attribute(name) unless name.is_a? Symbol + end + end + + def []=(key, value) + @__context.set_attribute(key.to_s, value) if key.is_a? Symbol + @__context.set_attribute(key, value) unless key.is_a? Symbol + super + end + + def [](key) + return super(key.to_s) if key.is_a? Symbol + + return super(key) + end + + def method_missing(symbol, *args) + @__context.send(symbol, *args) + end + end + module Controller + attr_accessor :response # todo the setters for this should be hidden? + attr_reader :request, :session - # the setters for these should be hidden (i.e. __request=, __response=, __session=)? - attr_accessor :request, :response, :session + def __set_request(request) + @request = WebContext.new(request) + end + def __set_session(session) + @session = WebContext.new(session) + end + def __pico_container=(pico) @@__pico_container = pico end def method_missing(symbol, *args) if symbol.to_s =~ /^find_/ - key = symbol.to_s.gsub(/^find_/, '') - return @@__pico_container.getComponentInstance(key) + key = symbol.to_s + key = key[5..key.length] + component = @@__pico_container.getComponentInstance(key) + + return component unless component.nil? end + + super(symbol, *args) end end
Modified: trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/JRubyRegistrar.java (94 => 95)
--- trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/JRubyRegistrar.java 2007-05-27 21:46:13 UTC (rev 94) +++ trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/JRubyRegistrar.java 2007-05-28 05:22:09 UTC (rev 95) @@ -19,16 +19,25 @@ @Override public void application() { registerInstance("chicago", "bears"); + String script = "class FooBar\n" + " def index\n" + - " \"HELLO WORLD from the index method #{find_chicago}\"\n" + + " request[:foo] = 'bar'\n" + + " session[:bar] = 'foo'\n" + + " p session\n" + + " begin\n" + + " \"HELLO WORLD from the index method \nlook up from pico: #{find_chicago} \nrequest: #{request} \nsession: #{session} \n#{session['waffle.session.container']} \"\n" + + " rescue Exception => e\n" + + " return e\n" + + " end\n" + " end\n" + " def bar\n" + " \"HELLO WORLD #{request.local_name} #{request.local_port} \"\n" + " end\n" + "end\n"; + // TODO ... update Registrar to have a "registerRubyScript(key, String)" .. and registerRubyScriptLocation(folder) ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("foo_bar", script); picoRegistrar.registerComponentAdapter(componentAdapter); }
To unsubscribe from this list please visit:
