jubilee 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/jars/jackson-core-asl-1.9.4.jar +0 -0
- data/jars/jackson-mapper-asl-1.9.4.jar +0 -0
- data/jars/vertx-core-1.3.0.final.jar +0 -0
- data/java/src/org/jruby/jubilee/Server.java +49 -13
- data/lib/jubilee.rb +2 -0
- data/lib/jubilee/cli.rb +12 -3
- data/lib/jubilee/configuration.rb +5 -1
- data/lib/jubilee/const.rb +2 -1
- data/lib/jubilee/jubilee.jar +0 -0
- data/lib/jubilee/response.rb +6 -3
- data/lib/jubilee/server.rb +5 -8
- data/lib/rack/handler/jubilee.rb +7 -6
- data/test/jubilee/test_cli.rb +1 -1
- data/test/jubilee/test_config.rb +2 -2
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
Binary file
|
Binary file
|
Binary file
|
@@ -7,6 +7,8 @@ import org.jruby.*;
|
|
7
7
|
import org.jruby.runtime.*;
|
8
8
|
import org.jruby.runtime.builtin.*;
|
9
9
|
import org.jruby.anno.JRubyMethod;
|
10
|
+
import org.vertx.java.core.json.JsonArray;
|
11
|
+
import org.vertx.java.core.json.JsonObject;
|
10
12
|
|
11
13
|
public class Server extends RubyObject {
|
12
14
|
final private Vertx vertx;
|
@@ -16,7 +18,9 @@ public class Server extends RubyObject {
|
|
16
18
|
private boolean ssl = false;
|
17
19
|
private String keyStorePath;
|
18
20
|
private String keyStorePassword;
|
21
|
+
private String eventBusPrefix;
|
19
22
|
private int port;
|
23
|
+
private String host;
|
20
24
|
|
21
25
|
public static void createServerClass(Ruby runtime) {
|
22
26
|
RubyModule mJubilee = runtime.defineModule("Jubilee");
|
@@ -36,23 +40,50 @@ public class Server extends RubyObject {
|
|
36
40
|
httpServer = vertx.createHttpServer();
|
37
41
|
}
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
/**
|
44
|
+
* Initialize jubilee server, take a rack application and a configuration hash as parameter
|
45
|
+
* @param context
|
46
|
+
* @param args
|
47
|
+
* @param block
|
48
|
+
* @return
|
49
|
+
*/
|
50
|
+
@JRubyMethod(name = "initialize")
|
51
|
+
public IRubyObject initialize(ThreadContext context, IRubyObject app, IRubyObject config, Block block) {
|
52
|
+
Ruby runtime = getRuntime();
|
53
|
+
RubyHash options = config.convertToHash();
|
54
|
+
RubySymbol port_k = runtime.newSymbol("Port");
|
55
|
+
RubySymbol host_k = runtime.newSymbol("Host");
|
56
|
+
RubySymbol ssl_k = runtime.newSymbol("ssl");
|
57
|
+
RubySymbol keystore_path_k = runtime.newSymbol("keystore_path");
|
58
|
+
RubySymbol keystore_password_k = runtime.newSymbol("keystore_password");
|
59
|
+
RubySymbol eventbus_prefix_k = runtime.newSymbol("eventbus_prefix");
|
60
|
+
this.port = RubyInteger.num2int(options.op_aref(context, port_k));
|
61
|
+
if (options.has_key_p(host_k).isTrue()) {
|
62
|
+
this.host = options.op_aref(context, host_k).toString();
|
63
|
+
} else {
|
64
|
+
this.host = "0.0.0.0";
|
65
|
+
}
|
66
|
+
this.ssl = options.op_aref(context, ssl_k).isTrue();
|
67
|
+
this.app = new RackApplication(app, this.ssl);
|
68
|
+
if (options.has_key_p(keystore_path_k).isTrue()) {
|
69
|
+
this.keyStorePath = options.op_aref(context, keystore_path_k).toString();
|
70
|
+
this.keyStorePassword = options.op_aref(context, keystore_password_k).toString();
|
71
|
+
}
|
72
|
+
if (options.has_key_p(eventbus_prefix_k).isTrue()) {
|
73
|
+
this.eventBusPrefix = options.op_aref(context, eventbus_prefix_k).toString();
|
44
74
|
}
|
45
|
-
this.app = new RackApplication(args[0], this.ssl);
|
46
|
-
if (args.length > 3)
|
47
|
-
this.keyStorePath = args[3].toString();
|
48
|
-
if (args.length > 4)
|
49
|
-
this.keyStorePassword = args[4].toString();
|
50
75
|
running = false;
|
51
76
|
return this;
|
52
77
|
}
|
53
78
|
|
54
|
-
|
55
|
-
|
79
|
+
/**
|
80
|
+
* Start http server, initialize states
|
81
|
+
* @param context
|
82
|
+
* @param block
|
83
|
+
* @return
|
84
|
+
*/
|
85
|
+
@JRubyMethod(name = "start")
|
86
|
+
public IRubyObject start(final ThreadContext context, final Block block) {
|
56
87
|
this.running = true;
|
57
88
|
httpServer.setAcceptBacklog(10000);
|
58
89
|
httpServer.requestHandler(new Handler<HttpServerRequest>() {
|
@@ -60,9 +91,14 @@ public class Server extends RubyObject {
|
|
60
91
|
app.call(req);
|
61
92
|
}
|
62
93
|
});
|
94
|
+
if (eventBusPrefix != null) {
|
95
|
+
JsonObject config = new JsonObject().putString("prefix", eventBusPrefix);
|
96
|
+
// TODO read inbounds and outbounds from config file
|
97
|
+
vertx.createSockJSServer(httpServer).bridge(config, new JsonArray(), new JsonArray());
|
98
|
+
}
|
63
99
|
if (ssl) httpServer.setSSL(true).setKeyStorePath(this.keyStorePath)
|
64
100
|
.setKeyStorePassword(this.keyStorePassword);
|
65
|
-
httpServer.listen(this.port);
|
101
|
+
httpServer.listen(this.port, this.host);
|
66
102
|
return this;
|
67
103
|
}
|
68
104
|
|
data/lib/jubilee.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../jars/jackson-core-asl-1.9.4.jar")
|
2
|
+
require File.join(File.dirname(__FILE__), "../jars/jackson-mapper-asl-1.9.4.jar")
|
1
3
|
require File.join(File.dirname(__FILE__), "../jars/vertx-core-1.3.0.final.jar")
|
2
4
|
require File.join(File.dirname(__FILE__), "../jars/netty-3.6.0.Beta1.jar")
|
3
5
|
|
data/lib/jubilee/cli.rb
CHANGED
@@ -22,7 +22,7 @@ module Jubilee
|
|
22
22
|
parse_options
|
23
23
|
@config = Jubilee::Configuration.new(@options)
|
24
24
|
@config.load
|
25
|
-
server = Jubilee::Server.new(@config.app,
|
25
|
+
server = Jubilee::Server.new(@config.app, @options)
|
26
26
|
server.start
|
27
27
|
puts "Jubilee is listening on port #{@config.port}, press Ctrl+C to quit"
|
28
28
|
starter = org.jruby.jubilee.deploy.Starter.new
|
@@ -33,7 +33,7 @@ module Jubilee
|
|
33
33
|
@options = {
|
34
34
|
debug: false,
|
35
35
|
daemon: false,
|
36
|
-
|
36
|
+
Port: 3215,
|
37
37
|
ssl: false,
|
38
38
|
environment: "development"
|
39
39
|
}
|
@@ -51,7 +51,10 @@ module Jubilee
|
|
51
51
|
@options[:chdir] = arg
|
52
52
|
end
|
53
53
|
o.on "-p", "--port PORT", "Defind which PORT the server should bind" do |arg|
|
54
|
-
@options[:
|
54
|
+
@options[:Port] = arg
|
55
|
+
end
|
56
|
+
o.on "--host HOST", "Defind which HOST the server should bind, default 0.0.0.0" do |arg|
|
57
|
+
@options[:Host] = arg
|
55
58
|
end
|
56
59
|
o.on "-e", "--environment ENV", "Rack environment" do |arg|
|
57
60
|
@options[:environment] = arg
|
@@ -67,6 +70,12 @@ module Jubilee
|
|
67
70
|
o.on "--ssl-password PASS", "SSL keystore password" do |arg|
|
68
71
|
@options[:keystore_password] = arg
|
69
72
|
end
|
73
|
+
o.separator ""
|
74
|
+
o.separator "Event bus options"
|
75
|
+
o.on "--eventbus PREFIX", "Event bus prefix" do |arg|
|
76
|
+
@options[:eventbus_prefix] = arg
|
77
|
+
end
|
78
|
+
|
70
79
|
o.separator ""
|
71
80
|
o.separator "Common options:"
|
72
81
|
o.on "--verbose", "Log low level debug information" do
|
data/lib/jubilee/const.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Jubilee
|
2
2
|
module Const
|
3
|
-
JUBILEE_VERSION = VERSION = "0.1
|
3
|
+
JUBILEE_VERSION = VERSION = "0.2.1".freeze
|
4
4
|
HTTP_11 = "HTTP/1.1".freeze
|
5
5
|
HTTP_10 = "HTTP/1.0".freeze
|
6
6
|
|
@@ -33,6 +33,7 @@ module Jubilee
|
|
33
33
|
HTTP_ACCEPT_LANGUAGE = "HTTP_ACCEPT_LANGUAGE".freeze
|
34
34
|
HTTP_ACCEPT_ENCODING = "HTTP_ACCEPT_ENCODING".freeze
|
35
35
|
HTTP_CONNECTION = "HTTP_CONNECTION".freeze
|
36
|
+
NEWLINE = "\n".freeze
|
36
37
|
|
37
38
|
STATUS_WITH_NO_ENTITY_BODY = Hash[Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.map{|s| [s, true]}]
|
38
39
|
end
|
data/lib/jubilee/jubilee.jar
CHANGED
Binary file
|
data/lib/jubilee/response.rb
CHANGED
@@ -36,16 +36,19 @@ module Jubilee
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def write_headers(response)
|
39
|
-
@headers.each do |key,
|
39
|
+
@headers.each do |key, values|
|
40
40
|
case key
|
41
41
|
when CONTENT_LENGTH
|
42
|
-
@content_length =
|
42
|
+
@content_length = values
|
43
43
|
next
|
44
44
|
when TRANSFER_ENCODING
|
45
45
|
@allow_chunked = false
|
46
46
|
@content_length = nil
|
47
47
|
end
|
48
|
-
|
48
|
+
# Multiple values are joined by \n
|
49
|
+
values.split(NEWLINE).each do |value|
|
50
|
+
response.putHeader(key, value)
|
51
|
+
end
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
data/lib/jubilee/server.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
|
+
require 'rack/methodoverride'
|
1
2
|
module Jubilee
|
2
3
|
class Server < VertxServer
|
3
4
|
def initialize(app, opts = {})
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
app = Rack::MethodOverride.new(app)
|
6
|
+
options = {Port: 3215, ssl: false}.merge(opts)
|
7
|
+
if (options[:ssl]) && options[:keystore_path].nil?
|
7
8
|
raise ArgumentError, "Please provide a keystore for ssl"
|
8
|
-
else
|
9
|
-
super(Application.new(app), options[:port], options[:ssl], options[:keystore_path], options[:keystore_password])
|
10
|
-
end
|
11
|
-
else
|
12
|
-
super(Application.new(app), options[:port])
|
13
9
|
end
|
10
|
+
super(Application.new(app), options)
|
14
11
|
end
|
15
12
|
end
|
16
13
|
end
|
data/lib/rack/handler/jubilee.rb
CHANGED
@@ -6,14 +6,14 @@ module Rack
|
|
6
6
|
module Handler
|
7
7
|
module Jubilee
|
8
8
|
DEFAULT_OPTIONS = {
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
9
|
+
:Host => '0.0.0.0',
|
10
|
+
:Port => 3000,
|
11
|
+
:Verbose => false
|
12
12
|
}
|
13
13
|
def self.run(app, options = {})
|
14
14
|
options = DEFAULT_OPTIONS.merge(options)
|
15
15
|
|
16
|
-
if options[:
|
16
|
+
if options[:Verbose]
|
17
17
|
app = Rack::CommonLogger.new(app, STDOUT)
|
18
18
|
end
|
19
19
|
|
@@ -23,8 +23,9 @@ module Rack
|
|
23
23
|
|
24
24
|
@server = ::Jubilee::Server.new(app, options)
|
25
25
|
|
26
|
-
puts "Jubilee starting..."
|
27
|
-
puts "Environment: #{ENV['RACK_ENV']}"
|
26
|
+
puts "Jubilee #{::Jubilee::Const::JUBILEE_VERSION} starting..."
|
27
|
+
puts "* Environment: #{ENV['RACK_ENV']}"
|
28
|
+
puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}"
|
28
29
|
|
29
30
|
yield @server if block_given?
|
30
31
|
|
data/test/jubilee/test_cli.rb
CHANGED
data/test/jubilee/test_config.rb
CHANGED
@@ -8,7 +8,7 @@ class TestConfig < MiniTest::Unit::TestCase
|
|
8
8
|
def test_load
|
9
9
|
@config.load
|
10
10
|
resp = [200, {"Content-Type" => "text/plain"}, ["embeded app"]]
|
11
|
-
skip "hard to test because of Rack::Lint"
|
12
|
-
|
11
|
+
#skip "hard to test because of Rack::Lint"
|
12
|
+
assert_equal resp, @config.app.call({})
|
13
13
|
end
|
14
14
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: jubilee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Isaiah Peng
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -85,6 +85,8 @@ files:
|
|
85
85
|
- examples/jubilee/server-keystore.jks
|
86
86
|
- examples/ssl/ServerTest.java
|
87
87
|
- examples/ssl/webroot/index.html
|
88
|
+
- jars/jackson-core-asl-1.9.4.jar
|
89
|
+
- jars/jackson-mapper-asl-1.9.4.jar
|
88
90
|
- jars/netty-3.6.0.Beta1.jar
|
89
91
|
- jars/vertx-core-1.3.0.final.jar
|
90
92
|
- java/.idea/ant.xml
|