]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | // @tag enterprise\r |
2 | /**\r | |
3 | * The SOAP Proxy class is an {@link Ext.data.proxy.Ajax Ajax Proxy} to access v1.1 SOAP\r | |
4 | * (Simple Object Access Protocol) services. SOAP Proxy constructs a SOAP Envelope and \r | |
5 | * submits an AJAX request to load a SOAP response from the server.\r | |
6 | * \r | |
7 | * For help getting started please refer to the [Soap Guide](../../../enterprise/soap.html).\r | |
8 | *\r | |
9 | * **Note: ** _This functionality is only available with the purchase of\r | |
10 | * Sencha Complete. For more information about using this class, please visit\r | |
11 | * our [Sencha Complete](https://www.sencha.com/products/complete/) product page._\r | |
12 | *\r | |
13 | * @class Ext.data.soap.Proxy\r | |
14 | */\r | |
15 | Ext.define('Ext.data.soap.Proxy', {\r | |
16 | extend: 'Ext.data.proxy.Ajax',\r | |
17 | alias: 'proxy.soap',\r | |
18 | \r | |
19 | requires: [\r | |
20 | 'Ext.data.soap.Reader'\r | |
21 | ],\r | |
22 | \r | |
23 | config: {\r | |
24 | /**\r | |
25 | * @cfg {Object} api\r | |
26 | * An object containing "create", "read", "update" and "destroy" properties that define\r | |
27 | * SOAP operations for each CRUD action method. These operations will be appended to\r | |
28 | * the {@link #url} as the {@link #operationParam} for each request type.\r | |
29 | * \r | |
30 | * api: {\r | |
31 | * create: undefined,\r | |
32 | * read: undefined,\r | |
33 | * update: undefined,\r | |
34 | * destroy: undefined\r | |
35 | * }\r | |
36 | * \r | |
37 | * At least one operation is required, but additional operations do not need to be configured\r | |
38 | * if they will not be used. For example, if this proxy is only used for read operations\r | |
39 | * the following configuration will be sufficient:\r | |
40 | * \r | |
41 | * api: {\r | |
42 | * read: 'Foo'\r | |
43 | * }\r | |
44 | */\r | |
45 | \r | |
46 | /**\r | |
47 | * @cfg {Object} soapAction\r | |
48 | * An object containing "create", "read", "update" and "destroy" properties that define\r | |
49 | * the [SOAPAction](http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528) header\r | |
50 | * for each CRUD action method. A soapAction must be specified for each operation\r | |
51 | * configured in {@link #api} Defaults to:\r | |
52 | * \r | |
53 | * soapAction: {\r | |
54 | * create: undefined,\r | |
55 | * read: undefined,\r | |
56 | * update: undefined,\r | |
57 | * destroy: undefined\r | |
58 | * }\r | |
59 | */\r | |
60 | soapAction: {},\r | |
61 | \r | |
62 | /**\r | |
63 | * @cfg {String} [operationParam='op']\r | |
64 | * The name of the operation parameter to be appened to the SOAP endpoint url\r | |
65 | */\r | |
66 | operationParam: 'op',\r | |
67 | \r | |
68 | /**\r | |
69 | * @cfg {Object/String/Ext.data.soap.Reader} [reader='soap']\r | |
70 | * The {@link Ext.data.soap.Reader} to use to decode the server's response. This can\r | |
71 | * either be a SOAP Reader instance, a SOAP Reader config object or 'soap'.\r | |
72 | */\r | |
73 | reader: 'soap',\r | |
74 | \r | |
75 | /**\r | |
76 | * @cfg {String} url\r | |
77 | * The SOAP endpoint url that this proxy will use to request the SOAP data. This can\r | |
78 | * be a proxied url to work around same-origin policy if the SOAP endpoint url is on\r | |
79 | * a different domain from your application.\r | |
80 | */\r | |
81 | url: '',\r | |
82 | \r | |
83 | /**\r | |
84 | * @cfg [envelopeTpl=undefined]\r | |
85 | * The template used to create the SOAP envelope. Defaults to:\r | |
86 | * \r | |
87 | * [\r | |
88 | * '<?xml version="1.0" encoding="utf-8" ?>',\r | |
89 | * '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',\r | |
90 | * '{[values.bodyTpl.apply(values)]}',\r | |
91 | * '</soap:Envelope>'\r | |
92 | * ]\r | |
93 | */\r | |
94 | envelopeTpl: [\r | |
95 | '<?xml version="1.0" encoding="utf-8" ?>',\r | |
96 | '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',\r | |
97 | '{[values.bodyTpl.apply(values)]}',\r | |
98 | '</soap:Envelope>'\r | |
99 | ],\r | |
100 | \r | |
101 | /**\r | |
102 | * @cfg {Ext.XTemplate/Array} createBodyTpl\r | |
103 | * The template used to create the SOAP body for the "create" action. If not specified\r | |
104 | * {@link #writeBodyTpl} will be used for the "create" action.\r | |
105 | */\r | |
106 | createBodyTpl: null,\r | |
107 | \r | |
108 | /**\r | |
109 | * @cfg {Ext.XTemplate/Array} [readBodyTpl=undefined]\r | |
110 | * The template used to create the SOAP body for the "read" action. Defaults to: \r | |
111 | * \r | |
112 | * [\r | |
113 | * '<soap:Body>',\r | |
114 | * '<{operation} xmlns="{targetNamespace}">',\r | |
115 | * '<tpl foreach="params">',\r | |
116 | * '<{$}>{.}</{$}>',\r | |
117 | * '</tpl>',\r | |
118 | * '</{operation}>',\r | |
119 | * '</soap:Body>'\r | |
120 | * ]\r | |
121 | */\r | |
122 | readBodyTpl: [\r | |
123 | '<soap:Body>',\r | |
124 | '<{operation} xmlns="{targetNamespace}">',\r | |
125 | '<tpl foreach="params">',\r | |
126 | '<{$}>{.}</{$}>',\r | |
127 | '</tpl>',\r | |
128 | '</{operation}>',\r | |
129 | '</soap:Body>'\r | |
130 | ],\r | |
131 | \r | |
132 | /**\r | |
133 | * @cfg {Ext.XTemplate/Array} updateBodyTpl\r | |
134 | * The template used to create the SOAP body for the "update" action. If not specified\r | |
135 | * {@link #writeBodyTpl} will be used for the "update" action.\r | |
136 | */\r | |
137 | updateBodyTpl: null,\r | |
138 | \r | |
139 | /**\r | |
140 | * @cfg {Ext.XTemplate/Array} destroyBodyTpl\r | |
141 | * The template used to create the SOAP body for the "destroy" action. If not specified\r | |
142 | * {@link #writeBodyTpl} will be used for the "destroy" action.\r | |
143 | */\r | |
144 | destroyBodyTpl: null,\r | |
145 | \r | |
146 | /**\r | |
147 | * @cfg {Ext.XTemplate/Array} [writeBodyTpl=undefined]\r | |
148 | * The default template used to create the SOAP body for write actions (create, update,\r | |
149 | * and destroy). The individual body templates for each write action can be configured\r | |
150 | * using {@link #createBodyTpl}, {@link #updateBodyTpl}, and {@link #destroyBodyTpl}.\r | |
151 | * Defaults to:\r | |
152 | * \r | |
153 | * [\r | |
154 | * '<soap:Body>',\r | |
155 | * '<{operation} xmlns="{targetNamespace}">',\r | |
156 | * '<tpl for="records">',\r | |
157 | * '{% var recordName=values.modelName.split(".").pop(); %}',\r | |
158 | * '<{[recordName]}>',\r | |
159 | * '<tpl for="fields">',\r | |
160 | * '<{name}>{[parent.get(values.name)]}</{name}>',\r | |
161 | * '</tpl>',\r | |
162 | * '</{[recordName]}>',\r | |
163 | * '</tpl>',\r | |
164 | * '</{operation}>',\r | |
165 | * '</soap:Body>'\r | |
166 | * ]\r | |
167 | */\r | |
168 | writeBodyTpl: [\r | |
169 | '<soap:Body>',\r | |
170 | '<{operation} xmlns="{targetNamespace}">',\r | |
171 | '<tpl for="records">',\r | |
172 | '{% var recordName=values.modelName.split(".").pop(); %}',\r | |
173 | '<{[recordName]}>',\r | |
174 | '<tpl for="fields">',\r | |
175 | '<{name}>{[parent.get(values.name)]}</{name}>',\r | |
176 | '</tpl>',\r | |
177 | '</{[recordName]}>',\r | |
178 | '</tpl>',\r | |
179 | '</{operation}>',\r | |
180 | '</soap:Body>'\r | |
181 | ],\r | |
182 | \r | |
183 | /**\r | |
184 | * @cfg {String} targetNamespace\r | |
185 | * namespace URI used by {@link #createBodyTpl}, {@link #readBodyTpl}, {@link #updateBodyTpl},\r | |
186 | * and {@link #destroyBodyTpl} as the "xmlns" attribute for the operation element.\r | |
187 | */\r | |
188 | targetNamespace: ''\r | |
189 | },\r | |
190 | \r | |
191 | applyEnvelopeTpl: function(tpl) {\r | |
192 | return this.createTpl(tpl);\r | |
193 | },\r | |
194 | \r | |
195 | applyCreateBodyTpl: function(tpl) {\r | |
196 | return this.createTpl(tpl);\r | |
197 | },\r | |
198 | \r | |
199 | applyReadBodyTpl: function(tpl) {\r | |
200 | return this.createTpl(tpl);\r | |
201 | },\r | |
202 | \r | |
203 | applyUpdateBodyTpl: function(tpl) {\r | |
204 | return this.createTpl(tpl);\r | |
205 | },\r | |
206 | \r | |
207 | applyDestroyBodyTpl: function(tpl) {\r | |
208 | return this.createTpl(tpl);\r | |
209 | },\r | |
210 | \r | |
211 | applyWriteBodyTpl: function(tpl) {\r | |
212 | return this.createTpl(tpl);\r | |
213 | },\r | |
214 | \r | |
215 | createTpl: function(tpl) {\r | |
216 | if (tpl && !tpl.isTpl) {\r | |
217 | tpl = new Ext.XTemplate(tpl);\r | |
218 | }\r | |
219 | return tpl;\r | |
220 | },\r | |
221 | \r | |
222 | /**\r | |
223 | * @property {Object} actionMethods\r | |
224 | * @readonly\r | |
225 | * Mapping of action name to HTTP request method. All SOAP actions are mapped to 'POST'\r | |
226 | */\r | |
227 | \r | |
228 | doRequest: function(operation) {\r | |
229 | var me = this,\r | |
230 | action = operation.getAction(),\r | |
231 | soapOperation = me.getApi()[action],\r | |
232 | params = Ext.applyIf(operation.getParams() || {}, me.getExtraParams() || {}),\r | |
233 | xmlData = me.getEnvelopeTpl().apply({\r | |
234 | operation: soapOperation,\r | |
235 | targetNamespace: me.getTargetNamespace(),\r | |
236 | params: params,\r | |
237 | records: operation.getRecords(),\r | |
238 | bodyTpl: me.getBodyTpl(action)\r | |
239 | }),\r | |
240 | request = new Ext.data.Request({\r | |
241 | url: me.getUrl() + '?' + me.getOperationParam() + '=' + soapOperation,\r | |
242 | method: 'POST',\r | |
243 | action: action,\r | |
244 | operation: operation,\r | |
245 | xmlData: xmlData,\r | |
246 | headers: Ext.apply({\r | |
247 | SOAPAction: me.getSoapAction()[action]\r | |
248 | }, me.getHeaders()),\r | |
249 | timeout: me.getTimeout(),\r | |
250 | scope: me,\r | |
251 | disableCaching: false // explicitly set it to false, ServerProxy handles caching\r | |
252 | });\r | |
253 | \r | |
254 | request.setCallback(me.createRequestCallback(request, operation));\r | |
255 | return me.sendRequest(request);\r | |
256 | },\r | |
257 | \r | |
258 | getBodyTpl: function(action) {\r | |
259 | action = Ext.String.capitalize(action);\r | |
260 | var tpl = this['get' + action + 'BodyTpl']();\r | |
261 | return tpl || this.getWriteBodyTpl();\r | |
262 | }\r | |
263 | });\r |