f3c195cf by Ean Schuessler

Initial service version, static support files

1 parent 6413f550
...@@ -7,5 +7,14 @@ ...@@ -7,5 +7,14 @@
7 <classpath type="jar" location="lib/*"/> 7 <classpath type="jar" location="lib/*"/>
8 <classpath type="jar" location="build/lib/*"/> 8 <classpath type="jar" location="build/lib/*"/>
9 9
10 <service-resource type="model" loader="main" location="servicedef/services.xml"/>
11
12 <webapp name="comet-messenger"
13 title="Comet Messenger"
14 server="default-server"
15 location="webapp"
16 mount-point="/comet"
17 app-bar-display="false"/>
18
10 </ofbiz-component> 19 </ofbiz-component>
11 20
......
...@@ -5,4 +5,19 @@ ...@@ -5,4 +5,19 @@
5 <vendor>DriverUp</vendor> 5 <vendor>DriverUp</vendor>
6 <version>1.0</version> 6 <version>1.0</version>
7 7
8 <service name="sendCometMessage" engine="java"
9 location="com.brainfood.ofbiz.CometMessengerServlet"
10 invoke="sendMessage" auth="false">
11 <attribute name="realm" type="String" mode="IN" optional="false"/>
12 <attribute name="channel" type="String" mode="IN" optional="false"/>
13 <attribute name="message" type="String" mode="IN" optional="false"/>
14 </service>
15
16 <service name="receiveCometMessage" engine="java"
17 location="com.brainfood.ofbiz.CometMessengerServlet"
18 invoke="receiveMessage" auth="false">
19 <attribute name="realm" type="String" mode="IN" optional="false"/>
20 <attribute name="channel" type="String" mode="IN" optional="false"/>
21 <attribute name="message" type="String" mode="IN" optional="false"/>
22 </service>
8 </services> 23 </services>
......
1 <?xml version="1.0"?>
2 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
3
4 <!--
5 Licensed to the Apache Software Foundation (ASF) under one
6 or more contributor license agreements. See the NOTICE file
7 distributed with this work for additional information
8 regarding copyright ownership. The ASF licenses this file
9 to you under the Apache License, Version 2.0 (the
10 "License"); you may not use this file except in compliance
11 with the License. You may obtain a copy of the License at
12
13 http://www.apache.org/licenses/LICENSE-2.0
14
15 Unless required by applicable law or agreed to in writing,
16 software distributed under the License is distributed on an
17 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 KIND, either express or implied. See the License for the
19 specific language governing permissions and limitations
20 under the License.
21 -->
22
23 <web-app>
24 <display-name>DriverUp API</display-name>
25 <description>DriverUp API</description>
26
27 <context-param>
28 <param-name>entityDelegatorName</param-name>
29 <param-value>default</param-value>
30 <description>The Name of the Entity Delegator to use, defined in entityengine.xml</description>
31 </context-param>
32 <context-param>
33 <param-name>localDispatcherName</param-name>
34 <param-value>cometmessenger</param-value>
35 <description>A unique name used to identify/recognize the local dispatcher for the Service Engine</description>
36 </context-param>
37
38 <servlet>
39 <servlet-name>CometMessengerServlet</servlet-name>
40 <display-name>CometMessengerServlet</display-name>
41 <description>Comet Messenger Servlet</description>
42 <servlet-class>com.brainfood.ofbiz.CometMessengerServlet</servlet-class>
43 <load-on-startup>1</load-on-startup>
44 </servlet>
45 <servlet-mapping>
46 <servlet-name>CometMessengerServlet</servlet-name>
47 <url-pattern>/messenger</url-pattern>
48 </servlet-mapping>
49 </web-app>
1 define([], function() {
2 var listeners = [];
3 var messenger = {
4 process: function() {
5 var url = "/comet/messenger"
6 var request = new XMLHttpRequest();
7 var responseLength = 0;
8 request.open("GET", url, true);
9 request.setRequestHeader("Content-Type","application/x-javascript;");
10 request.onreadystatechange = function() {
11 if (request.readyState == 3 || request.readyState == 4) {
12 if (request.status == 200){
13 if (request.responseText) {
14 var newText = request.responseText.substr(responseLength);
15 if (newText.length > 0) {
16 for (var i=0; i < listeners.length; i++) {
17 listeners[i](newText);
18 }
19 }
20 responseLength = request.responseText.length;
21 }
22 }
23 if (request.readyState == 4) {
24 if (request.status == 200) {
25 messenger.process();
26 } else {
27 console.log('Error, retrying in 5 seconds');
28 setTimeout(function() { messenger.process(); }, 5000);
29 }
30 }
31 }
32 };
33 request.send(null);
34 },
35 addListener: function(listener) {
36 listeners.push(listener);
37 },
38 removeListener: function(listener) {
39 var index = listeners.indexOf(listener);
40 if (index > -1) {
41 array.splice(index, 1);
42 }
43 }
44 }
45 messenger.process();
46
47 return messenger;
48 });