rubylet-rack-handler 2.0.0.pre1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Common Ground Publishing
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.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0.pre1
@@ -0,0 +1,39 @@
1
+ require 'rack/handler'
2
+
3
+ class Rack::Handler::Rubylet
4
+ def self.run(app, options)
5
+ klass = case (options[:Engine] || 'jetty')
6
+ when 'tomcat'
7
+ require 'rubylet/rack/handler/tomcat'
8
+ Rubylet::Rack::Handler::Tomcat
9
+ when 'jetty'
10
+ require 'rubylet/rack/handler/jetty'
11
+ Rubylet::Rack::Handler::Jetty
12
+ else
13
+ raise ArgumentError, "unknown engine #{options[:Engine]}"
14
+ end
15
+
16
+ @server = klass.new(app, options)
17
+ @server.start
18
+ @server.join
19
+ end
20
+
21
+ def self.shutdown
22
+ @server.stop
23
+ end
24
+
25
+ def self.valid_options
26
+ {
27
+ 'ContextPath=PATH' =>
28
+ 'The context path at which to serve the app (defualt "/")',
29
+ 'Threads=NUM' =>
30
+ 'Number of threads in the threadpool (default unlimited)',
31
+ 'NoPublic' =>
32
+ 'Set to disable static file serving (default is to serve)',
33
+ 'PublicRoot=PATH' =>
34
+ 'Path to static files (default "public")'
35
+ }
36
+ end
37
+ end
38
+
39
+ Rack::Handler.register('rubylet', Rack::Handler::Rubylet)
@@ -0,0 +1,4 @@
1
+ require 'rack/handler'
2
+ require 'rubylet/jetty'
3
+
4
+ Rack::Handler.register('rubylet/jetty', Rubylet::Jetty)
@@ -0,0 +1,6 @@
1
+ require 'rack/handler'
2
+ require 'rubylet/jetty'
3
+
4
+ # rack 1.2's handler loading is a bit different. Commandline: rackup -s RubyletJetty
5
+ Rack::Handler::RubyletJetty = Rubylet::Jetty
6
+
@@ -0,0 +1,113 @@
1
+ require 'mini_aether'
2
+
3
+ MiniAether.setup do
4
+ jetty_version = '8.1.8.v20121106'
5
+
6
+ jar "org.eclipse.jetty:jetty-servlet:#{jetty_version}"
7
+
8
+ # slf4j_version = '1.7.2'
9
+ # jar "org.slf4j:slf4j-api:#{slf4j_version}"
10
+ # jar "org.slf4j:slf4j-simple:#{slf4j_version}"
11
+ end
12
+
13
+ require 'rubylet/rack'
14
+
15
+ module Rubylet; module Rack; module Handler; end; end; end
16
+
17
+ class Rubylet::Rack::Handler::Jetty
18
+ Server = Java::OrgEclipseJettyServer::Server
19
+ ServletContextHandler = Java::OrgEclipseJettyServlet::ServletContextHandler
20
+ ServletHolder = Java::OrgEclipseJettyServlet::ServletHolder
21
+ FilterHolder = Java::OrgEclipseJettyServlet::FilterHolder
22
+ SelectChannelConnector = Java::OrgEclipseJettyServerNio::SelectChannelConnector
23
+ ExecutorThreadPool = Java::OrgEclipseJettyUtilThread::ExecutorThreadPool
24
+ DefaultServlet = Java::OrgEclipseJettyServlet::DefaultServlet
25
+ DispatcherType = Java::JavaxServlet::DispatcherType
26
+
27
+ attr_reader :options
28
+
29
+ def initialize(app, options)
30
+ @app = app
31
+ @options = options
32
+ @contextPath = options[:ContextPath] || '/'
33
+
34
+ @context = ServletContextHandler.new(ServletContextHandler::SESSIONS)
35
+ @context.setContextPath(@contextPath)
36
+
37
+ add_public unless options[:NoPublic]
38
+ add_rack_app
39
+
40
+ @server = make_server
41
+ @server.setHandler(@context)
42
+ end
43
+
44
+ def start
45
+ @server.start
46
+ end
47
+
48
+ def join
49
+ @server.join
50
+ end
51
+
52
+ def stop
53
+ @server.stop
54
+ end
55
+
56
+ private
57
+
58
+ # order matters here; rubylet must be added *after* the
59
+ # default servlet so that rubylet has priority
60
+ def add_rack_app
61
+ ServletHolder.new(Rubylet::Rack::Servlet.new(@app)).tap do |holder|
62
+ @context.addServlet holder, '/*'
63
+ end
64
+ end
65
+
66
+ def make_server
67
+ server = Server.new
68
+
69
+ connector = SelectChannelConnector.new
70
+ connector.setPort options[:Port].to_i
71
+ connector.setHost options[:Host]
72
+ server.addConnector connector
73
+
74
+ if options[:Threads]
75
+ pool = ExecutorThreadPool.new(options[:Threads].to_i,
76
+ options[:Threads].to_i,
77
+ 0)
78
+ server.setThreadPool pool
79
+ end
80
+
81
+ server
82
+ end
83
+
84
+ # Add a filter that will serve static files if they exist, or
85
+ # continue down the chain (to the rack app).
86
+ #
87
+ # Installs a default servlet at '/*', so must be called before
88
+ # the rack app's servlet is added so rack will take priority.
89
+ def add_public
90
+ public_root = options[:PublicRoot] || 'public'
91
+
92
+ FilterHolder.new(Rubylet::StaticFileFilter.new).tap do |holder|
93
+ holder.setInitParameter 'resourceBase', public_root
94
+ types = [DispatcherType::ASYNC,
95
+ DispatcherType::ERROR,
96
+ DispatcherType::FORWARD,
97
+ DispatcherType::INCLUDE,
98
+ DispatcherType::REQUEST]
99
+ dispatches = Java::JavaUtil::EnumSet.of(*types)
100
+ @context.addFilter holder, '/*', dispatches
101
+ end
102
+
103
+ ServletHolder.new('default', DefaultServlet.new).tap do |holder|
104
+ {
105
+ 'acceptRanges' => true,
106
+ 'welcomeServlets' => false,
107
+ 'gzip' => true,
108
+ 'resourceBase' => public_root
109
+ }.each { |k,v| holder.setInitParameter(k, v.to_s) }
110
+ @context.addServlet holder, '/*'
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,55 @@
1
+ require 'mini_aether'
2
+
3
+ MiniAether.setup do
4
+ group 'org.apache.tomcat' do
5
+ version '7.0.37' do
6
+ jar 'tomcat-catalina'
7
+ jar 'tomcat-coyote'
8
+ end
9
+ end
10
+ end
11
+
12
+ require 'rubylet/rack'
13
+
14
+ # well this is dumb...
15
+ module Rubylet; module Rack; module Handler; end; end; end
16
+
17
+ class Rubylet::Rack::Handler::Tomcat
18
+ java_import org.apache.catalina.startup.Tomcat
19
+
20
+ attr_reader :options
21
+
22
+ def initialize(app, options)
23
+ @app = app
24
+ @options = options
25
+
26
+ contextPath = options[:ContextPath] || '/'
27
+ publicRoot = options[:PublicRoot] || 'public'
28
+ baseDir = options[:BaseDir] || 'tmp'
29
+
30
+ @server = Tomcat.new
31
+ @server.setPort(options[:Port].to_i)
32
+ @server.setBaseDir(File.expand_path(baseDir))
33
+
34
+ context = @server.addContext(contextPath, File.expand_path(publicRoot))
35
+ Tomcat.addServlet(context, 'rack', Rubylet::Rack::Servlet.new(@app))
36
+ context.addServletMapping('/*', 'rack')
37
+
38
+ # // Add AprLifecycleListener
39
+ # StandardServer server = (StandardServer)tomcat.getServer();
40
+ # AprLifecycleListener listener = new AprLifecycleListener();
41
+ # server.addLifecycleListener(listener);
42
+ end
43
+
44
+ def start
45
+ @server.start
46
+ end
47
+
48
+ def join
49
+ @server.getServer.await
50
+ end
51
+
52
+ def stop
53
+ @server.stop
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubylet-rack-handler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 6
5
+ version: 2.0.0.pre1
6
+ platform: java
7
+ authors:
8
+ - Patrick Mahoney
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mini_aether
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 0.0.7
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.7
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: rubylet-rack
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.0.0.pre1
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.0.0.pre1
43
+ none: false
44
+ prerelease: false
45
+ type: :runtime
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: !binary |-
53
+ MA==
54
+ none: false
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: !binary |-
60
+ MA==
61
+ none: false
62
+ prerelease: false
63
+ type: :development
64
+ - !ruby/object:Gem::Dependency
65
+ name: minitest-matchers
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: !binary |-
71
+ MA==
72
+ none: false
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: !binary |-
78
+ MA==
79
+ none: false
80
+ prerelease: false
81
+ type: :development
82
+ - !ruby/object:Gem::Dependency
83
+ name: rack
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: !binary |-
89
+ MA==
90
+ none: false
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: !binary |-
96
+ MA==
97
+ none: false
98
+ prerelease: false
99
+ type: :development
100
+ - !ruby/object:Gem::Dependency
101
+ name: rake
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: !binary |-
107
+ MA==
108
+ none: false
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: !binary |-
114
+ MA==
115
+ none: false
116
+ prerelease: false
117
+ type: :development
118
+ - !ruby/object:Gem::Dependency
119
+ name: version
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: !binary |-
125
+ MA==
126
+ none: false
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: !binary |-
132
+ MA==
133
+ none: false
134
+ prerelease: false
135
+ type: :development
136
+ description: ''
137
+ email:
138
+ - pat@polycrystal.org
139
+ executables: []
140
+ extensions: []
141
+ extra_rdoc_files: []
142
+ files:
143
+ - VERSION
144
+ - MIT-LICENSE
145
+ - lib/rack/handler/rubylet.rb
146
+ - lib/rack/handler/rubylet_jetty.rb
147
+ - lib/rack/handler/rubylet/jetty.rb
148
+ - lib/rubylet/rack/handler/jetty.rb
149
+ - lib/rubylet/rack/handler/tomcat.rb
150
+ homepage:
151
+ licenses: []
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ segments:
161
+ - 0
162
+ hash: 2
163
+ version: !binary |-
164
+ MA==
165
+ none: false
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - !binary |-
169
+ Pg==
170
+ - !ruby/object:Gem::Version
171
+ version: 1.3.1
172
+ none: false
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 1.8.24
176
+ signing_key:
177
+ specification_version: 3
178
+ summary: Rack::Handler using rubylet-rack and Jetty or Tomcat
179
+ test_files: []