DistelliServiceFrameworkRails 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,8 @@ module DistelliServiceFrameworkRails
7
7
  $json_marshaller = Distelli::JsonMarshaller.new
8
8
 
9
9
  def get_request_id()
10
- request_id = request.headers[Distelli::ServiceConstants::REQUEST_ID_HEADER]
10
+ header_name = Distelli::ServiceConstants::REQUEST_ID_HEADER.upcase().gsub("-", "_")
11
+ request_id = request.headers[header_name]
11
12
  if request_id != nil
12
13
  return request_id
13
14
  end
@@ -19,12 +20,13 @@ module DistelliServiceFrameworkRails
19
20
 
20
21
  # Create a new request id
21
22
  request_id = SecureRandom.uuid
22
- request.headers[Distelli::ServiceConstants::REQUEST_ID_HEADER] = request_id
23
+ request.headers[header_name] = request_id
23
24
  return request_id
24
25
  end
25
26
 
26
27
  def get_response_type()
27
- response_type = request.headers[Distelli::ServiceConstants::RESPONSE_TYPE_HEADER]
28
+ header_name = Distelli::ServiceConstants::RESPONSE_TYPE_HEADER.upcase().gsub("-","_")
29
+ response_type = request.headers[header_name]
28
30
  if response_type != nil
29
31
  return validate_response_type(response_type)
30
32
  end
@@ -38,12 +40,8 @@ module DistelliServiceFrameworkRails
38
40
  end
39
41
 
40
42
  def get_operation()
41
- # First check to see if there is the operation header.
42
- # If there is then thats the operation
43
- # If not then check to see if there is the operation query param
44
- # If it is then thats the operation
45
- # else the operation is null
46
- op_name = request.headers[Distelli::ServiceConstants::OPERATION_HEADER]
43
+ header_name = Distelli::ServiceConstants::OPERATION_HEADER.upcase().gsub("-","_")
44
+ op_name = request.headers[header_name]
47
45
  if op_name != nil
48
46
  return op_name
49
47
  end
@@ -55,12 +53,11 @@ module DistelliServiceFrameworkRails
55
53
  return params[Distelli::ServiceConstants::OPERATION_PARAM]
56
54
  end
57
55
 
58
- # def handle_stuff(status, content_type, body)
59
- # response.status = status
60
- # response.headers["Content-Type"] = content_type
61
- # # render :inline => body, :status => status
62
- # self.response_body = "DistelliSFR Body: "+body
63
- # end
56
+ def get_content_type()
57
+ header_name = Distelli::ServiceConstants::CONTENT_TYPE_HEADER.upcase().gsub("-","_")
58
+ content_type = request.headers[header_name]
59
+ return content_type
60
+ end
64
61
 
65
62
  def validate_response_type(response_type)
66
63
  if response_type == nil
@@ -77,7 +74,7 @@ module DistelliServiceFrameworkRails
77
74
  end
78
75
 
79
76
  def unmarshall_request()
80
- content_type = request.headers[Distelli::ServiceConstants::CONTENT_TYPE_HEADER]
77
+ content_type = get_content_type()
81
78
  if content_type == Distelli::ServiceConstants::CONTENT_TYPE_JSON
82
79
  return $json_marshaller.unmarshall(request.body)
83
80
  elsif content_type == Distelli::ServiceConstants::CONTENT_TYPE_XML
@@ -119,6 +116,7 @@ module DistelliServiceFrameworkRails
119
116
  if error.is_a?(Distelli::BaseException)
120
117
  response.status = error.http_code
121
118
  else
119
+ # LOGGER.error("Unhandled Exception: "+error.message+" "+error.backtrace.join(" \n"))
122
120
  error = Distelli::ServerError.new("Cannot marshall error of type "+error.class.name+" Defaulting to ServerError")
123
121
  response.status = error.http_code
124
122
  end
@@ -136,7 +134,7 @@ module DistelliServiceFrameworkRails
136
134
  response.headers.update(headers_hash)
137
135
  self.response_body = $xml_marshaller.marshall_error(error)
138
136
  else
139
- LOGGER.error("Invalid Response Type: "+response_type)
137
+ # LOGGER.error("Invalid Response Type: "+response_type)
140
138
  error = ServerError.new("Invalid response type: "+response_type)
141
139
  response.status = error.http_code
142
140
  headers_hash[Distelli::ServiceConstants::CONTENT_TYPE_HEADER] = Distelli::ServiceConstants::CONTENT_TYPE_JSON
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: DistelliServiceFrameworkRails
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
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-10-04 00:00:00.000000000 Z
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails