Package org.jruby.rack

Examples of org.jruby.rack.RackApplicationFactory


    public void init(ServletConfig config) {
        if(config.getServletContext().getAttribute(RackApplicationFactory.RACK_CONTEXT) == null){  
            System.out.println("setup rails application via jruby-rack - started . . .");
            ServletContext ctx = config.getServletContext();
            ServletRackConfig rackConfig = new RestyServletRackConfig(ctx);
            final RackApplicationFactory fac = new SharedRackApplicationFactory(new RailsRackApplicationFactory());
            ctx.setAttribute(RackApplicationFactory.FACTORY, fac);
            ServletRackContext rackContext = new ServletRackContext(rackConfig);
            ctx.setAttribute(RackApplicationFactory.RACK_CONTEXT, rackContext);
            try {
                fac.init(rackContext);
                System.out.println("setup rails application via jruby-rack - done . . .");
            } catch (Exception ex) {
                ctx.log("Error: application initialization failed", ex);
            }
        }
View Full Code Here


    }

    @Override
    public Ruby getRuntime() throws IllegalStateException, UnsupportedOperationException {
        // obtain JRuby runtime from JRuby-Rack :
        final RackApplicationFactory appFactory = getRackFactory();
        if ( appFactory == null ) {
            final String message =
                    RackApplicationFactory.class.getName() + " not yet initialized - " +
                    "seems this listener is executing before the " +
                    "RackServletContextListener / RailsSevletContextListener !";
            log("[" + getClass().getName() + "] " + message);
            throw new IllegalStateException(message);
        }
        final RackApplication app;
        try {
            app = appFactory.getApplication();
        }
        catch (RackException e) {
            throw new UnsupportedOperationException(e); // rack/rails initialization failure
        }
        if ( app == null ) {
View Full Code Here

        subject.startup();
    }
   
    @Test
    public void startsUpWithRackFactoryAndWorkerScriptSet() {
        RackApplicationFactory applicationFactory = newMockRackApplicationFactory( null );
        when( servletContext.getAttribute( "rack.factory" ) ).thenReturn( applicationFactory );
        when( mockServletContext().getInitParameter( "jruby.worker.script" ) ).thenReturn( "nil" );

        subject.startup();
View Full Code Here

        verify( servletContext ).getInitParameter( "jruby.worker.script" );
    }

    @Test
    public void startsUpWithRackFactoryAndWorkerScriptPathSet() throws UnsupportedEncodingException {
        RackApplicationFactory applicationFactory = newMockRackApplicationFactory( null );
        when( servletContext.getAttribute( "rack.factory" ) ).thenReturn( applicationFactory );
        when( mockServletContext().getInitParameter( "jruby.worker.script.path" ) ).thenReturn( "/path/worker.rb" );
        InputStream inputStream = new ByteArrayInputStream( "nil".getBytes("UTF-8") );
        when( mockServletContext().getResourceAsStream("/path/worker.rb") ).thenReturn( inputStream );
       
View Full Code Here

   
    @Test
    public void usesRuntimeFromRackApplication() {
        final Ruby runtime = Ruby.newInstance();
        RackApplication application = newMockRackApplication( runtime );
        RackApplicationFactory applicationFactory = newMockRackApplicationFactory( application );
        when( servletContext.getAttribute( "rack.factory" ) ).thenReturn( applicationFactory );
        //when( mockServletContext().getInitParameter( "jruby.worker.script" ) ).thenReturn( "nil" );

        assertSame(runtime, subject.getRuntime());
    }
View Full Code Here

    }

    @Test // an "integration" test
    public void spawnsRubyExecutionInAThread() throws InterruptedException {

        RackApplicationFactory applicationFactory = newMockRackApplicationFactory( null );
        when( mockServletContext().getAttribute( "rack.factory" ) ).thenReturn( applicationFactory );
        when( mockServletContext().getInitParameter( WorkerManager.SCRIPT_KEY ) ).thenReturn(
                "puts 'hello from a jruby worker'\n" +
                "require 'java'\n" +
                "Java::JavaLang::System.setProperty('WorkerContextListenerTest', 'set_from_jruby')"
View Full Code Here

*/
public class RailsServletContextListener extends RackServletContextListener {
   
    @Override
    protected RackApplicationFactory newApplicationFactory(RackConfig config) {
        final RackApplicationFactory factory = new RailsRackApplicationFactory();
        final Integer maxRuntimes = config.getMaximumRuntimes();
        // TODO maybe after Rails 4 is out switch to shared by default as well !
        if ( maxRuntimes != null && maxRuntimes.intValue() == 1 ) {
            return new SharedRackApplicationFactory(factory);
        }
View Full Code Here

TOP

Related Classes of org.jruby.rack.RackApplicationFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.