jstp 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jstp/configuration.rb +2 -2
- data/lib/jstp/dispatch.rb +8 -0
- data/lib/jstp/engine.rb +18 -7
- data/lib/jstp/version.rb +1 -1
- data/lib/reader/jstp/engine.rb +1 -1
- metadata +1 -1
data/lib/jstp/configuration.rb
CHANGED
@@ -8,7 +8,7 @@ module JSTP
|
|
8
8
|
@logger = Logger.new $stdout
|
9
9
|
@hostname = (`hostname`)[0..-2]
|
10
10
|
@environment = :development
|
11
|
-
@gateway = true
|
11
|
+
@gateway = SymbolMatrix :reverse => true, :forward => true, :local => true
|
12
12
|
end
|
13
13
|
|
14
14
|
def port argument = nil
|
@@ -48,7 +48,7 @@ module JSTP
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def gateway argument = nil
|
51
|
-
@gateway = argument unless argument.nil?
|
51
|
+
@gateway = SymbolMatrix argument unless argument.nil?
|
52
52
|
@gateway
|
53
53
|
end
|
54
54
|
|
data/lib/jstp/dispatch.rb
CHANGED
data/lib/jstp/engine.rb
CHANGED
@@ -10,18 +10,28 @@ module JSTP
|
|
10
10
|
# Processes the dispatch in the new REST engine way
|
11
11
|
def dispatch message, client
|
12
12
|
host, the_class, query = discover_resource message["resource"].clone
|
13
|
-
if @config.gateway && host != @config.hostname && host != 'localhost'
|
13
|
+
if @config.gateway.forward && host != @config.hostname && host != 'localhost'
|
14
14
|
# May be we should gateway this message, if this wasn't aimed at us
|
15
15
|
message.to.send @config.strategy.outbound
|
16
16
|
else
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
# Is there a reverse gateway token there?
|
18
|
+
if @config.gateway.reverse && message.gateway == 'reverse'
|
19
|
+
if clients.has_key? message.token.first
|
20
|
+
clients[message.token.first].send message.to.json
|
21
|
+
@config.logger.debug message.to.string
|
22
|
+
else
|
23
|
+
raise ClientNotFoundError, "Client #{message.token.first} is not registered in this server"
|
24
|
+
end
|
20
25
|
else
|
21
|
-
if
|
22
|
-
|
26
|
+
if the_class.ancestors.include? JSTP::Controller
|
27
|
+
resource = the_class.new message, query, self, client
|
28
|
+
resource.send message["method"].downcase.to_sym
|
23
29
|
else
|
24
|
-
|
30
|
+
if @config.environment == :development
|
31
|
+
raise NotAControllerError, "The resource class #{the_class} for #{message["resource"].join("/")} was found, but is not a JSTP::Controller"
|
32
|
+
else
|
33
|
+
raise NotPermittedError, "The selected resource is forbidden for this type of request"
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
@@ -52,6 +62,7 @@ module JSTP
|
|
52
62
|
|
53
63
|
class NotPermittedError < RuntimeError; end
|
54
64
|
class NotAControllerError < RuntimeError; end
|
65
|
+
class ClientNotFoundError < RuntimeError; end
|
55
66
|
|
56
67
|
# DSL for configuration
|
57
68
|
def self.port argument = nil
|
data/lib/jstp/version.rb
CHANGED
data/lib/reader/jstp/engine.rb
CHANGED
@@ -59,7 +59,7 @@ module Reader
|
|
59
59
|
def log_exception exception, message
|
60
60
|
@config.logger.error "#{exception.class}: #{exception.message}"
|
61
61
|
@config.logger.debug exception.backtrace.to_s
|
62
|
-
@config.logger.debug
|
62
|
+
@config.logger.debug ::JSTP::Dispatch.new(message).to.string if message
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|