soap-debug.js 9.5 KB

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