Merge "heat API : Add support for ContentType=JSON query parameter"
This commit is contained in:
commit
fa7d89e5ed
|
@ -352,5 +352,4 @@ def create_resource(options):
|
||||||
Stacks resource factory method.
|
Stacks resource factory method.
|
||||||
"""
|
"""
|
||||||
deserializer = wsgi.JSONRequestDeserializer()
|
deserializer = wsgi.JSONRequestDeserializer()
|
||||||
serializer = wsgi.XMLResponseSerializer()
|
return wsgi.Resource(StackController(options), deserializer)
|
||||||
return wsgi.Resource(StackController(options), deserializer, serializer)
|
|
||||||
|
|
|
@ -481,16 +481,13 @@ class Resource(object):
|
||||||
may raise a webob.exc exception or return a dict, which will be
|
may raise a webob.exc exception or return a dict, which will be
|
||||||
serialized by requested content type.
|
serialized by requested content type.
|
||||||
"""
|
"""
|
||||||
def __init__(self, controller, deserializer, serializer):
|
def __init__(self, controller, deserializer):
|
||||||
"""
|
"""
|
||||||
:param controller: object that implement methods created by routes lib
|
:param controller: object that implement methods created by routes lib
|
||||||
:param deserializer: object that supports webob request deserialization
|
:param deserializer: object that supports webob request deserialization
|
||||||
through controller-like actions
|
through controller-like actions
|
||||||
:param serializer: object that supports webob response serialization
|
|
||||||
through controller-like actions
|
|
||||||
"""
|
"""
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.serializer = serializer
|
|
||||||
self.deserializer = deserializer
|
self.deserializer = deserializer
|
||||||
|
|
||||||
@webob.dec.wsgify(RequestClass=Request)
|
@webob.dec.wsgify(RequestClass=Request)
|
||||||
|
@ -499,6 +496,15 @@ class Resource(object):
|
||||||
action_args = self.get_action_args(request.environ)
|
action_args = self.get_action_args(request.environ)
|
||||||
action = action_args.pop('action', None)
|
action = action_args.pop('action', None)
|
||||||
|
|
||||||
|
# From reading the boto code, and observation of real AWS api responses
|
||||||
|
# it seems that the AWS api ignores the content-type in the html header
|
||||||
|
# Instead it looks at a "ContentType" GET query parameter
|
||||||
|
# This doesn't seem to be documented in the AWS cfn API spec, but it
|
||||||
|
# would appear that the default response serialization is XML, as
|
||||||
|
# described in the API docs, but passing a query parameter of
|
||||||
|
# ContentType=JSON results in a JSON serialized response...
|
||||||
|
content_type = request.GET.get("ContentType")
|
||||||
|
|
||||||
deserialized_request = self.dispatch(self.deserializer,
|
deserialized_request = self.dispatch(self.deserializer,
|
||||||
action, request)
|
action, request)
|
||||||
action_args.update(deserialized_request)
|
action_args.update(deserialized_request)
|
||||||
|
@ -507,7 +513,12 @@ class Resource(object):
|
||||||
request, **action_args)
|
request, **action_args)
|
||||||
try:
|
try:
|
||||||
response = webob.Response(request=request)
|
response = webob.Response(request=request)
|
||||||
self.dispatch(self.serializer, action, response, action_result)
|
if content_type == "JSON":
|
||||||
|
self.dispatch(JSONResponseSerializer(),
|
||||||
|
action, response, action_result)
|
||||||
|
else:
|
||||||
|
self.dispatch(XMLResponseSerializer(), action,
|
||||||
|
response, action_result)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# return unserializable result (typically a webob exc)
|
# return unserializable result (typically a webob exc)
|
||||||
|
|
Loading…
Reference in New Issue