mizuno 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -0
- data/LICENSE +202 -0
- data/README +33 -0
- data/bin/mizuno +12 -0
- data/lib/java/cometd-api-1.1.0.jar +0 -0
- data/lib/java/cometd-java-server-1.1.0.jar +0 -0
- data/lib/java/jetty-continuation-7.0.2.v20100331.jar +0 -0
- data/lib/java/jetty-http-7.0.2.v20100331.jar +0 -0
- data/lib/java/jetty-io-7.0.2.v20100331.jar +0 -0
- data/lib/java/jetty-jmx-7.0.2.v20100331.jar +0 -0
- data/lib/java/jetty-security-7.0.2.v20100331.jar +0 -0
- data/lib/java/jetty-server-7.0.2.v20100331.jar +0 -0
- data/lib/java/jetty-servlet-7.0.2.v20100331.jar +0 -0
- data/lib/java/jetty-servlets-7.0.2.v20100331.jar +0 -0
- data/lib/java/jetty-util-7.0.2.v20100331.jar +0 -0
- data/lib/java/servlet-api-2.5.jar +0 -0
- data/lib/rack/handler/mizuno.rb +1 -0
- data/lib/rack/handler/mizuno/http_server.rb +64 -0
- data/lib/rack/handler/mizuno/rack_servlet.rb +218 -0
- data/mizuno.gemspec +35 -0
- metadata +84 -0
data/.gitignore
ADDED
|
File without changes
|
data/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Mizuno is a set of Jetty-powered running shoes for JRuby/Rack.
|
|
2
|
+
|
|
3
|
+
To use Mizuno with your Rack app:
|
|
4
|
+
|
|
5
|
+
gem install mizuno
|
|
6
|
+
cd /path/to/my/rack/app
|
|
7
|
+
mizuno
|
|
8
|
+
|
|
9
|
+
...and you're off and running. You don't need to set up a Java web
|
|
10
|
+
container for your Rack application to run under JRuby, because Mizuno
|
|
11
|
+
works just like Mongrel, WEBRick, Thin, or any other standard Rack
|
|
12
|
+
handler.
|
|
13
|
+
|
|
14
|
+
Mizuno is the fastest option for Rack applications on JRuby:
|
|
15
|
+
|
|
16
|
+
Mizuno: 6106.66 req/s (mean)
|
|
17
|
+
Jetty (via jruby-rack): 2011.67 req/s (mean)
|
|
18
|
+
Mongrel: 1479.15 req/sec (mean)
|
|
19
|
+
|
|
20
|
+
Mizuno also supports asynchronous request handling.
|
|
21
|
+
|
|
22
|
+
All the speed comes from Jetty 7; Mizuno just ties it to Rack through
|
|
23
|
+
JRuby's Ruby/Java integration layer.
|
|
24
|
+
|
|
25
|
+
Note that Mizuno is NOT a direct replacement for jruby-rack or Warbler,
|
|
26
|
+
because it doesn't produce WAR files or make any attempt to package a
|
|
27
|
+
Rack application for installation in a Java web container.
|
|
28
|
+
|
|
29
|
+
There's also a few features that I have yet to implement:
|
|
30
|
+
1. Integrate the cometd servlet to provide Comet/Bayeux.
|
|
31
|
+
2. Route Jetty's logs into Rack::Logger.
|
|
32
|
+
3. Add hooks for realtime monitoring of server performance.
|
|
33
|
+
4. Add the ability to run multiple Rack apps in a single JVM.
|
data/bin/mizuno
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# Make sure we're on JRuby.
|
|
4
|
+
raise("Rack::Handler::Mizuno only runs on JRuby.") \
|
|
5
|
+
unless (RUBY_PLATFORM =~ /java/)
|
|
6
|
+
|
|
7
|
+
require 'rack'
|
|
8
|
+
require 'rack/handler/mizuno'
|
|
9
|
+
|
|
10
|
+
server = Rack::Server.new
|
|
11
|
+
server.options[:server] = 'mizuno'
|
|
12
|
+
server.start
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'rack/handler/mizuno/http_server'
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#
|
|
2
|
+
# A Rack handler for Jetty 7.
|
|
3
|
+
#
|
|
4
|
+
# Written by Don Werve <don@madwombat.com>
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
require 'java'
|
|
8
|
+
require 'rack'
|
|
9
|
+
|
|
10
|
+
# Load Jetty JARs.
|
|
11
|
+
jars = File.join(File.dirname(__FILE__), '..', '..', '..', 'java', '*.jar')
|
|
12
|
+
Dir[jars].each { |j| require j }
|
|
13
|
+
|
|
14
|
+
# Load the Rack/Servlet bridge.
|
|
15
|
+
require 'rack/handler/mizuno/rack_servlet'
|
|
16
|
+
|
|
17
|
+
# Have Jetty log to stdout for the time being.
|
|
18
|
+
java.lang.System.setProperty("org.eclipse.jetty.util.log.class",
|
|
19
|
+
"org.eclipse.jetty.util.log.StdErrLog")
|
|
20
|
+
|
|
21
|
+
module Rack::Handler::Mizuno
|
|
22
|
+
class HttpServer
|
|
23
|
+
include_class 'org.eclipse.jetty.server.Server'
|
|
24
|
+
include_class 'org.eclipse.jetty.servlet.ServletContextHandler'
|
|
25
|
+
include_class 'org.eclipse.jetty.servlet.ServletHolder'
|
|
26
|
+
include_class 'org.eclipse.jetty.server.nio.SelectChannelConnector'
|
|
27
|
+
include_class 'org.eclipse.jetty.util.thread.QueuedThreadPool'
|
|
28
|
+
|
|
29
|
+
def self.run(app, options = {})
|
|
30
|
+
# The Jetty server
|
|
31
|
+
server = Server.new
|
|
32
|
+
|
|
33
|
+
# Thread pool
|
|
34
|
+
thread_pool = QueuedThreadPool.new
|
|
35
|
+
thread_pool.min_threads = 5
|
|
36
|
+
thread_pool.max_threads = 50
|
|
37
|
+
server.set_thread_pool(thread_pool)
|
|
38
|
+
|
|
39
|
+
# Connector
|
|
40
|
+
connector = SelectChannelConnector.new
|
|
41
|
+
connector.setPort(options[:Port].to_i)
|
|
42
|
+
connector.setHost(options[:Host])
|
|
43
|
+
server.addConnector(connector)
|
|
44
|
+
|
|
45
|
+
# Servlet context.
|
|
46
|
+
context = ServletContextHandler.new(nil, "/",
|
|
47
|
+
ServletContextHandler::NO_SESSIONS)
|
|
48
|
+
|
|
49
|
+
# The servlet itself.
|
|
50
|
+
servlet = RackServlet.new
|
|
51
|
+
servlet.rackup(app)
|
|
52
|
+
holder = ServletHolder.new(servlet)
|
|
53
|
+
context.addServlet(holder, "/")
|
|
54
|
+
|
|
55
|
+
# Add the context to the server and start.
|
|
56
|
+
server.set_handler(context)
|
|
57
|
+
puts "Started Jetty on #{connector.getHost}:#{connector.getPort}"
|
|
58
|
+
server.start
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Register ourselves with Rack when this file gets loaded.
|
|
64
|
+
Rack::Handler.register 'mizuno', 'Rack::Handler::Mizuno::HttpServer'
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Wraps a Rack application in a Java servlet.
|
|
3
|
+
#
|
|
4
|
+
# Relevant documentation:
|
|
5
|
+
#
|
|
6
|
+
# http://rack.rubyforge.org/doc/SPEC.html
|
|
7
|
+
# http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServlet.html
|
|
8
|
+
#
|
|
9
|
+
module Rack::Handler::Mizuno
|
|
10
|
+
include_class javax.servlet.http.HttpServlet
|
|
11
|
+
|
|
12
|
+
class RackServlet < HttpServlet
|
|
13
|
+
include_class java.io.FileInputStream
|
|
14
|
+
include_class org.eclipse.jetty.continuation.ContinuationSupport
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# Sets the Rack application that handles requests sent to this
|
|
18
|
+
# servlet container.
|
|
19
|
+
#
|
|
20
|
+
def rackup(app)
|
|
21
|
+
@app = app
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# Takes an incoming request (as a Java Servlet) and dispatches it to
|
|
26
|
+
# the rack application setup via [rackup]. All this really involves
|
|
27
|
+
# is translating the various bits of the Servlet API into the Rack
|
|
28
|
+
# API on the way in, and translating the response back on the way
|
|
29
|
+
# out.
|
|
30
|
+
#
|
|
31
|
+
# Also, we implement a common extension to the Rack api for
|
|
32
|
+
# asynchronous request processing. We supply an 'async.callback'
|
|
33
|
+
# parameter in env to the Rack application. If we catch an
|
|
34
|
+
# :async symbol thrown by the app, we initiate a Jetty continuation.
|
|
35
|
+
#
|
|
36
|
+
# When 'async.callback' gets a response with empty headers and an
|
|
37
|
+
# empty body, we declare the async response finished.
|
|
38
|
+
#
|
|
39
|
+
def service(request, response)
|
|
40
|
+
# Turn the ServletRequest into a Rack env hash
|
|
41
|
+
env = servlet_to_rack(request)
|
|
42
|
+
|
|
43
|
+
# Handle asynchronous responses via Servlet continuations.
|
|
44
|
+
continuation = ContinuationSupport.getContinuation(request)
|
|
45
|
+
|
|
46
|
+
# If this is an expired connection, do nothing.
|
|
47
|
+
return if continuation.isExpired
|
|
48
|
+
|
|
49
|
+
# We should never be re-dispatched.
|
|
50
|
+
raise("Request re-dispatched.") unless continuation.isInitial
|
|
51
|
+
|
|
52
|
+
# Add our own special bits to the rack environment so that
|
|
53
|
+
# Rack middleware can have access to the Java internals.
|
|
54
|
+
env['rack.java.servlet'] = true
|
|
55
|
+
env['rack.java.servlet.request'] = request
|
|
56
|
+
env['rack.java.servlet.response'] = response
|
|
57
|
+
env['rack.java.servlet.continuation'] = continuation
|
|
58
|
+
|
|
59
|
+
# Add an callback that can be used to add results to the
|
|
60
|
+
# response asynchronously.
|
|
61
|
+
env['async.callback'] = lambda do |rack_response|
|
|
62
|
+
servlet_response = continuation.getServletResponse
|
|
63
|
+
rack_to_servlet(rack_response, servlet_response) \
|
|
64
|
+
and continuation.complete
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Execute the Rack request.
|
|
68
|
+
catch(:async) do
|
|
69
|
+
rack_response = @app.call(env)
|
|
70
|
+
|
|
71
|
+
# For apps that don't throw :async.
|
|
72
|
+
unless(rack_response[0] == -1)
|
|
73
|
+
# Nope, nothing asynchronous here.
|
|
74
|
+
rack_to_servlet(rack_response, response)
|
|
75
|
+
return
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# If we got here, this is a continuation.
|
|
80
|
+
continuation.suspend(response)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
#
|
|
86
|
+
# Turns a Servlet request into a Rack request hash.
|
|
87
|
+
#
|
|
88
|
+
def servlet_to_rack(request)
|
|
89
|
+
# The Rack request that we will pass on.
|
|
90
|
+
env = Hash.new
|
|
91
|
+
|
|
92
|
+
# Map Servlet bits to Rack bits.
|
|
93
|
+
env['REQUEST_METHOD'] = request.getMethod
|
|
94
|
+
env['QUERY_STRING'] = request.getQueryString.to_s
|
|
95
|
+
env['SERVER_NAME'] = request.getServerName
|
|
96
|
+
env['SERVER_PORT'] = request.getServerPort.to_s
|
|
97
|
+
env['rack.version'] = Rack::VERSION
|
|
98
|
+
env['rack.url_scheme'] = request.getScheme
|
|
99
|
+
env['HTTP_VERSION'] = request.getProtocol
|
|
100
|
+
env["SERVER_PROTOCOL"] = request.getProtocol
|
|
101
|
+
env['REMOTE_ADDR'] = request.getRemoteAddr
|
|
102
|
+
env['REMOTE_HOST'] = request.getRemoteHost
|
|
103
|
+
|
|
104
|
+
# request.getPathInfo seems to be blank, so we're using the URI.
|
|
105
|
+
env['REQUEST_PATH'] = request.getRequestURI
|
|
106
|
+
env['PATH_INFO'] = request.getRequestURI
|
|
107
|
+
env['SCRIPT_NAME'] = ""
|
|
108
|
+
|
|
109
|
+
# Rack says URI, but it hands off a URL.
|
|
110
|
+
env['REQUEST_URI'] = request.getRequestURL.toString
|
|
111
|
+
|
|
112
|
+
# Java chops off the query string, but a Rack application will
|
|
113
|
+
# expect it, so we'll add it back if present
|
|
114
|
+
env['REQUEST_URI'] << "?#{env['QUERY_STRING']}" \
|
|
115
|
+
if env['QUERY_STRING']
|
|
116
|
+
|
|
117
|
+
# JRuby is like the matrix, only there's no spoon or fork().
|
|
118
|
+
env['rack.multiprocess'] = false
|
|
119
|
+
env['rack.multithread'] = true
|
|
120
|
+
env['rack.run_once'] = false
|
|
121
|
+
|
|
122
|
+
# Populate the HTTP headers.
|
|
123
|
+
request.getHeaderNames.each do |header_name|
|
|
124
|
+
header = header_name.upcase.tr('-', '_')
|
|
125
|
+
env["HTTP_#{header}"] = request.getHeader(header_name)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Rack Weirdness: HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH
|
|
129
|
+
# both need to have the HTTP_ part dropped.
|
|
130
|
+
env["CONTENT_TYPE"] = env.delete("HTTP_CONTENT_TYPE") \
|
|
131
|
+
if env["HTTP_CONTENT_TYPE"]
|
|
132
|
+
env["CONTENT_LENGTH"] = env.delete("HTTP_CONTENT_LENGTH") \
|
|
133
|
+
if env["HTTP_CONTENT_LENGTH"]
|
|
134
|
+
|
|
135
|
+
# The input stream is a wrapper around the Java InputStream.
|
|
136
|
+
env['rack.input'] = request.getInputStream.to_io
|
|
137
|
+
|
|
138
|
+
# The output stream defaults to stderr.
|
|
139
|
+
env['rack.errors'] ||= $stderr
|
|
140
|
+
|
|
141
|
+
# All done, hand back the Rack request.
|
|
142
|
+
return(env)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
#
|
|
146
|
+
# Turns a Rack response into a Servlet response; can be called
|
|
147
|
+
# multiple times. Returns true if this is the full request (either
|
|
148
|
+
# a synchronous request or the last part of an async request),
|
|
149
|
+
# false otherwise.
|
|
150
|
+
#
|
|
151
|
+
# Note that keep-alive *only* happens if we get either a pathname
|
|
152
|
+
# (because we can find the length ourselves), or if we get a
|
|
153
|
+
# Content-Length header as part of the response. While we can
|
|
154
|
+
# readily buffer the response object to figure out how long it is,
|
|
155
|
+
# we have no guarantee that we aren't going to be buffering
|
|
156
|
+
# something *huge*.
|
|
157
|
+
#
|
|
158
|
+
# http://docstore.mik.ua/orelly/java-ent/servlet/ch05_03.htm
|
|
159
|
+
#
|
|
160
|
+
def rack_to_servlet(rack_response, response)
|
|
161
|
+
# Split apart the Rack response.
|
|
162
|
+
status, headers, body = rack_response
|
|
163
|
+
|
|
164
|
+
# We assume the request is finished if we got empty headers,
|
|
165
|
+
# an empty body, and we have a committed response.
|
|
166
|
+
finished = (headers.empty? and \
|
|
167
|
+
body.respond_to?(:empty?) and body.empty?)
|
|
168
|
+
return(true) if (finished and response.isCommitted)
|
|
169
|
+
|
|
170
|
+
# No need to send headers again if we've already shipped
|
|
171
|
+
# data out on an async request.
|
|
172
|
+
unless(response.isCommitted)
|
|
173
|
+
# Set the HTTP status code.
|
|
174
|
+
response.setStatus(status)
|
|
175
|
+
|
|
176
|
+
# Did we get a Content-Length header?
|
|
177
|
+
content_length = headers.delete('Content-Length')
|
|
178
|
+
response.setContentLength(content_length.to_i) \
|
|
179
|
+
if content_length
|
|
180
|
+
|
|
181
|
+
# Add all the result headers.
|
|
182
|
+
headers.each { |h, v| response.addHeader(h, v) }
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# How else would we write output?
|
|
186
|
+
output = response.getOutputStream
|
|
187
|
+
|
|
188
|
+
# Turn the body into something nice and Java-y.
|
|
189
|
+
if(body.respond_to?(:to_path))
|
|
190
|
+
# We've been told to serve a file; use FileInputStream to
|
|
191
|
+
# stream the file directly to the servlet, because this
|
|
192
|
+
# is a lot faster than doing it with Ruby.
|
|
193
|
+
file = java.io.File.new(body.to_path)
|
|
194
|
+
|
|
195
|
+
# We set the content-length so we can use Keep-Alive,
|
|
196
|
+
# unless this is an async request.
|
|
197
|
+
response.setContentLength(file.length) \
|
|
198
|
+
unless content_length
|
|
199
|
+
|
|
200
|
+
# Stream the file directly.
|
|
201
|
+
buffer = Java::byte[4096].new
|
|
202
|
+
input_stream = FileInputStream.new(file)
|
|
203
|
+
while((count = input_stream.read(buffer)) != -1)
|
|
204
|
+
output.write(buffer, 0, count)
|
|
205
|
+
end
|
|
206
|
+
input_stream.close
|
|
207
|
+
else
|
|
208
|
+
body.each { |l| output.write(l.to_java_bytes) }
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# Close the body if we're supposed to.
|
|
212
|
+
body.close if body.respond_to?(:close)
|
|
213
|
+
|
|
214
|
+
# All done.
|
|
215
|
+
output.flush
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
data/mizuno.gemspec
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Gem::Specification.new do |spec|
|
|
2
|
+
spec.name = "mizuno"
|
|
3
|
+
spec.version = "0.3.6"
|
|
4
|
+
spec.required_rubygems_version = Gem::Requirement.new(">= 1.2") \
|
|
5
|
+
if spec.respond_to?(:required_rubygems_version=)
|
|
6
|
+
spec.authors = [ "Don Werve" ]
|
|
7
|
+
spec.description = 'Jetty-powered running shoes for JRuby/Rack.'
|
|
8
|
+
spec.summary = 'Rack handler for Jetty 7 on JRuby. Features multithreading, event-driven I/O, and async support.'
|
|
9
|
+
spec.email = 'don@madwombat.com'
|
|
10
|
+
spec.executables = [ "mizuno" ]
|
|
11
|
+
spec.files = [ ".gitignore",
|
|
12
|
+
"README",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"mizuno.gemspec",
|
|
15
|
+
"lib/java/cometd-api-1.1.0.jar",
|
|
16
|
+
"lib/java/cometd-java-server-1.1.0.jar",
|
|
17
|
+
"lib/java/jetty-continuation-7.0.2.v20100331.jar",
|
|
18
|
+
"lib/java/jetty-http-7.0.2.v20100331.jar",
|
|
19
|
+
"lib/java/jetty-io-7.0.2.v20100331.jar",
|
|
20
|
+
"lib/java/jetty-jmx-7.0.2.v20100331.jar",
|
|
21
|
+
"lib/java/jetty-security-7.0.2.v20100331.jar",
|
|
22
|
+
"lib/java/jetty-server-7.0.2.v20100331.jar",
|
|
23
|
+
"lib/java/jetty-servlet-7.0.2.v20100331.jar",
|
|
24
|
+
"lib/java/jetty-servlets-7.0.2.v20100331.jar",
|
|
25
|
+
"lib/java/jetty-util-7.0.2.v20100331.jar",
|
|
26
|
+
"lib/java/servlet-api-2.5.jar",
|
|
27
|
+
"lib/rack/handler/mizuno/http_server.rb",
|
|
28
|
+
"lib/rack/handler/mizuno/rack_servlet.rb",
|
|
29
|
+
"lib/rack/handler/mizuno.rb",
|
|
30
|
+
"bin/mizuno" ]
|
|
31
|
+
spec.homepage = 'http://github.com/matadon/mizuno'
|
|
32
|
+
spec.has_rdoc = false
|
|
33
|
+
spec.require_paths = [ "lib" ]
|
|
34
|
+
spec.rubygems_version = '1.3.6'
|
|
35
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mizuno
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 3
|
|
8
|
+
- 6
|
|
9
|
+
version: 0.3.6
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Don Werve
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-07-03 00:00:00 +09:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies: []
|
|
20
|
+
|
|
21
|
+
description: Jetty-powered running shoes for JRuby/Rack.
|
|
22
|
+
email: don@madwombat.com
|
|
23
|
+
executables:
|
|
24
|
+
- mizuno
|
|
25
|
+
extensions: []
|
|
26
|
+
|
|
27
|
+
extra_rdoc_files: []
|
|
28
|
+
|
|
29
|
+
files:
|
|
30
|
+
- .gitignore
|
|
31
|
+
- README
|
|
32
|
+
- LICENSE
|
|
33
|
+
- mizuno.gemspec
|
|
34
|
+
- lib/java/cometd-api-1.1.0.jar
|
|
35
|
+
- lib/java/cometd-java-server-1.1.0.jar
|
|
36
|
+
- lib/java/jetty-continuation-7.0.2.v20100331.jar
|
|
37
|
+
- lib/java/jetty-http-7.0.2.v20100331.jar
|
|
38
|
+
- lib/java/jetty-io-7.0.2.v20100331.jar
|
|
39
|
+
- lib/java/jetty-jmx-7.0.2.v20100331.jar
|
|
40
|
+
- lib/java/jetty-security-7.0.2.v20100331.jar
|
|
41
|
+
- lib/java/jetty-server-7.0.2.v20100331.jar
|
|
42
|
+
- lib/java/jetty-servlet-7.0.2.v20100331.jar
|
|
43
|
+
- lib/java/jetty-servlets-7.0.2.v20100331.jar
|
|
44
|
+
- lib/java/jetty-util-7.0.2.v20100331.jar
|
|
45
|
+
- lib/java/servlet-api-2.5.jar
|
|
46
|
+
- lib/rack/handler/mizuno/http_server.rb
|
|
47
|
+
- lib/rack/handler/mizuno/rack_servlet.rb
|
|
48
|
+
- lib/rack/handler/mizuno.rb
|
|
49
|
+
- bin/mizuno
|
|
50
|
+
has_rdoc: true
|
|
51
|
+
homepage: http://github.com/matadon/mizuno
|
|
52
|
+
licenses: []
|
|
53
|
+
|
|
54
|
+
post_install_message:
|
|
55
|
+
rdoc_options: []
|
|
56
|
+
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
none: false
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
segments:
|
|
65
|
+
- 0
|
|
66
|
+
version: "0"
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
none: false
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
segments:
|
|
73
|
+
- 1
|
|
74
|
+
- 2
|
|
75
|
+
version: "1.2"
|
|
76
|
+
requirements: []
|
|
77
|
+
|
|
78
|
+
rubyforge_project:
|
|
79
|
+
rubygems_version: 1.3.7
|
|
80
|
+
signing_key:
|
|
81
|
+
specification_version: 3
|
|
82
|
+
summary: Rack handler for Jetty 7 on JRuby. Features multithreading, event-driven I/O, and async support.
|
|
83
|
+
test_files: []
|
|
84
|
+
|