jetty-rackup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jason Rogers
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,89 @@
1
+ jetty-rackup
2
+ ============
3
+
4
+ For the newer projects we decided to switch from MRI to JRuby. One of
5
+ the bigger questions is certainly the deployment.
6
+
7
+ Reading and trying all the warbler stuff, we had enough of packaging and
8
+ wanted to do it the Ruby/Sinatra way (with a standalone script, where
9
+ one can consciously start things like `run Sinatra::Application` from a
10
+ rackup script).
11
+
12
+ Embedding jetty is also mentioned in the jetty documentation "For many
13
+ applications, HTTP is just another interface protocol. Jetty can easily
14
+ be embedded in such applications and products without adopting a WWW
15
+ centric application architecture."
16
+
17
+ So here is the solution:
18
+
19
+ * write your Rack based application as usual
20
+ * create a rackup script `config.ru` as usual; there is more information in
21
+ the official tutorial
22
+ <http://wiki.github.com/rack/rack/tutorial-rackup-howto>
23
+ * install jetty-rackup (this project), e.g.
24
+ `git clone git://github.com/geekq/jetty-rackup.git`
25
+ * from your application folder run `jetty-rackup`. You can also provide
26
+ a path to non-standard rackup-script and the desired port
27
+ number for the server to run.
28
+
29
+ Now your application runs inside jetty servlet container. Enjoy!
30
+
31
+
32
+ Example
33
+ -------
34
+ $cat config.ru
35
+
36
+ #\ -p 8765
37
+ require 'rubygems'
38
+ gem 'sinatra', '~> 0.9.4'
39
+ require './my_app.rb'
40
+ set :run, false # disable built-in sinatra web server
41
+ set :environment, :development
42
+ set :base_url, 'http://xxtrial' # custom application option
43
+ run Sinatra::Application
44
+
45
+
46
+ Binaries
47
+ --------
48
+ The jetty and jruby-rack binaries are now provided for your convinience.
49
+ But you can also download a different version of them, if you wish, from
50
+ the official web sites of the respective projects:
51
+
52
+ * <http://jetty.codehaus.org/jetty/>
53
+ * <http://kenai.com/projects/jruby-rack/pages/Home>
54
+
55
+
56
+ FAQ
57
+ ---
58
+
59
+ > What's the best way to set max memory?
60
+
61
+ jruby -J-Xmx2048m /usr/local/lib/jetty-rackup/jetty-rackup config.ru
62
+
63
+ See also
64
+ --------
65
+ For Rails deployment you may prefer jetty-rails
66
+ <http://jetty-rails.rubyforge.org/>
67
+
68
+
69
+ Copyright
70
+ ---------
71
+ (c) 2009 Vodafone Group Services GmbH
72
+
73
+
74
+ Author
75
+ ------
76
+ Vladimir Dobriakov, innoQ Deutschland GmbH
77
+ <http://blog.geekq.net>, <http://www.innoq.com/blog/vd>
78
+
79
+ With contributions by [Leandro Silva](http://leandrosilva.com.br/) and
80
+ [Jason Rogers](http://wordsanddeeds.org/)
81
+
82
+ Further Credits
83
+ ---------------
84
+ * Michal Hantl for the first working jetty based 'Hello world'
85
+ application. <http://michal.hantl.cz/>
86
+ * Nick Sieger for the explanation of servlet context init params and of
87
+ course jruby-rack itself. <http://blog.nicksieger.com/>
88
+
89
+
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "jetty-rackup"
8
+ gem.summary = %Q{Rack + Jetty = Retty}
9
+ gem.description = %Q{Runs a rack conform application inside jetty web server}
10
+ gem.email = "jacaetevha@gmail.com"
11
+ gem.homepage = "http://github.com/jacaetevha/jetty-rackup"
12
+ gem.authors = ["Jason Rogers"]
13
+ # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "jetty-rackup #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
4
+
5
+ require 'jetty-rackup'
@@ -0,0 +1,17 @@
1
+ require 'sinatra'
2
+
3
+ # If you want to have auto reload in development mode (what is sweet)
4
+ # you can uncomment this following lines:
5
+ #
6
+ configure :development do
7
+ Sinatra::Application.reset! # to reload routes and its contents
8
+ use Rack::Reloader # to reload required every files
9
+ end
10
+
11
+ get '/?' do
12
+ "hello"
13
+ end
14
+
15
+ get '/:message/?' do |message|
16
+ "hello #{message}"
17
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'app'
3
+
4
+ set :run, false # disable built-in sinatra web server
5
+ set :environment, :development
6
+
7
+ run Sinatra::Application
@@ -0,0 +1 @@
1
+ Hello from HTML
@@ -0,0 +1,21 @@
1
+ require 'sinatra'
2
+
3
+ # If you want to have auto reload in development mode (what is sweet)
4
+ # you can uncomment this following lines:
5
+ #
6
+ # configure :development do
7
+ # Sinatra::Application.reset! # to reload routes and its contents
8
+ # use Rack::Reloader # to reload required every files
9
+ # end
10
+
11
+ get '/some' do
12
+ import 'Some' # using import
13
+
14
+ some = Some.new
15
+ "From WEB-INF/classes: #{some.say}"
16
+ end
17
+
18
+ get '/other' do
19
+ other = Java::Other.new # or directly by the Java "namespace"
20
+ "From WEB-INF/lib: #{other.say}"
21
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'app'
3
+
4
+ set :run, false # disable built-in sinatra web server
5
+ set :environment, :development
6
+
7
+ run Sinatra::Application
@@ -0,0 +1,3 @@
1
+ public class Other {
2
+ public String say = "Hello Other";
3
+ }
@@ -0,0 +1,3 @@
1
+ public class Some {
2
+ public String say = "Hello Some";
3
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env jruby
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+ require 'rack'
6
+ require 'java'
7
+ require 'optparse'
8
+
9
+ require 'jetty-rackup/server'
10
+ require 'jetty-rackup/bootstrap'
@@ -0,0 +1,119 @@
1
+ #
2
+ # Option parsing is based on the original rackup script.
3
+ #
4
+
5
+ automatic = false
6
+ server_type = nil
7
+ env = "development"
8
+ pid = nil
9
+ options = {:Port => 9292, :Host => "0.0.0.0", :AccessLog => []}
10
+
11
+ opts = OptionParser.new("", 24, ' ') { |opts|
12
+ opts.banner = "Usage: jetty_rackup [ruby options] [rack options] [rackup config]"
13
+
14
+ opts.separator ""
15
+ opts.separator "Ruby options:"
16
+
17
+ lineno = 1
18
+ opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line|
19
+ eval line, TOPLEVEL_BINDING, "-e", lineno
20
+ lineno += 1
21
+ }
22
+
23
+ opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
24
+ $DEBUG = true
25
+ }
26
+ opts.on("-w", "--warn", "turn warnings on for your script") {
27
+ $-w = true
28
+ }
29
+
30
+ opts.on("-I", "--include PATH",
31
+ "specify $LOAD_PATH (may be used more than once)") { |path|
32
+ $LOAD_PATH.unshift(*path.split(":"))
33
+ }
34
+
35
+ opts.on("-r", "--require LIBRARY",
36
+ "require the library, before executing your script") { |library|
37
+ require library
38
+ }
39
+
40
+ opts.separator ""
41
+ opts.separator "Rack options:"
42
+ opts.on("-s", "--server SERVER", "serve using SERVER (only jetty is supported)") { |s|
43
+ server_type = s
44
+ }
45
+
46
+ opts.on("-o", "--host HOST", "listen on HOST (default: 0.0.0.0)") { |host|
47
+ options[:Host] = host
48
+ }
49
+
50
+ opts.on("-p", "--port PORT", "use PORT (default: 9292)") { |port|
51
+ options[:Port] = port.to_i
52
+ }
53
+
54
+ opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
55
+ env = e
56
+ }
57
+
58
+ opts.on("-D", "--daemonize", "run daemonized in the background - does not work with JRuby - please use a wrapper shell script") { |d|
59
+ daemonize = d ? true : false
60
+ }
61
+
62
+ opts.on("-P", "--pid FILE", "file to store PID (default: rack.pid)") { |f|
63
+ pid = File.expand_path(f)
64
+ }
65
+
66
+ opts.separator ""
67
+ opts.separator "Common options:"
68
+
69
+ opts.on_tail("-h", "--help", "Show this message") do
70
+ puts opts
71
+ exit
72
+ end
73
+
74
+ opts.on_tail("--version", "Show version") do
75
+ puts "Rack #{Rack.version}"
76
+ exit
77
+ end
78
+
79
+ opts.parse! ARGV
80
+ }
81
+
82
+ require 'pp' if $DEBUG
83
+
84
+ config = ARGV[0] || "config.ru"
85
+ if !File.exist? config
86
+ abort "configuration #{config} not found"
87
+ end
88
+
89
+ if config =~ /\.ru$/
90
+ rackup = File.read(config)
91
+ if rackup[/^#\\(.*)/]
92
+ opts.parse! $1.split(/\s+/)
93
+ end
94
+ #rackup << "\n set :environment, :#{env}" if env
95
+ rackup.gsub! /set :environment, .*?$/, "set :environment, :#{env}" if env
96
+ else
97
+ abort "configuration file with .ru extention expected, was '#{config}'"
98
+ end
99
+
100
+ #
101
+ # Boot the server.
102
+ #
103
+
104
+ unless server = Rack::Handler.get(server_type)
105
+ server = Rack::Handler::Jetty
106
+ end
107
+
108
+ p server if $DEBUG
109
+
110
+ if $DEBUG
111
+ pp app
112
+ pp rackup
113
+ end
114
+
115
+ puts "---- rackup"
116
+ puts rackup
117
+ puts "---- "
118
+
119
+ server.run rackup, options
@@ -0,0 +1,40 @@
1
+ class Rack::Handler::Jetty
2
+ def self.run(rackup_content, options={})
3
+ Dir["#{File.dirname(__FILE__)}/../../jars/*.jar"].each { |jar| require jar }
4
+
5
+ include_class 'javax.servlet.http.HttpServlet'
6
+ include_class 'org.mortbay.jetty.Server'
7
+ include_class 'org.mortbay.jetty.servlet.Context'
8
+ include_class 'org.mortbay.jetty.servlet.ServletHolder'
9
+ include_class 'org.jruby.rack.servlet.ServletRackContext'
10
+ include_class 'org.mortbay.jetty.handler.ResourceHandler'
11
+ include_class 'org.mortbay.jetty.handler.DefaultHandler'
12
+ include_class 'org.mortbay.jetty.handler.HandlerList'
13
+ include_class 'org.mortbay.jetty.handler.ContextHandlerCollection'
14
+ include_class 'org.mortbay.jetty.servlet.DefaultServlet'
15
+
16
+ jetty = org.mortbay.jetty.Server.new options[:Port]
17
+
18
+ context = org.mortbay.jetty.servlet.Context.new(nil, "/", org.mortbay.jetty.servlet.Context::NO_SESSIONS)
19
+ context.add_filter("org.jruby.rack.RackFilter", "/*", org.mortbay.jetty.Handler::DEFAULT)
20
+ context.set_resource_base(File.dirname(__FILE__))
21
+ context.add_event_listener(org.jruby.rack.RackServletContextListener.new)
22
+
23
+ context.set_init_params(java.util.HashMap.new(
24
+ 'org.mortbay.jetty.servlet.Default.relativeResourceBase' => '/public',
25
+ 'rackup' => rackup_content,
26
+ 'jruby.max.runtimes' => '1'))
27
+
28
+ context.add_servlet(org.mortbay.jetty.servlet.ServletHolder.new(
29
+ org.mortbay.jetty.servlet.DefaultServlet.new), "/")
30
+
31
+ JRuby.runtime.jruby_class_loader.add_url(java.io.File.new("WEB-INF/classes").to_url)
32
+
33
+ Dir["WEB-INF/lib/**/*.jar"].each do |jar|
34
+ JRuby.runtime.jruby_class_loader.add_url(java.io.File.new(jar).to_url)
35
+ end
36
+
37
+ jetty.set_handler(context)
38
+ jetty.start
39
+ end
40
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'jetty-rackup'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestJettyRackup < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jetty-rackup
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Jason Rogers
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-12 00:00:00 +01:00
14
+ default_executable: jetty-rackup
15
+ dependencies: []
16
+
17
+ description: Runs a rack conform application inside jetty web server
18
+ email: jacaetevha@gmail.com
19
+ executables:
20
+ - jetty-rackup
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.markdown
26
+ files:
27
+ - LICENSE
28
+ - README.markdown
29
+ - Rakefile
30
+ - VERSION
31
+ - bin/jetty-rackup
32
+ - examples/just_ruby/app.rb
33
+ - examples/just_ruby/config.ru
34
+ - examples/just_ruby/public/hello.html
35
+ - examples/using_java/WEB-INF/classes/Some.class
36
+ - examples/using_java/WEB-INF/lib/other.jar
37
+ - examples/using_java/app.rb
38
+ - examples/using_java/config.ru
39
+ - examples/using_java/java/Other.java
40
+ - examples/using_java/java/Some.java
41
+ - jars/core-3.1.1.jar
42
+ - jars/jetty-6.1.14.jar
43
+ - jars/jetty-plus-6.1.14.jar
44
+ - jars/jetty-util-6.1.14.jar
45
+ - jars/jruby-rack-0.9.5.jar
46
+ - jars/jsp-2.1.jar
47
+ - jars/jsp-api-2.1.jar
48
+ - jars/servlet-api-2.5-6.1.14.jar
49
+ - lib/jetty-rackup.rb
50
+ - lib/jetty-rackup/bootstrap.rb
51
+ - lib/jetty-rackup/server.rb
52
+ - test/helper.rb
53
+ - test/test_jetty-rackup.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/jacaetevha/jetty-rackup
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.5.0
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Rack + Jetty = Retty
82
+ test_files:
83
+ - examples/just_ruby/app.rb
84
+ - examples/using_java/app.rb
85
+ - test/helper.rb
86
+ - test/test_jetty-rackup.rb