From cd7d1fa7adaa890bae754e7035fe991ce1c25b56 Mon Sep 17 00:00:00 2001 From: fmoga Date: Mon, 20 Sep 2010 18:00:18 +0000 Subject: Added binding comet runtime for experiments. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@999029 13f79535-47bb-0310-9956-ffa450edef68 --- ...che.tuscany.sca.provider.BindingProviderFactory | 20 + .../src/main/resources/cometComponentContext.js | 48 ++ .../src/main/resources/jquery.atmosphere.js | 534 +++++++++++++++++++++ .../src/main/resources/jquery.json-2.2.min.js | 31 ++ 4 files changed, 633 insertions(+) create mode 100644 sandbox/fmoga/binding-comet-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sandbox/fmoga/binding-comet-runtime/src/main/resources/cometComponentContext.js create mode 100644 sandbox/fmoga/binding-comet-runtime/src/main/resources/jquery.atmosphere.js create mode 100644 sandbox/fmoga/binding-comet-runtime/src/main/resources/jquery.json-2.2.min.js (limited to 'sandbox/fmoga/binding-comet-runtime/src/main/resources') diff --git a/sandbox/fmoga/binding-comet-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sandbox/fmoga/binding-comet-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..cb6db39c4e --- /dev/null +++ b/sandbox/fmoga/binding-comet-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.comet.runtime.CometBindingProviderFactory;model=org.apache.tuscany.sca.binding.comet.CometBinding + diff --git a/sandbox/fmoga/binding-comet-runtime/src/main/resources/cometComponentContext.js b/sandbox/fmoga/binding-comet-runtime/src/main/resources/cometComponentContext.js new file mode 100644 index 0000000000..9d9254199e --- /dev/null +++ b/sandbox/fmoga/binding-comet-runtime/src/main/resources/cometComponentContext.js @@ -0,0 +1,48 @@ + +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +var SCA = new function() { + +this.TuscanyComet = { + appUrl: 'tuscany-comet', + connectedEndpoint : null, + connect : function(transport) { + $.atmosphere.subscribe(document.location.toString() + this.appUrl, + this.callback, + $.atmosphere.request = { + transport : transport + }); + this.connectedEndpoint = $.atmosphere.response; + }, + callAsync : function(url, params, callbackMethod) { + this.connectedEndpoint.push(document.location.toString() + + this.appUrl + '/' + url, + null, + $.atmosphere.request = { + method : 'POST', + data : 'callback=' + callbackMethod.name + '¶ms=' + params + }); + }, + callback : function(response) { + eval(response.responseBody); + } +}; + +this.CometComponentContext = new Object(); diff --git a/sandbox/fmoga/binding-comet-runtime/src/main/resources/jquery.atmosphere.js b/sandbox/fmoga/binding-comet-runtime/src/main/resources/jquery.atmosphere.js new file mode 100644 index 0000000000..eb94c9f6f5 --- /dev/null +++ b/sandbox/fmoga/binding-comet-runtime/src/main/resources/jquery.atmosphere.js @@ -0,0 +1,534 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +jQuery.atmosphere = function() +{ + var activeRequest; + $(window).unload(function() + { + if (activeRequest) + activeRequest.abort(); + }); + + return { + version : 0.7, + response : { + status: 200, + responseBody : '', + headers : [], + state : "messageReceived", + transport : "polling", + push : [], + error: null, + id : 0 + }, + + request : {}, + logLevel : 'info', + callbacks: [], + activeTransport : null, + websocket : null, + killHiddenIFrame : null, + + subscribe: function(url, callback, request) + { + jQuery.atmosphere.request = jQuery.extend({ + timeout: 300000, + method: 'GET', + headers: {}, + contentType : "text/html;charset=ISO-8859-1", + cache: true, + async: true, + ifModified: false, + callback: null, + dataType: '', + url : url, + data : '', + suspend : true, + maxRequest : 60, + lastIndex : 0, + logLevel : 'info', + requestCount : 0, + fallbackTransport : 'streaming', + transport : 'long-polling' + + }, request); + + logLevel = jQuery.atmosphere.request.logLevel || 'info'; + if (callback != null) { + jQuery.atmosphere.addCallback(callback); + jQuery.atmosphere.request.callback = callback; + } + + if (jQuery.atmosphere.request.transport != jQuery.atmosphere.activeTransport) { + jQuery.atmosphere.closeSuspendedConnection(); + } + jQuery.atmosphere.activeTransport = jQuery.atmosphere.request.transport; + + if (jQuery.atmosphere.request.transport != 'websocket') { + jQuery.atmosphere.executeRequest(); + } else if (jQuery.atmosphere.request.transport == 'websocket') { + if (!window.WebSocket) { + jQuery.atmosphere.log(logLevel, ["Websocket is not supported, using request.fallbackTransport"]); + jQuery.atmosphere.request.transport = jQuery.atmosphere.request.fallbackTransport; + jQuery.atmosphere.executeRequest(); + } + else { + jQuery.atmosphere.executeWebSocket(); + } + } + }, + + /** + * Always make sure one transport is used, not two at the same time except for Websocket. + */ + closeSuspendedConnection : function () { + if (activeRequest != null) { + activeRequest.abort(); + } + + if (jQuery.atmosphere.websocket != null) { + jQuery.atmosphere.websocket.close(); + jQuery.atmosphere.websocket = null; + } + }, + + executeRequest: function() + { + + if (jQuery.atmosphere.request.transport == 'streaming') { + if ($.browser.msie) { + jQuery.atmosphere.ieStreaming(); + return; + } else if ((typeof window.addEventStream) == 'function') { + jQuery.atmosphere.operaStreaming(); + return; + } + } + + if (jQuery.atmosphere.request.requestCount++ < jQuery.atmosphere.request.maxRequest) { + jQuery.atmosphere.response.push = function (url) + { + jQuery.atmosphere.request.callback = null; + jQuery.atmosphere.publish(url, null, jQuery.atmosphere.request); + }; + + var request = jQuery.atmosphere.request; + var response = jQuery.atmosphere.response; + if (request.transport != 'polling') { + response.transport = request.transport; + } + + var ajaxRequest; + var error = false; + if ($.browser.msie) { + var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] + for (var i = 0; i < activexmodes.length; i++) { + try { + ajaxRequest = new ActiveXObject(activexmodes[i]) + } + catch(e) { + } + } + } else if (window.XMLHttpRequest) { + ajaxRequest = new XMLHttpRequest(); + } + + if (request.suspend) { + activeRequest = ajaxRequest; + } + + ajaxRequest.open(request.method, request.url, true); + ajaxRequest.setRequestHeader("X-Atmosphere-Framework", jQuery.atmosphere.version); + ajaxRequest.setRequestHeader("X-Atmosphere-Transport", request.transport); + ajaxRequest.setRequestHeader("X-Cache-Date", new Date()); + + if (!$.browser.msie) { + ajaxRequest.onerror = function() + { + error = true; + try { + response.status = XMLHttpRequest.status; + } + catch(e) { + response.status = 404; + } + + response.state = "error"; + jQuery.atmosphere.invokeCallback(response); + ajaxRequest.abort(); + activeRequest = null; + } + } + + ajaxRequest.onreadystatechange = function() + { + var junkForWebkit = false; + var update = false; + if (ajaxRequest.readyState == 4) { + jQuery.atmosphere.request = request; + if (request.suspend && ajaxRequest.status == 200) { + jQuery.atmosphere.executeRequest(); + } + + if ($.browser.msie) { + update = true; + } + } else if (!$.browser.msie && ajaxRequest.readyState == 3 && ajaxRequest.status == 200) { + update = true; + } else { + clearTimeout(request.id); + } + + if (update) { + if (request.transport == 'streaming') { + response.responseBody = ajaxRequest.responseText.substring(request.lastIndex, ajaxRequest.responseText.length); + request.lastIndex = ajaxRequest.responseText.length; + + if (response.responseBody.indexOf("