135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/distelli/clientframework.rb', line 135
def execute(request_info)
if @endpoint == nil
raise ClientException.new("Invalid endpoint: "+@endpoint.to_s)
end
logger.debug("Executing request to endpoint: "+@endpoint.to_s)
request_info.(ServiceConstants::OPERATION_HEADER, request_info.operation)
request_info.(ServiceConstants::CONTENT_TYPE_HEADER, request_info.content_type)
if not request_info.(ServiceConstants::RESPONSE_TYPE_HEADER)
request_info.(ServiceConstants::RESPONSE_TYPE_HEADER, request_info.response_type)
end
request_info.remove_query_params(ServiceConstants::OPERATION_PARAM)
request_info.remove_query_params(ServiceConstants::RESPONSE_TYPE_PARAM)
if request_info.request_id == nil
request_info.request_id = SecureRandom.uuid
end
request_info.(ServiceConstants::REQUEST_ID_HEADER, request_info.request_id)
request_info.remove_query_params(ServiceConstants::REQUEST_ID_PARAM)
cur_time = Time.now.utc
request_info.(ServiceConstants::DATE_HEADER, cur_time.strftime("%a, %d %b %Y %H:%M:%S %z"))
uri = URI.parse(request_info.get_uri(@endpoint))
if @credentials != nil
signer = RequestSigner.new
signature = signer.get_signature(@credentials.secret_key, request_info)
request_info.(ServiceConstants::AUTHORIZATION_HEADER, "DWS "+@credentials.key_id+":"+signature)
end
response = nil
http_method = request_info.http_method
http_client = Net::HTTP.new(uri.host, uri.port)
http_client.set_debug_output($stdout)
if http_method == ServiceConstants::HTTP_METHOD_GET
logger.debug("Executing GET: "+request_info.to_s)
http_request = Net::HTTP::Get.new(uri.request_uri, request_info.)
response = http_client.request(http_request)
elsif http_method == ServiceConstants::HTTP_METHOD_POST
logger.debug("Executing POST: "+request_info.to_s)
payload = get_payload(request_info)
http_request = Net::HTTP::Post.new(uri.request_uri, request_info.)
http_request.body = payload
response = http_client.request(http_request)
elsif http_method == ServiceConstants::HTTP_METHOD_PUT
logger.debug("Executing PUT: "+request_info.to_s)
payload = get_payload(request_info)
http_request = Net::HTTP::Put.new(uri.request_uri, request_info.)
http_request.body= payload
response = http_client.request(http_request)
elsif http_method == ServiceConstants::HTTP_METHOD_DELETE
logger.debug("Executing DELETE: "+request_info.to_s)
http_request = Net::HTTP::Delete.new(uri.request_uri, request_info.)
response = http_client.request(http_request)
else
raise ClientException.new("Invalid HTTP Method: "+http_method)
end
return handle_response(response)
end
|