📄 rpcmanager.js
字号:
// // @see attr:rpcRequest.actionURL // // @visibility external //< actionURL:"[ISOMORPHIC]/IDACall", //> @classAttr RPCManager.useXmlHttpRequest (boolean : true if XMLHttpRequest is supported, false otherwise : RW) // // Selects the default http transport for all RPC requests. If set to true, RPCManager // will use XMLHttp for requests to the server. If set to false, it will use hidden // frames. Overrideable on a per-request basis via +link{RPCRequest.useXmlHttpRequest}. // <p> // Note that if the end user disables ActiveX controls in Internet Explorer, the XMLHttpRequest // object will not be available and SmartClient will automatically fall back on frames // communication. // // @deprecated As of SmartClient 5.5, use +link{RPCManager.defaultTransport}. If you // specify a value for this property, it will take precedence over // +link{RPCManager.defaultTransport} for requests that do not specify a // +link{RPCRequest.transport} or +link{RPCRequest.useXmlHttpRequest}. // // @see attr:rpcRequest.useXmlHttpRequest // // @visibility external //< //> @classAttr RPCManager.defaultTransport (RPCTransport : "xmlHttpRequest": IRW) // // Selects the transport use for RPC requests by default. You can override this setting on // a per-request basis by setting +link{rpcRequest.transport}. // // @see rpcRequest.transport // @visibility external //< defaultTransport: "xmlHttpRequest", // whether to ever attempt to use the "HttpProxy" servlet to enable web service requests to // servers other than the origin server. useHttpProxy : (!isc.Browser.isApollo), //> @classAttr RPCManager.dataEncoding (string : RPCManager.dataEncoding : RWA) // // Controls the encoding of the _transaction field of the client->server comm. Valid values are // "XML" and "JS" and enable the XML and Javascript encoding, respectively. // // @visibility internal //< dataEncoding: "XML", //> @classAttr RPCManager.preserveTypes (boolean : RPCManager.preserveTypes : RWA) // // If true, numbers and booleans become Number and Boolean on the server. Otherwise they are // Strings. A true value is currently supported only with dataEncoding: XML. // // @visibility internal //< preserveTypes: true, //> @classAttr RPCManager.credentialsURL (string : RPCManager.credentialsURL : RWA) // // Specifies URL where credentials should be submitted to attempt relogin when session // timeout is encountered during a background RPC. See +link{group:relogin,Relogin} // // @group relogin // @visibility external //< credentialsURL: isc.Page.getIsomorphicDir()+"login/loginSuccessMarker.html", // XXX document loginWindowSettings: "WIDTH=550,HEIGHT=250", // don't scan RPC responses longer than this for relogin commands: 1 Megabyte. Scanning a // file this large for the relogin string on a Core 2 Duo 6700 CPU in IE takes 2.66ms maxLoginPageLength: 1048576, // outstanding transactions to the server and counter. A transaction is a set of // RPCRequests sent to one URL _transactions: Array.create({ // these methods are here for the RPCTracker class that's part of the DevConsole (RPC // tracking) addTrack : function (object, secondArg) { this._lastChanged = object; this.add(object, secondArg); this._lastChanged = null; }, setLastChanged : function (transaction) { this._lastChanged = transaction; }, clearLastChanged : function () { this._lastChanged = null; }, getLastChanged : function () { return this._lastChanged; } }), _nextTransactionNum: 0, _activeTransactions:[], getTransactions : function () { return this._transactions; } });isc.RPCManager.addClassMethods({ //> @classMethod RPCManager.xmlHttpRequestAvailable() // // Returns true if the XMLHttpRequest object is available, false otherwise. See // +link{group:platformDependencies} for more information on when XMLHttpRequest parser may // not available and what features are // impacted as a result. // // @return (boolean) true if XMLHttpRequest is available, false otherwise. // // @visibility external //< xmlHttpRequestAvailable : function () { // createXMLHttpRequest() actually does a new ActiveXObject() in IE, but // we don't cache the result because the user can change ActiveX settings on the fly. // This probably won't happen in actual usage, but developers will almost certainly try // it this way and it needs to work if (isc.Browser.isIE) return (isc.Comm.createXMLHttpRequest() != null); return true; }, // return the action URL, dereferencing any special local directories. // used internally by the RPCManager for url interpolation getActionURL : function () { return isc.Page.getURL(this.actionURL); }, //> @classMethod RPCManager.send() // // This method is a convenience wrapper on <code>RPCManager.sendRequest()</code> - it calls // through to sendRequest(). // // @param data (any) data to be passed to the server // @param [callback] (RPCCallback) method to call on RPC completion // @param [requestParams] (Object) object literal containing any additional properties // you want to set - these will be applied to the // RPCRequest object that will be auto-created for you. // // @see RPCManager.sendRequest() // @see class:RPCRequest // // @visibility external //< send : function (data, callback, requestParams) { var rpcRequest = (requestParams || {}); isc.addProperties(rpcRequest, { data: data, callback: callback }); return this.sendRequest(rpcRequest); }, _warnIfXmlHttpRequestUnavailable : function (featureName) { if (this.xmlHttpRequestAvailable() || !this.logIsWarnEnabled()) return false; var message = "Feature "+featureName+" requires the xmlHttpRequest transport" +" which is not currently available because ActiveX is disabled." +" Please see the 'Features requiring ActiveX or Native support'" +" topic in the client-side reference under Client Reference/System" +" for more information."; this.logWarn(message); return true; },// sendProxied() : send an RPC through an HTTP Proxy// ---------------------------------------------------------------------------------------//> @classMethod RPCManager.sendProxied()// Send an HTTP request to a remote host, potentially through the HttpProxy servlet installed// on the ISC server.// <P>// This API allows contacting services which are hosted on servers other than the origin server// if the HttpProxy servlet is enabled on the ISC server.// <P>// The HttpProxy will be used if the +link{rpcRequest.actionURL} starts with "http" and uses a// hostname other than "localhost" or <code>window.location.hostname</code>, or if// <code>request.useHttpProxy</code> is explicitly set. Otherwise the request goes to the// origin server (the server that returned the current page).// <P>// The +link{RPCRequest} properties that will be respected when relaying requests via the// HttpProxy are: // +link{RPCRequest.actionURL,actionURL}, +link{RPCRequest.httpMethod,httpMethod}, // +link{RPCRequest.params,params}, +link{RPCRequest.contentType,contentType}, // +link{RPCRequest.httpHeaders,httpHeaders}, and +link{RPCRequest.data,data}. In this case// "data", if set, will be used as the request body for an HTTP POST.// <P>// Higher-level APIs like +link{DataSource} or +link{WebService} call through this API, and so// automatically use the HttpProxy if +link{dataSource.dataURL} or// +link{webService.setLocation(),webService.location} is set to a foreign server.// <P>// This API is only suitable for direct use when loading unstructured data that will not be// shown in a +link{DataBoundComponent}. For a WSDL-described web service, use// +link{XMLTools.loadWSDL()} instead. For other web services, use a +link{DataSource} with// +link{DataSource.dataURL,dataURL}, and use +link{DataSource.transformRequest()} and// +link{DataSource.transformResponse()} as necessary to form requests for the service and// transform responses for display.//// @param request (rpcRequest) rpcRequest to be routed through the HttpProxy// @requiresModules SCServer// @visibility external//<sendProxied : function (request, allowRPCFormat) { request.serverOutputAsString = true; request.sendNoQueue = true; // don't use ISC-format multi-op var url = request.actionURL || isc.RPCManager.actionURL; //this.logWarn("url is: " + url); // use the proxy if request.useHttpProxy has been specifically set for this request, or.. var useProxy = (request.useHttpProxy != null ? request.useHttpProxy : // the proxy is available and .. (isc.RPCManager.useHttpProxy && // and the URL appears to be remote (starts with http and not obviously local) url.startsWith("http") && !this.isLocalURL(url))); if (!useProxy) { // contact origin server directly, but don't send the ISC-specific transaction // structure if (!allowRPCFormat) request.useSimpleHttp = true; } else { // contact foreign server by way of HttpProxy, which expects an RPCRequest where "data" // contains configuration for sending an HTTPRequest request = isc.addProperties({}, request, { actionURL : isc.XMLTools.httpProxyURL, // mark as proxied so we can perform better error reporting isProxied: true, // data is parameters the HttpProxy understands useSimpleHttp: true, proxiedURL: url, params : { data : isc.Comm.xmlSerialize("data", { url : url, httpMethod : request.httpMethod, params : request.params, contentType : request.contentType, requestBody : request.data, // NOTE: the only header the proxy actually supports sending through is // "SOAPAction", but we send all headers to the server in case someone wants to // customize this httpHeaders : request.httpHeaders, uploadFileName : request.uploadFileName }) }, // Force XHR on for this request because the proxy will feed us the response // directly and this is the only way to capture it without additional server // support. transport: "xmlHttpRequest", // wipe out these properties since they apply only to the relayed request, not to // the request intended for the HttpProxy servlet. NOTE: we leave httpHeaders // intact in case someone has some kind of advanced usage in mind; RPCManager // ignores all headers by default httpMethod: null, data: null, contentType:null }); //this.logWarn("proxied request: " + this.echo(request) + // ", data for proxy: " + this.echo(request.data) + // ", requestBody: " + this.echo(request.data.requestBody)); } return isc.rpc.sendRequest(request);},// given a URL, get the host without port_getHost : function (url) { var protocol = isc.Page.getProtocol(url), // first slash after the protocol endHostSlash = url.indexOf("/", protocol.length), host = url.substring(protocol.length, endHostSlash); if (host.contains(":")) host = host.substring(0, host.indexOf(":")); return host;},// see if this is a URL that we can access locallyisLocalURL : function (url) { var host = this._getHost(url); // NOTE: bad case: might be accessing wrath.isomorphic.com as just "wrath", in // which case we can't detect that wrath.isomorphic.com is actually a local URL. // To make this check better we might need to actually attempt an XMLHttpRequest for the // ambiguous cases, catch the error, and cache the URL as known good or bad. However // depending on security settings, attempting to access a foreign URL may launch a // confirmation dialog, so the best we can do is probably to try to detect whether the // HttpProxy servlet is installed (whether via a flag dumped by the loadISC tag or a // dynamic requ
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -