DistelliServiceFrameworkSinatra 1.0 → 1.1
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/lib/distelli/serviceframeworksinatra.rb +23 -20
- metadata +2 -2
|
@@ -9,7 +9,12 @@ module Rack
|
|
|
9
9
|
class CommonLogger
|
|
10
10
|
def call(env)
|
|
11
11
|
# do nothing
|
|
12
|
-
|
|
12
|
+
begin
|
|
13
|
+
@app.call(env)
|
|
14
|
+
rescue Exception => e
|
|
15
|
+
puts e.message
|
|
16
|
+
puts e.backtrace.inspect
|
|
17
|
+
end
|
|
13
18
|
end
|
|
14
19
|
end
|
|
15
20
|
end
|
|
@@ -17,28 +22,26 @@ end
|
|
|
17
22
|
module Distelli
|
|
18
23
|
class ServiceBase < Sinatra::Base
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
disable :
|
|
23
|
-
disable :show_exceptions
|
|
24
|
-
disable :dump_errors
|
|
25
|
-
|
|
26
|
-
# Parse the json config file and get the application name and
|
|
27
|
-
# version to set the log file name
|
|
28
|
-
|
|
25
|
+
# disable :raise_errors
|
|
26
|
+
# disable :show_exceptions
|
|
27
|
+
# disable :dump_errors
|
|
29
28
|
LOGGER = Logging.logger[:root]
|
|
30
|
-
LOGGER.add_appenders(rf_appender)
|
|
31
29
|
LOGGER.level = :debug
|
|
32
|
-
LOGGER.debug("TestRubyService initialized!")
|
|
33
30
|
|
|
34
|
-
def initialize()
|
|
31
|
+
def initialize(service_name)
|
|
35
32
|
super()
|
|
33
|
+
my_layout = Logging::Layouts::Pattern.new(:pattern => "%d:[%l]:[%t]:[%c]:%m\n")
|
|
34
|
+
rf_appender = Logging::Appenders::RollingFile.new(service_name, :filename => './logs/'+service_name+'.log', :layout => my_layout, :roll_by => 'date', :age => '3600')
|
|
35
|
+
|
|
36
|
+
LOGGER.add_appenders(rf_appender)
|
|
37
|
+
LOGGER.info("Initialized service: "+service_name)
|
|
38
|
+
|
|
36
39
|
@xml_marshaller = Distelli::XmlMarshaller.new
|
|
37
40
|
@json_marshaller = Distelli::JsonMarshaller.new
|
|
38
41
|
end
|
|
39
42
|
|
|
40
43
|
def add_object(obj)
|
|
41
|
-
LOGGER.
|
|
44
|
+
LOGGER.info("Added model object: "+obj.inspect.to_s)
|
|
42
45
|
@xml_marshaller.add_object(obj)
|
|
43
46
|
@json_marshaller.add_object(obj)
|
|
44
47
|
end
|
|
@@ -65,7 +68,7 @@ module Distelli
|
|
|
65
68
|
if http_code != nil
|
|
66
69
|
status http_code
|
|
67
70
|
end
|
|
68
|
-
|
|
71
|
+
|
|
69
72
|
headers_hash = Hash.new
|
|
70
73
|
headers_hash[ServiceConstants::SERVER_HEADER] = "DistelliWS"
|
|
71
74
|
headers_hash[ServiceConstants::REQUEST_ID_HEADER] = get_request_id()
|
|
@@ -95,7 +98,7 @@ module Distelli
|
|
|
95
98
|
error = Distelli::ServerError.new("Cannot marshall error of type "+error.class.name+" Defaulting to ServerError")
|
|
96
99
|
status error.http_code
|
|
97
100
|
end
|
|
98
|
-
|
|
101
|
+
|
|
99
102
|
headers_hash = Hash.new
|
|
100
103
|
headers_hash[ServiceConstants::SERVER_HEADER] = "DistelliWS"
|
|
101
104
|
headers_hash[ServiceConstants::REQUEST_ID_HEADER] = get_request_id()
|
|
@@ -132,7 +135,7 @@ module Distelli
|
|
|
132
135
|
return ServiceConstants::RESPONSE_TYPE_JSON
|
|
133
136
|
end
|
|
134
137
|
end
|
|
135
|
-
|
|
138
|
+
|
|
136
139
|
def get_request_id()
|
|
137
140
|
request_id = request[ServiceConstants::REQUEST_ID_HEADER]
|
|
138
141
|
if request_id != nil
|
|
@@ -155,7 +158,7 @@ module Distelli
|
|
|
155
158
|
if response_type != nil
|
|
156
159
|
return validate_response_type(response_type)
|
|
157
160
|
end
|
|
158
|
-
|
|
161
|
+
|
|
159
162
|
response_type = nil
|
|
160
163
|
params = request.params()
|
|
161
164
|
if params != nil
|
|
@@ -186,7 +189,7 @@ module Distelli
|
|
|
186
189
|
# Error Handlers
|
|
187
190
|
######################################
|
|
188
191
|
error do
|
|
189
|
-
# Marshall the error as a server error
|
|
192
|
+
# Marshall the error as a server error
|
|
190
193
|
ex = env['sinatra.error']
|
|
191
194
|
LOGGER.error('Unhandled Exception: '+ex.inspect+ex.backtrace.join("\n"))
|
|
192
195
|
return marshall_error(ex)
|
|
@@ -199,7 +202,7 @@ module Distelli
|
|
|
199
202
|
end
|
|
200
203
|
|
|
201
204
|
error Distelli::ServerError do
|
|
202
|
-
# Marshall the Server Error Exception and set the response code
|
|
205
|
+
# Marshall the Server Error Exception and set the response code
|
|
203
206
|
se = env['sinatra.error']
|
|
204
207
|
return marshall_error(se)
|
|
205
208
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: DistelliServiceFrameworkSinatra
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.1'
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: sinatra
|