f3c195cf by Ean Schuessler

Initial service version, static support files

1 parent 6413f550
......@@ -7,5 +7,14 @@
<classpath type="jar" location="lib/*"/>
<classpath type="jar" location="build/lib/*"/>
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
<webapp name="comet-messenger"
title="Comet Messenger"
server="default-server"
location="webapp"
mount-point="/comet"
app-bar-display="false"/>
</ofbiz-component>
......
......@@ -5,4 +5,19 @@
<vendor>DriverUp</vendor>
<version>1.0</version>
<service name="sendCometMessage" engine="java"
location="com.brainfood.ofbiz.CometMessengerServlet"
invoke="sendMessage" auth="false">
<attribute name="realm" type="String" mode="IN" optional="false"/>
<attribute name="channel" type="String" mode="IN" optional="false"/>
<attribute name="message" type="String" mode="IN" optional="false"/>
</service>
<service name="receiveCometMessage" engine="java"
location="com.brainfood.ofbiz.CometMessengerServlet"
invoke="receiveMessage" auth="false">
<attribute name="realm" type="String" mode="IN" optional="false"/>
<attribute name="channel" type="String" mode="IN" optional="false"/>
<attribute name="message" type="String" mode="IN" optional="false"/>
</service>
</services>
......
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<!--
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.
-->
<web-app>
<display-name>DriverUp API</display-name>
<description>DriverUp API</description>
<context-param>
<param-name>entityDelegatorName</param-name>
<param-value>default</param-value>
<description>The Name of the Entity Delegator to use, defined in entityengine.xml</description>
</context-param>
<context-param>
<param-name>localDispatcherName</param-name>
<param-value>cometmessenger</param-value>
<description>A unique name used to identify/recognize the local dispatcher for the Service Engine</description>
</context-param>
<servlet>
<servlet-name>CometMessengerServlet</servlet-name>
<display-name>CometMessengerServlet</display-name>
<description>Comet Messenger Servlet</description>
<servlet-class>com.brainfood.ofbiz.CometMessengerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CometMessengerServlet</servlet-name>
<url-pattern>/messenger</url-pattern>
</servlet-mapping>
</web-app>
define([], function() {
var listeners = [];
var messenger = {
process: function() {
var url = "/comet/messenger"
var request = new XMLHttpRequest();
var responseLength = 0;
request.open("GET", url, true);
request.setRequestHeader("Content-Type","application/x-javascript;");
request.onreadystatechange = function() {
if (request.readyState == 3 || request.readyState == 4) {
if (request.status == 200){
if (request.responseText) {
var newText = request.responseText.substr(responseLength);
if (newText.length > 0) {
for (var i=0; i < listeners.length; i++) {
listeners[i](newText);
}
}
responseLength = request.responseText.length;
}
}
if (request.readyState == 4) {
if (request.status == 200) {
messenger.process();
} else {
console.log('Error, retrying in 5 seconds');
setTimeout(function() { messenger.process(); }, 5000);
}
}
}
};
request.send(null);
},
addListener: function(listener) {
listeners.push(listener);
},
removeListener: function(listener) {
var index = listeners.indexOf(listener);
if (index > -1) {
array.splice(index, 1);
}
}
}
messenger.process();
return messenger;
});