wildsonet-server 0.2.1-java → 0.2.2-java
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/README.rdoc +9 -1
- data/jars/wildsonet_server.jar +0 -0
- data/lib/wildsonet-server-version.rb +1 -1
- data/lib/wildsonet-server.rb +49 -116
- data/wildsonet-server.gemspec +5 -11
- metadata +34 -13
- data/jars/jetty-continuation-7.2.0.v20101020.jar +0 -0
- data/jars/jetty-http-7.2.0.v20101020.jar +0 -0
- data/jars/jetty-io-7.2.0.v20101020.jar +0 -0
- data/jars/jetty-security-7.2.0.v20101020.jar +0 -0
- data/jars/jetty-server-7.2.0.v20101020.jar +0 -0
- data/jars/jetty-servlet-7.2.0.v20101020.jar +0 -0
- data/jars/jetty-util-7.2.0.v20101020.jar +0 -0
- data/jars/servlet-api-2.5.jar +0 -0
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ Server backend for WildSoNet.
|
|
4
4
|
|
5
5
|
== Implementation
|
6
6
|
|
7
|
-
|
7
|
+
Implements simple Rack interdace on top of Netty library.
|
8
8
|
|
9
9
|
== Status
|
10
10
|
|
@@ -29,6 +29,8 @@ This server should be used behind front-end server.
|
|
29
29
|
}
|
30
30
|
|
31
31
|
location / {
|
32
|
+
proxy_set_header X-For-Host $http_host;
|
33
|
+
proxy_set_header X-For-Scheme $scheme;
|
32
34
|
proxy_pass http://<rails_address>:<address_port>;
|
33
35
|
}
|
34
36
|
|
@@ -58,6 +60,12 @@ where App is your Rack application.
|
|
58
60
|
* Configuration (threadpool)
|
59
61
|
* Lots of other features
|
60
62
|
|
63
|
+
== Changes
|
64
|
+
|
65
|
+
=== 0.2.2
|
66
|
+
|
67
|
+
* Rewritten from Jetty to Netty - no need for full web server
|
68
|
+
|
61
69
|
== Contributing to wildsonet-server
|
62
70
|
|
63
71
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
Binary file
|
data/lib/wildsonet-server.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require "java"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require "wildsonet-netty"
|
4
|
+
require "active_support/core_ext/hash/reverse_merge"
|
5
|
+
|
6
|
+
require File.join(File.dirname(__FILE__), "..", "jars", "wildsonet_server.jar")
|
6
7
|
|
7
8
|
require "wildsonet-server-version"
|
8
9
|
|
@@ -12,19 +13,21 @@ module WildSoNet
|
|
12
13
|
# Rack extensions from WildSoNet
|
13
14
|
module Server
|
14
15
|
|
15
|
-
java_import "
|
16
|
-
java_import "
|
17
|
-
java_import "org.eclipse.jetty.servlet.ServletContextHandler"
|
18
|
-
java_import "org.eclipse.jetty.servlet.ServletHolder"
|
16
|
+
java_import "cz.wildsonet.server.RackProxy"
|
17
|
+
java_import "cz.wildsonet.server.Server"
|
19
18
|
|
20
|
-
java_import "org.
|
21
|
-
java_import "org.
|
22
|
-
java_import "
|
19
|
+
java_import "org.jboss.netty.buffer.ChannelBuffers"
|
20
|
+
java_import "org.jboss.netty.handler.codec.http.DefaultHttpResponse"
|
21
|
+
java_import "org.jboss.netty.handler.codec.http.HttpResponseStatus"
|
22
|
+
java_import "org.jboss.netty.handler.codec.http.HttpVersion"
|
23
|
+
java_import "org.jboss.netty.channel.ChannelFutureListener"
|
23
24
|
|
24
25
|
# Rack handler utilizing Jetty web server. Works with nginx as frontend server to proxy the requests.
|
25
26
|
# Jetty handles only dynamic requests. Static requests are handled by nginx proxy.
|
26
27
|
|
27
|
-
class Handler
|
28
|
+
class Handler
|
29
|
+
|
30
|
+
include RackProxy
|
28
31
|
|
29
32
|
# Starts the server.
|
30
33
|
#
|
@@ -36,132 +39,62 @@ module WildSoNet
|
|
36
39
|
options[:Host] ||= "0.0.0.0"
|
37
40
|
|
38
41
|
# Create new server
|
39
|
-
@@server = Server.new
|
40
|
-
|
41
|
-
# Create new connector and configure it according to options
|
42
|
-
connector = SelectChannelConnector.new
|
43
|
-
connector.port = options[:Port]
|
44
|
-
connector.host = options[:Host]
|
45
|
-
|
46
|
-
# Add connector to server
|
47
|
-
@@server.connectors = [connector]
|
48
|
-
|
49
|
-
# Create new server context and configure it ad root
|
50
|
-
context = ServletContextHandler.new(ServletContextHandler::NO_SESSIONS)
|
51
|
-
context.contextPath = "/"
|
42
|
+
@@server = Server.new(options[:Host], options[:Port], self.new(app, options))
|
52
43
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
servlet.setup(app, options)
|
59
|
-
|
60
|
-
# Connect the handler with context
|
61
|
-
context.addServlet(ServletHolder.new(servlet), "/*")
|
62
|
-
|
63
|
-
# Start server
|
64
|
-
@@server.start
|
65
|
-
@@server.join
|
66
|
-
|
67
|
-
end
|
44
|
+
Thread.new do
|
45
|
+
while true
|
46
|
+
Kernel.sleep 10
|
47
|
+
end
|
48
|
+
end.join
|
68
49
|
|
69
|
-
# Stops the server
|
70
|
-
def self.shutdown
|
71
|
-
# Stop server
|
72
|
-
@@server.stop
|
73
|
-
@@server = nil
|
74
50
|
end
|
75
51
|
|
76
52
|
# Setup the server.
|
77
53
|
#
|
78
54
|
# @param app Rack application to start
|
79
55
|
# @param options Options for server
|
80
|
-
def
|
81
|
-
@app = app
|
56
|
+
def initialize(app, options)
|
57
|
+
@app = ::Rack::Lint.new(app)
|
82
58
|
@options = options
|
83
|
-
|
84
|
-
# By default serve static files from directory "public" in current directory
|
85
|
-
@options[:Public] ||= File.expand_path("public")
|
86
59
|
end
|
87
60
|
|
88
|
-
|
89
|
-
#
|
90
|
-
# @param request Request to process
|
91
|
-
# @param response Response to the request
|
92
|
-
def service request, response
|
93
|
-
# "Compute" the path to request file
|
94
|
-
file = File.join(@options[:Public], request.getRequestURI())
|
95
|
-
# Check file existence
|
96
|
-
if File.exists?(file) and File.file?(file)
|
97
|
-
# Tell the proxy server(nginx) to serve this request from static files
|
98
|
-
response.setHeader("X-Accel-Redirect", "/static" + request.getRequestURI())
|
99
|
-
else
|
100
|
-
# Process the request
|
101
|
-
self.call(request, response)
|
102
|
-
end
|
103
|
-
end
|
61
|
+
def call env
|
104
62
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
"PATH_INFO" => request.getPathInfo() =~ /^\// ? request.getPathInfo() : "/" + request.getPathInfo(),
|
116
|
-
"QUERY_STRING" => request.getQueryString(),
|
117
|
-
"SERVER_NAME" => request.getServerName(),
|
118
|
-
"SERVER_PORT" => request.getServerPort(),
|
119
|
-
|
120
|
-
"rack.version" => [1, 1],
|
121
|
-
"rack.url_scheme" => request.isSecure() ? "https" : "http",
|
122
|
-
"rack.input" => request.getInputStream().to_io,
|
123
|
-
"rack.errors" => $stderr,
|
124
|
-
"rack.multithread" => true,
|
125
|
-
"rack.multiprocess" => false,
|
126
|
-
"rack.run_once" => false,
|
127
|
-
|
128
|
-
# If this environment parameter is true after request processing, returned body will not be written to response
|
129
|
-
"wildsonet.written" => false
|
130
|
-
}
|
131
|
-
|
132
|
-
# Process HTTP headers from request; transforms header names into Rack format, if nil returned, the header is skipped
|
133
|
-
request.getHeaderNames().each do |name|
|
134
|
-
key = self.header_handler(name)
|
135
|
-
if key
|
136
|
-
env[key] = request.getHeader(name)
|
63
|
+
ruby = {}
|
64
|
+
|
65
|
+
env.keySet.each do |key|
|
66
|
+
case key
|
67
|
+
when "rack.input"
|
68
|
+
ruby[key] = env[key].to_io
|
69
|
+
when "rack.errors"
|
70
|
+
ruby[key] = env[key].to_io
|
71
|
+
else
|
72
|
+
ruby[key] = env[key]
|
137
73
|
end
|
138
74
|
end
|
139
75
|
|
140
|
-
|
141
|
-
status, headers, content = @app.call(env)
|
76
|
+
ruby["rack.version"] = ::Rack::VERSION
|
142
77
|
|
143
|
-
|
144
|
-
|
145
|
-
|
78
|
+
status, headers, body = @app.call(ruby)
|
79
|
+
|
80
|
+
response = DefaultHttpResponse.new(HttpVersion::HTTP_1_1, HttpResponseStatus.valueOf(status))
|
81
|
+
|
82
|
+
headers.each_pair do |header, value|
|
83
|
+
response.addHeader(header, value)
|
146
84
|
end
|
147
85
|
|
148
|
-
|
149
|
-
|
86
|
+
buffer = ChannelBuffers.dynamicBuffer
|
87
|
+
|
88
|
+
body.each do |line|
|
89
|
+
buffer.writeBytes(line.to_s.to_java_bytes)
|
90
|
+
end
|
150
91
|
|
151
|
-
|
152
|
-
# Skips this step if environment parameter was set to true
|
153
|
-
content.each do |part|
|
154
|
-
response.writer.write(part)
|
155
|
-
end unless env["wildsonet.written"]
|
92
|
+
response.content = buffer
|
156
93
|
|
157
|
-
|
94
|
+
future = env["wsn.context"].channel.write(response)
|
158
95
|
|
159
|
-
|
160
|
-
|
161
|
-
# @param name Header name to transform
|
162
|
-
# @return Rack formatted header name or nil to skip the header
|
163
|
-
def header_handler name
|
164
|
-
"HTTP_" + name.to_s.sub("-", "_").upcase
|
96
|
+
future.addListener(ChannelFutureListener::CLOSE)
|
97
|
+
|
165
98
|
end
|
166
99
|
|
167
100
|
end
|
data/wildsonet-server.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.name = "wildsonet-server"
|
9
9
|
s.version = WildSoNet::Server::VERSION
|
10
10
|
s.authors = ["Marek Jelen"]
|
11
|
-
s.summary = "Server
|
12
|
-
s.description = "Server
|
11
|
+
s.summary = "Server backend for WildSoNet"
|
12
|
+
s.description = "Server backend for WildSoNet on top of Netty library"
|
13
13
|
s.email = "marek@jelen.biz"
|
14
14
|
s.homepage = "http://github.com/marekjelen/wildsonet-server"
|
15
15
|
s.licenses = ["MIT"]
|
@@ -26,14 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Gemfile",
|
27
27
|
"LICENSE.txt",
|
28
28
|
"README.rdoc",
|
29
|
-
"jars/
|
30
|
-
"jars/jetty-http-7.2.0.v20101020.jar",
|
31
|
-
"jars/jetty-io-7.2.0.v20101020.jar",
|
32
|
-
"jars/jetty-security-7.2.0.v20101020.jar",
|
33
|
-
"jars/jetty-server-7.2.0.v20101020.jar",
|
34
|
-
"jars/jetty-servlet-7.2.0.v20101020.jar",
|
35
|
-
"jars/jetty-util-7.2.0.v20101020.jar",
|
36
|
-
"jars/servlet-api-2.5.jar",
|
29
|
+
"jars/wildsonet_server.jar",
|
37
30
|
"lib/wildsonet-server.rb",
|
38
31
|
"lib/wildsonet-server-version.rb",
|
39
32
|
"wildsonet-server.gemspec"
|
@@ -45,6 +38,7 @@ Gem::Specification.new do |s|
|
|
45
38
|
]
|
46
39
|
|
47
40
|
s.add_runtime_dependency("rack", ["> 1.0"])
|
48
|
-
|
41
|
+
s.add_runtime_dependency("wildsonet-netty", ["> 0.0"])
|
42
|
+
s.add_runtime_dependency("activesupport", ["> 3.0"])
|
49
43
|
end
|
50
44
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: java
|
11
11
|
authors:
|
12
12
|
- Marek Jelen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-30 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -31,7 +31,35 @@ dependencies:
|
|
31
31
|
version: "1.0"
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
|
-
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: wildsonet-netty
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
- 0
|
45
|
+
version: "0.0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: activesupport
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 3
|
58
|
+
- 0
|
59
|
+
version: "3.0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
description: Server backend for WildSoNet on top of Netty library
|
35
63
|
email: marek@jelen.biz
|
36
64
|
executables: []
|
37
65
|
|
@@ -44,14 +72,7 @@ files:
|
|
44
72
|
- Gemfile
|
45
73
|
- LICENSE.txt
|
46
74
|
- README.rdoc
|
47
|
-
- jars/
|
48
|
-
- jars/jetty-http-7.2.0.v20101020.jar
|
49
|
-
- jars/jetty-io-7.2.0.v20101020.jar
|
50
|
-
- jars/jetty-security-7.2.0.v20101020.jar
|
51
|
-
- jars/jetty-server-7.2.0.v20101020.jar
|
52
|
-
- jars/jetty-servlet-7.2.0.v20101020.jar
|
53
|
-
- jars/jetty-util-7.2.0.v20101020.jar
|
54
|
-
- jars/servlet-api-2.5.jar
|
75
|
+
- jars/wildsonet_server.jar
|
55
76
|
- lib/wildsonet-server.rb
|
56
77
|
- lib/wildsonet-server-version.rb
|
57
78
|
- wildsonet-server.gemspec
|
@@ -88,6 +109,6 @@ rubyforge_project:
|
|
88
109
|
rubygems_version: 1.3.7
|
89
110
|
signing_key:
|
90
111
|
specification_version: 3
|
91
|
-
summary: Server
|
112
|
+
summary: Server backend for WildSoNet
|
92
113
|
test_files: []
|
93
114
|
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/jars/servlet-api-2.5.jar
DELETED
Binary file
|