0
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,283

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,283
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript of "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!
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×