Index: src/main/java/com/sun/grizzly/rails/RailsSelectorThread.java =================================================================== RCS file: /cvs/glassfish/appserv-http-engine/modules/rails/src/main/java/com/sun/grizzly/rails/RailsSelectorThread.java,v retrieving revision 1.2 diff -u -r1.2 RailsSelectorThread.java --- src/main/java/com/sun/grizzly/rails/RailsSelectorThread.java 5 Dec 2006 18:07:34 -0000 1.2 +++ src/main/java/com/sun/grizzly/rails/RailsSelectorThread.java 7 Dec 2006 15:03:37 -0000 @@ -1,167 +1,126 @@ -/* - * The contents of this file are subject to the terms - * of the Common Development and Distribution License - * (the License). You may not use this file except in - * compliance with the License. - * - * You can obtain a copy of the license at - * https://glassfish.dev.java.net/public/CDDLv1.0.html or - * glassfish/bootstrap/legal/CDDLv1.0.txt. - * See the License for the specific language governing - * permissions and limitations under the License. - * - * When distributing Covered Code, include this CDDL - * Header Notice in each file and include the License file - * at glassfish/bootstrap/legal/CDDLv1.0.txt. - * If applicable, add the following below the CDDL Header, - * with the fields enclosed by brackets [] replaced by - * you own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - */ -package com.sun.grizzly.rails; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; - -import com.sun.enterprise.web.connector.grizzly.SelectorThread; -import java.util.logging.Level; - -/** - * @author TAKAI Naoto - */ -public class RailsSelectorThread extends SelectorThread { - /** - * Is Grizzly embedded in GlassFish. - */ - protected static boolean embeddedInGlassFish = false; - - // Are we running embedded or not. - static { - try { - embeddedInGlassFish = (Class.forName("org.apache.coyote.tomcat5.Constants") != null); - } catch (Exception ex) { - ; // Swallow - } - } - - private String configFile = null; - - private String jrubyLib = null; - - private int numberOfRuntime = 5; - - private RubyObjectPool pool = null; - - private String railsRoot = null; - - @Override - public void initEndpoint() throws IOException, InstantiationException { - if (embeddedInGlassFish) { - configFile = System.getProperty("com.sun.aas.instanceRoot") + "/config/rails.xml"; - railsRoot = System.getProperty("com.sun.aas.instanceRoot") + "/applications/rails"; - } - setupSystemProperties(); - initializeRubyRuntime(); - - this.adapter = new RailsAdapter(pool); - - super.initEndpoint(); - } - - public void setConfigFile(String configFile) { - this.configFile = configFile; - } - - public void setNumberOfRuntime(int numberOfRuntime) { - this.numberOfRuntime = numberOfRuntime; - } - - @Override - public synchronized void stopEndpoint() { - pool.stop(); - - super.stopEndpoint(); - } - - protected void initializeRubyRuntime() { - pool = new RubyObjectPool(); - pool.setNumberOfRuntime(numberOfRuntime); - pool.setJrubyLib(jrubyLib); - pool.setRailsRoot(railsRoot); - - try{ - pool.start(); - } catch (Throwable t){ - logger.log(Level.WARNING, t.getMessage()); - } - } - - protected Properties loadConfigFile() { - if (configFile == null) { - throw new IllegalStateException("configFile can not be null."); - } - - FileInputStream stream = null; - Properties properties = new Properties(); - - try { - stream = new FileInputStream(configFile); - properties.loadFromXML(stream); - } catch (FileNotFoundException e) { - throw new IllegalStateException(e.getMessage(), e); - } catch (IOException e) { - throw new IllegalStateException(e.getMessage(), e); - } finally { - try { - stream.close(); - } catch (IOException e) { - } - } - - return properties; - } - - protected void setupSystemProperties() { - Properties configs = loadConfigFile(); - - String jrubyBase = configs.getProperty("jruby.base"); - String jrubyHome = configs.getProperty("jruby.home"); - String jrubyShell = configs.getProperty("jruby.shell"); - String jrubyScript = configs.getProperty("jruby.script"); - - if (jrubyBase == null) { - throw new IllegalStateException("jruby.base can not be null"); - } - if (jrubyHome == null) { - throw new IllegalStateException("jruby.home can not be null"); - } - if (jrubyShell == null) { - jrubyShell = ""; - } - if (jrubyScript == null) { - jrubyScript = ""; - } - System.setProperty("jruby.base", jrubyBase); - System.setProperty("jruby.home", jrubyHome); - System.setProperty("jruby.shell", jrubyShell); - System.setProperty("jruby.script", jrubyScript); - - jrubyLib = configs.getProperty("jruby.lib"); - - System.setProperty("jruby.lib", jrubyLib); - - if (jrubyLib == null) { - throw new IllegalStateException("jruby.lib can not be null"); - } - if (railsRoot == null) { - railsRoot = configs.getProperty("rails.root"); - if (railsRoot == null) { - throw new IllegalStateException("rails.root can not be null"); - } - } - } -} +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the license at + * https://glassfish.dev.java.net/public/CDDLv1.0.html or + * glassfish/bootstrap/legal/CDDLv1.0.txt. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at glassfish/bootstrap/legal/CDDLv1.0.txt. + * If applicable, add the following below the CDDL Header, + * with the fields enclosed by brackets [] replaced by + * you own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + */ +package com.sun.grizzly.rails; + +import java.io.IOException; +import java.util.logging.Level; + +import com.sun.enterprise.web.connector.grizzly.SelectorThread; + +/** + * @author TAKAI Naoto + */ +public class RailsSelectorThread extends SelectorThread { + /** + * Is Grizzly embedded in GlassFish. + */ + protected static boolean embeddedInGlassFish = false; + + // Are we running embedded or not. + static { + try { + embeddedInGlassFish = (Class.forName("org.apache.coyote.tomcat5.Constants") != null); + } catch (Exception ex) { + ; // Swallow + } + } + + private String jrubyLib = null; + + private int numberOfRuntime = 5; + + private RubyObjectPool pool = null; + + private String railsRoot = null; + + public String getRailsRoot() { + return railsRoot; + } + + @Override + public void initEndpoint() throws IOException, InstantiationException { + if (embeddedInGlassFish) { + railsRoot = System.getProperty("com.sun.aas.instanceRoot") + "/applications/rails"; + } + setupSystemProperties(); + initializeRubyRuntime(); + + this.adapter = new RailsAdapter(pool); + + super.initEndpoint(); + } + + public void setNumberOfRuntime(int numberOfRuntime) { + this.numberOfRuntime = numberOfRuntime; + } + + public void setRailsRoot(String railsRoot) { + this.railsRoot = railsRoot; + } + + @Override + public synchronized void stopEndpoint() { + pool.stop(); + + super.stopEndpoint(); + } + + protected void initializeRubyRuntime() { + pool = new RubyObjectPool(); + pool.setNumberOfRuntime(numberOfRuntime); + pool.setJrubyLib(jrubyLib); + pool.setRailsRoot(railsRoot); + + try { + pool.start(); + } catch (Throwable t) { + logger.log(Level.WARNING, t.getMessage()); + } + } + + protected void setupSystemProperties() { + String jrubyBase = System.getProperty("jruby.base"); + String jrubyHome = System.getProperty("jruby.home"); + String jrubyShell = System.getProperty("jruby.shell"); + String jrubyScript = System.getProperty("jruby.script"); + + if (jrubyBase == null) { + throw new IllegalStateException("Set system property jruby.base to JRuby directory"); + } + if (jrubyHome == null) { + System.setProperty("jruby.home", jrubyBase); + } + if (jrubyShell == null) { + System.setProperty("jruby.shell", ""); + } + if (jrubyScript == null) { + System.setProperty("jruby.script", ""); + } + + jrubyLib = System.getProperty("jruby.lib"); + if (jrubyLib == null) { + jrubyLib = jrubyBase + "/lib"; + System.setProperty("jruby.lib", jrubyLib); + } + } +} Index: src/main/java/com/sun/grizzly/rails/standalone/Main.java =================================================================== RCS file: /cvs/glassfish/appserv-http-engine/modules/rails/src/main/java/com/sun/grizzly/rails/standalone/Main.java,v retrieving revision 1.1 diff -u -r1.1 Main.java --- src/main/java/com/sun/grizzly/rails/standalone/Main.java 5 Dec 2006 16:33:57 -0000 1.1 +++ src/main/java/com/sun/grizzly/rails/standalone/Main.java 7 Dec 2006 15:03:37 -0000 @@ -1,43 +1,48 @@ -/* - * The contents of this file are subject to the terms - * of the Common Development and Distribution License - * (the License). You may not use this file except in - * compliance with the License. - * - * You can obtain a copy of the license at - * https://glassfish.dev.java.net/public/CDDLv1.0.html or - * glassfish/bootstrap/legal/CDDLv1.0.txt. - * See the License for the specific language governing - * permissions and limitations under the License. - * - * When distributing Covered Code, include this CDDL - * Header Notice in each file and include the License file - * at glassfish/bootstrap/legal/CDDLv1.0.txt. - * If applicable, add the following below the CDDL Header, - * with the fields enclosed by brackets [] replaced by - * you own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - */ -package com.sun.grizzly.rails.standalone; - -import java.io.IOException; - -import com.sun.grizzly.rails.RailsSelectorThread; - -public class Main { - public static void main(String[] args) throws IOException, InstantiationException { - String config = "src/test/conf/rails.xml"; - if(args.length > 0) - config = args[0]; - - RailsSelectorThread selectorThread = new RailsSelectorThread(); - selectorThread.setConfigFile(config); - selectorThread.setPort(3000); - selectorThread.setNumberOfRuntime(3); - selectorThread.setDisplayConfiguration(true); - selectorThread.initEndpoint(); - selectorThread.startEndpoint(); - } -} +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the license at + * https://glassfish.dev.java.net/public/CDDLv1.0.html or + * glassfish/bootstrap/legal/CDDLv1.0.txt. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at glassfish/bootstrap/legal/CDDLv1.0.txt. + * If applicable, add the following below the CDDL Header, + * with the fields enclosed by brackets [] replaced by + * you own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + */ +package com.sun.grizzly.rails.standalone; + +import java.io.IOException; + +import com.sun.grizzly.rails.RailsSelectorThread; + +public class Main { + public static void main(String[] args) throws IOException, InstantiationException { + String railsRoot = null; + + if(args.length > 0) { + railsRoot = args[0]; + } else { + System.err.println("Usage: java com.sun.grizzly.rails.standalone.Main RAILS_ROOT"); + System.exit(1); + } + + RailsSelectorThread selectorThread = new RailsSelectorThread(); + selectorThread.setRailsRoot(railsRoot); + selectorThread.setPort(3000); + selectorThread.setNumberOfRuntime(3); + selectorThread.setDisplayConfiguration(true); + selectorThread.initEndpoint(); + selectorThread.startEndpoint(); + } +} Index: src/main/resources/dispatch.rb =================================================================== RCS file: src/main/resources/dispatch.rb diff -N src/main/resources/dispatch.rb --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/main/resources/dispatch.rb 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,56 @@ +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the License). You may not use this file except in +# compliance with the License. +# +# You can obtain a copy of the license at +# https://glassfish.dev.java.net/public/CDDLv1.0.html or +# glassfish/bootstrap/legal/CDDLv1.0.txt. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# Header Notice in each file and include the License file +# at glassfish/bootstrap/legal/CDDLv1.0.txt. +# If applicable, add the following below the CDDL Header, +# with the fields enclosed by brackets [] replaced by +# you own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# +require 'cgi/force_nph' +require 'jdk_logger' + +info = $req.getRequestProcessor() +headers = $req.getMimeHeaders() +request_uri = $req.requestURI().to_s + +# RFC3875 The Common Gateway Interface (CGI) Version 1.1 +ENV['AUTH_TYPE'] = $req.getAuthType().to_s +ENV['CONTENT_LENGTH'] = info.getContentLength().to_s +ENV['CONTENT_TYPE'] = $req.getContentType() +ENV['GATEWAY_INTERFACE'] = 'CGI/1.1' +ENV['PATH_INFO'] = request_uri +ENV['PATH_TRANSLATED'] = request_uri.split('?', 2).first +ENV['QUERY_STRING'] = $req.queryString().to_s +ENV['REMOTE_ADDR'] = info.getRemoteAddr() +ENV['REMOTE_HOST'] = $req.remoteHost().to_s +ENV['REMOTE_USER'] = $req.getRemoteUser().to_s +ENV['REQUEST_METHOD'] = info.getMethod() +ENV['SCRIPT_NAME'] = '' +ENV['SERVER_NAME'] = $req.serverName().to_s +ENV['SERVER_PORT'] = $req.getServerPort().to_s +ENV['SERVER_PROTOCOL'] = $req.protocol().to_s +ENV['SERVER_SOFTWARE'] = 'Grizzly/1.0.5' + +for i in 0 ... headers.size + name = headers.getName(i).to_s + value = headers.getValue(i).to_s + ENV['HTTP_' + name.upcase.tr('-','_')] = value +end + +require "dispatcher" + +Dispatcher.dispatch Index: src/main/resources/jdk_logger.rb =================================================================== RCS file: src/main/resources/jdk_logger.rb diff -N src/main/resources/jdk_logger.rb --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/main/resources/jdk_logger.rb 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,41 @@ +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the License). You may not use this file except in +# compliance with the License. +# +# You can obtain a copy of the license at +# https://glassfish.dev.java.net/public/CDDLv1.0.html or +# glassfish/bootstrap/legal/CDDLv1.0.txt. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# Header Notice in each file and include the License file +# at glassfish/bootstrap/legal/CDDLv1.0.txt. +# If applicable, add the following below the CDDL Header, +# with the fields enclosed by brackets [] replaced by +# you own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# +class Logger + def add(severity, message = nil, progname = nil, &block) + severity ||= UNKNOWN + if @logdev.nil? or severity < @level + return true + end + progname ||= @progname + if message.nil? + if block_given? + message = yield + else + message = progname + progname = @progname + end + end + $logger.info(format_message(format_severity(severity), Time.now, progname, message)) + true + end +end Index: src/main/resources/cgi/force_nph.rb =================================================================== RCS file: src/main/resources/cgi/force_nph.rb diff -N src/main/resources/cgi/force_nph.rb --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/main/resources/cgi/force_nph.rb 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,34 @@ +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the License). You may not use this file except in +# compliance with the License. +# +# You can obtain a copy of the license at +# https://glassfish.dev.java.net/public/CDDLv1.0.html or +# glassfish/bootstrap/legal/CDDLv1.0.txt. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# Header Notice in each file and include the License file +# at glassfish/bootstrap/legal/CDDLv1.0.txt. +# If applicable, add the following below the CDDL Header, +# with the fields enclosed by brackets [] replaced by +# you own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# +require 'cgi' + +class CGI + def force_nph_header(options) + options['nph'] = true + options['connection'] = 'close' + __header__(options) + end + + alias_method :__header__, :header + alias_method :header, :force_nph_header +end