Successfully reported this slideshow.
JRuby                                                  Webwith JRuby                  Enterprise Web Application Developme...
Photo by Koichiro Ohba
RubyistStruts
Front ControllerActionServlet             RequestProcessor             Action                                     processA...
Front ControllerActionServlet             RequestProcessor             Action                                     processA...
JRubyRequestControllerStruts               RequestProcessor Rubyclass   RubyActionRequestProcessor  def   process_action_f...
JRubyRequestController.javapublic class JRubyRequestProcessor    extends RequestProcessor {...    @Override    public void...
struts-config.xml<struts-config>...  <controller    processorClass="n.r.s.JRubyRequestProcessor">    <set-property       ke...
JRubyRequestController#init()container = new ScriptingContainer(                  LocalContextScope.THREADSAFE            ...
JRubyRequestController#init()container.put("SERVLET_CONTEXT",              servlet.getServletContext());• ServletContext  ...
JRubyRequestController#init()String path =    moduleConfig.getControllerConfig()                .getProperty("scriptPath")...
JRubyRequestController#init()String[] names =    container.callMethod(requestProcessor,                         "public_me...
JRubyRequestController.java@Overrideprotected ActionForward process...(    HttpServletRequest request...) throws ...{    i...
requestProcessor               JRubyRequsetProcessor                                                  :IRubyObjectprocessA...
JRubyRequestProcessor
SinatraRequestProcessorclass SinatraRequestProcessor  def initialize    @app = SinatraHelloAction.new  end  def process re...
Happy Hacking!     and Good Carling!
JRubyによるエンタープライズweb開発
JRubyによるエンタープライズweb開発
JRubyによるエンタープライズweb開発
JRubyによるエンタープライズweb開発
JRubyによるエンタープライズweb開発
Upcoming SlideShare
Loading in …5
×

JRubyによるエンタープライズweb開発

2,941 views

Published on

Published in: Technology
  • Be the first to comment

JRubyによるエンタープライズweb開発

  1. 1. JRuby Webwith JRuby Enterprise Web Application Development 2010 12 4 Akasaka.rbPhoto by Michael Pick
  2. 2. Photo by Koichiro Ohba
  3. 3. RubyistStruts
  4. 4. Front ControllerActionServlet RequestProcessor Action processActionPerform process execute
  5. 5. Front ControllerActionServlet RequestProcessor Action processActionPerform process execute
  6. 6. JRubyRequestControllerStruts RequestProcessor Rubyclass RubyActionRequestProcessor def process_action_form req, res, mapping # do something end def process_action_perform req, res, action, form, mapping # do something endend
  7. 7. JRubyRequestController.javapublic class JRubyRequestProcessor extends RequestProcessor {... @Override public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException { super.init(servlet, moduleConfig);...
  8. 8. struts-config.xml<struts-config>... <controller processorClass="n.r.s.JRubyRequestProcessor"> <set-property key="scriptPath" value="/WEB-INF/request-processor.rb" /> </controller>...</struts-config>
  9. 9. JRubyRequestController#init()container = new ScriptingContainer( LocalContextScope.THREADSAFE );•• LocalContextScope.THREADSAFE Ruby
  10. 10. JRubyRequestController#init()container.put("SERVLET_CONTEXT", servlet.getServletContext());• ServletContext SERVLET_CONTEXT
  11. 11. JRubyRequestController#init()String path = moduleConfig.getControllerConfig() .getProperty("scriptPath");InputStream stream = servlet.getServletContext() .getResourceAsStream(path);EmbedEvalUnit unit = container.parse(stream, path);requestProcessor = unit.run();• scriptPath requestProcessor
  12. 12. JRubyRequestController#init()String[] names = container.callMethod(requestProcessor, "public_methods", false, String[].class);supportedMethods = new HashSet<String>(Arrays.asList(names));• requestProcessor public_methods false
  13. 13. JRubyRequestController.java@Overrideprotected ActionForward process...( HttpServletRequest request...) throws ...{ if (supportedMethods.contains("process...")){ return container.callMethod( requestProcessor, "process...", new Object[] { request, ... }, ActionForward.class); } else { return super.process... }...
  14. 14. requestProcessor JRubyRequsetProcessor :IRubyObjectprocessActionPerform process_action_perform Ruby
  15. 15. JRubyRequestProcessor
  16. 16. SinatraRequestProcessorclass SinatraRequestProcessor def initialize @app = SinatraHelloAction.new end def process req, res servlet_env = ServletRackEnvironment.new req env = Rack::Handler::LazyEnv.new servlet_env status, header, body = @app.call env.to_hash res.setStatus(status) header.each do |k, v| res.setHeader(k, v) end out = res.getOutputStream out.print(body.join) endend
  17. 17. Happy Hacking! and Good Carling!

×