]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | // Package restxml provides RESTful XML serialization of AWS |
2 | // requests and responses. | |
3 | package restxml | |
4 | ||
5 | //go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/input/rest-xml.json build_test.go | |
6 | //go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/output/rest-xml.json unmarshal_test.go | |
7 | ||
8 | import ( | |
9 | "bytes" | |
10 | "encoding/xml" | |
11 | ||
12 | "github.com/aws/aws-sdk-go/aws/awserr" | |
13 | "github.com/aws/aws-sdk-go/aws/request" | |
14 | "github.com/aws/aws-sdk-go/private/protocol/query" | |
15 | "github.com/aws/aws-sdk-go/private/protocol/rest" | |
16 | "github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil" | |
17 | ) | |
18 | ||
19 | // BuildHandler is a named request handler for building restxml protocol requests | |
20 | var BuildHandler = request.NamedHandler{Name: "awssdk.restxml.Build", Fn: Build} | |
21 | ||
22 | // UnmarshalHandler is a named request handler for unmarshaling restxml protocol requests | |
23 | var UnmarshalHandler = request.NamedHandler{Name: "awssdk.restxml.Unmarshal", Fn: Unmarshal} | |
24 | ||
25 | // UnmarshalMetaHandler is a named request handler for unmarshaling restxml protocol request metadata | |
26 | var UnmarshalMetaHandler = request.NamedHandler{Name: "awssdk.restxml.UnmarshalMeta", Fn: UnmarshalMeta} | |
27 | ||
28 | // UnmarshalErrorHandler is a named request handler for unmarshaling restxml protocol request errors | |
29 | var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.restxml.UnmarshalError", Fn: UnmarshalError} | |
30 | ||
31 | // Build builds a request payload for the REST XML protocol. | |
32 | func Build(r *request.Request) { | |
33 | rest.Build(r) | |
34 | ||
35 | if t := rest.PayloadType(r.Params); t == "structure" || t == "" { | |
36 | var buf bytes.Buffer | |
37 | err := xmlutil.BuildXML(r.Params, xml.NewEncoder(&buf)) | |
38 | if err != nil { | |
107c1cdb ND |
39 | r.Error = awserr.NewRequestFailure( |
40 | awserr.New("SerializationError", "failed to encode rest XML request", err), | |
41 | r.HTTPResponse.StatusCode, | |
42 | r.RequestID, | |
43 | ) | |
bae9f6d2 JC |
44 | return |
45 | } | |
46 | r.SetBufferBody(buf.Bytes()) | |
47 | } | |
48 | } | |
49 | ||
50 | // Unmarshal unmarshals a payload response for the REST XML protocol. | |
51 | func Unmarshal(r *request.Request) { | |
52 | if t := rest.PayloadType(r.Data); t == "structure" || t == "" { | |
53 | defer r.HTTPResponse.Body.Close() | |
54 | decoder := xml.NewDecoder(r.HTTPResponse.Body) | |
55 | err := xmlutil.UnmarshalXML(r.Data, decoder, "") | |
56 | if err != nil { | |
107c1cdb ND |
57 | r.Error = awserr.NewRequestFailure( |
58 | awserr.New("SerializationError", "failed to decode REST XML response", err), | |
59 | r.HTTPResponse.StatusCode, | |
60 | r.RequestID, | |
61 | ) | |
bae9f6d2 JC |
62 | return |
63 | } | |
64 | } else { | |
65 | rest.Unmarshal(r) | |
66 | } | |
67 | } | |
68 | ||
69 | // UnmarshalMeta unmarshals response headers for the REST XML protocol. | |
70 | func UnmarshalMeta(r *request.Request) { | |
71 | rest.UnmarshalMeta(r) | |
72 | } | |
73 | ||
74 | // UnmarshalError unmarshals a response error for the REST XML protocol. | |
75 | func UnmarshalError(r *request.Request) { | |
76 | query.UnmarshalError(r) | |
77 | } |