1 include(bbq.ajax.SoapRequest);
  2 
  3 bbq.ajax.ForwardingSoapRequest = Class.create(bbq.ajax.SoapRequest, /** @lends bbq.ajax.ForwardingSoapRequest.prototype */ {
  4 	/**
  5 	 * This class is designed to be used with the org.bbqjs.spring.ajax.RequestForwarder class
  6 	 * and attepts to work around the same origin policy of most browsers in terms of AJAX.
  7 	 *
  8 	 * The policy means that you can only dispatch an AJAX request to the server from which
  9 	 * the JavaScript dispatching the request was loaded.  So if you deliver your code from
 10 	 * http://www.example.org, you cannot make a request to http://api.google.com.
 11 	 *
 12 	 * The RequestForwarder class will forward on the request to the location specified in the
 13 	 * url property of the options argument, even if it's a different domain.
 14 	 *
 15 	 * Other than that it behaves in the same way as bbq.ajax.SoapRequest
 16 	 *
 17 	 * @example
 18 	 * <pre><code class="language-javascript">
 19 	 *
 20 	 * var request = new bbq.ajax.ForwardingSoapRequest({
 21 	 *     url: "http://api.google.com",
 22 	 *     onSuccess: function(serverRequest, json) {
 23 	 *
 24 	 *     }
 25 	 *     ... // more args similar to bbq.ajax.SoapRequest
 26 	 * });
 27 	 *
 28 	 * </code></pre>
 29 	 * @constructs
 30 	 * @param {Object} options
 31 	 * @extends bbq.ajax.SoapRequest
 32 	 */
 33 	initialize: function($super, options) {
 34 		options.forwardTo = options.url;
 35 		options.url = "/forward";
 36 		
 37 		$super(options);
 38 	},
 39 	
 40 	_createRequestHeaders: function($super) {
 41 		var headers = $super();
 42 		headers["X-BBQ-Forward-To"] = this.options.forwardTo;
 43 		
 44 		return headers;
 45 	},
 46 	
 47 	onSuccess: function(serverResponse) {
 48 		if(serverResponse.getResponseHeader("X-responseType") == -100) {
 49 			this._callHandler("onError", $A(arguments));
 50 		} else {
 51 			this._callHandler("onSuccess", $A(arguments));
 52 		}
 53 	}
 54 });
 55