Skip to content
Snippets Groups Projects
Commit 11e665cb authored by Constantin Jucovschi's avatar Constantin Jucovschi
Browse files

adding appjs theo

parent f4cdd773
No related branches found
No related tags found
No related merge requests found
Showing with 384 additions and 16 deletions
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema. // Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2014.04.17 at 03:49:09 PM CEST // Generated on: 2014.04.23 at 01:50:46 PM CEST
// //
package info.kwarc.sally.comm.core; package info.kwarc.sally.comm.select;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
......
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2014.04.23 at 01:50:46 PM CEST
//
@javax.xml.bind.annotation.XmlSchema(namespace = "http://kwarc.info/sally/comm/select")
package info.kwarc.sally.comm.select;
...@@ -23,15 +23,6 @@ ...@@ -23,15 +23,6 @@
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="onsallyframe">
<xs:complexType>
<xs:sequence>
<xs:element name="posx" type="xs:int" />
<xs:element name="posy" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="heartbeatrequest"> <xs:element name="heartbeatrequest">
<xs:complexType> <xs:complexType>
</xs:complexType> </xs:complexType>
......
<?xml version="1.0"?> <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://kwarc.info/sally/comm/select"> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://kwarc.info/sally/comm/select">
<xs:element name="onsallyframe">
<xs:complexType>
<xs:sequence>
<xs:element name="posx" type="xs:int" />
<xs:element name="posy" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema> </xs:schema>
\ No newline at end of file
...@@ -92,7 +92,6 @@ public class SallyDocImpl extends RouteBuilder implements SallyDoc { ...@@ -92,7 +92,6 @@ public class SallyDocImpl extends RouteBuilder implements SallyDoc {
@Override @Override
public ProducerConsumerSplitterComponent getAlexComponent() { public ProducerConsumerSplitterComponent getAlexComponent() {
log.info("will start on queue "+docStateQueue);
return new ProducerConsumerSplitterComponent("activemq:queue:"+docStateQueue, "activemq:queue:"+docQueue); return new ProducerConsumerSplitterComponent("activemq:queue:"+docStateQueue, "activemq:queue:"+docQueue);
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
<module>planetary</module> <module>planetary</module>
<module>servlet</module> <module>servlet</module>
<module>MathHubWorker</module> <module>MathHubWorker</module>
<module>OfficeBase</module>
<module>activemq</module> <module>activemq</module>
</modules> </modules>
......
node
node_modules
\ No newline at end of file
appjs = require('appjs');
async = require "async"
http = require('http')
express = require('express');
connect = require('connect')
SallyClient = (require "./sally_client").SallyClient
stomp_args =
port : 61613,
host: 'localhost',
login: 'webclient',
passcode: 'webclient',
# debug: true,
handler = (body, msg) =>
console.log(msg);
sally = new SallyClient stomp_args, handler
sally.connect ["theo"], (body, msg)->
console.log("connected ");
createNewWindow = (body) ->
window = appjs.createWindow(body.url, {
width : 640,
height : 460,
});
window.on('create', () ->
window.frame.show();
window.frame.center();
)
window.on('ready', () ->
window.process = process;
window.module = module;
);
window.on('close', () ->
console.log("Window Closed");
);
#process.on 'SIGINT', () ->
# client.disconnect()
// Generated by CoffeeScript 1.6.3
(function() {
var SallyClient, appjs, async, connect, createNewWindow, express, handler, http, sally, stomp_args,
_this = this;
appjs = require('appjs');
async = require("async");
http = require('http');
express = require('express');
connect = require('connect');
SallyClient = (require("./sally_client")).SallyClient;
stomp_args = {
port: 61613,
host: 'localhost',
login: 'webclient',
passcode: 'webclient'
};
handler = function(body, msg) {
return console.log(msg);
};
sally = new SallyClient(stomp_args, handler);
sally.connect(["theo"], function(body, msg) {
return console.log("connected ");
});
createNewWindow = function(body) {
var window;
window = appjs.createWindow(body.url, {
width: 640,
height: 460
});
window.on('create', function() {
window.frame.show();
return window.frame.center();
});
window.on('ready', function() {
window.process = process;
return window.module = module;
});
return window.on('close', function() {
return console.log("Window Closed");
});
};
}).call(this);
<!doctype html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
#!/bin/bash
node/bin/npm install $1
\ No newline at end of file
Stomp = require "stomp"
xml2js = require("xml2js");
EventEmitter = require('events').EventEmitter
builder = new xml2js.Builder()
createRegisterDocument = (docQueue, theoQueue, interfaces) ->
{
"registerdocument" :
'$' :
"xmlns" : "http://kwarc.info/sally/comm/core"
"documentqueue" : [ docQueue ],
"environmentid" : [ process.env.SALLYENVID ],
"interfaces" : interfaces
}
connections = {};
class SallyClient
constructor : (@config, @msgHandler) ->
if connections[config.stompUrl]?
@stompClient = connections[config.stompUrl]
else
@stompClient = new Stomp.Stomp(config)
connections[config.stompUrl] = @stompClient
@stompClient.connect()
@stompClient.on "connected", =>
@stompClient.connection_div.emit("onConnected");
registerDocument : (interfaces, callback) =>
msg = createRegisterDocument(@privateQueue, @privateQueue+"_theo", interfaces)
@send("/queue/sally_register", msg, (msg) =>
@sally_queue = msg["registerdocumentresponse"]["sallyqueue"];
callback();
)
connect : (@interfaces, callback) ->
client = @stompClient
if client.connected
return callback();
if not client.connection_div?
client.connection_div = new EventEmitter();
client.connection_div.on("onConnected", (e) =>
@privateQueue = "theo_"+Math.floor(Math.random()*100000);
@stompClient.subscribe({destination : "/queue/"+@privateQueue}, @stompMsgHandler)
@registerDocument(@interfaces, callback)
)
sendSally : (msg, callback, headers) ->
@send(@sally_queue, msg, callback, headers)
send : (destination, msg, callback, headers) ->
if typeof msg == "object"
msg = builder.buildObject(msg)
if callback?
corrid = Math.random();
queue_post = "/temp-queue/editor_exchange"+corrid;
sub = @stompClient.subscribe({destination : queue_post}, (msg) =>
xml2js.parseString msg, (err, body) =>
if (not body.html?) and callback(body, msg) == true
return;
@stompClient.unsubscribe({destination : queue_post});
)
headers ?= {};
headers["reply-to"] = queue_post;
headers["correlation-id"] = corrid;
headers["destination"] = destination;
headers["body"] = msg;
@stompClient.send(headers)
stompMsgHandler : (msg, msgHeaders) =>
msg = msg[0];
body = xml2js.parseString msg, (err,body) =>
if body["heartbeatrequest"]? and body["heartbeatrequest"]["$"]["xmlns"] == "http://kwarc.info/sally/comm/core"
@send(msgHeaders["reply-to"], {"heartbeatresponse" : {"$" : { "xmlns" : "http://kwarc.info/sally/comm/core"}}}, null,
{"correlation-id" : msgHeaders["correlation-id"]})
return;
@msgHandler(body, msg, (sendBack) =>
@send(msgHeaders["reply-to"], sendBack, null,
{"correlation-id" : msgHeaders["correlation-id"]})
);
exports.SallyClient = SallyClient
\ No newline at end of file
// Generated by CoffeeScript 1.6.3
var EventEmitter, SallyClient, Stomp, builder, connections, createRegisterDocument, xml2js,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Stomp = require("stomp");
xml2js = require("xml2js");
EventEmitter = require('events').EventEmitter;
builder = new xml2js.Builder();
createRegisterDocument = function(docQueue, theoQueue, interfaces) {
return {
"registerdocument": {
'$': {
"xmlns": "http://kwarc.info/sally/comm/core"
},
"documentqueue": [docQueue],
"environmentid": [process.env.SALLYENVID],
"interfaces": interfaces
}
};
};
connections = {};
SallyClient = (function() {
function SallyClient(config, msgHandler) {
var _this = this;
this.config = config;
this.msgHandler = msgHandler;
this.stompMsgHandler = __bind(this.stompMsgHandler, this);
this.registerDocument = __bind(this.registerDocument, this);
if (connections[config.stompUrl] != null) {
this.stompClient = connections[config.stompUrl];
} else {
this.stompClient = new Stomp.Stomp(config);
connections[config.stompUrl] = this.stompClient;
this.stompClient.connect();
this.stompClient.on("connected", function() {
return _this.stompClient.connection_div.emit("onConnected");
});
}
}
SallyClient.prototype.registerDocument = function(interfaces, callback) {
var msg,
_this = this;
msg = createRegisterDocument(this.privateQueue, this.privateQueue + "_theo", interfaces);
return this.send("/queue/sally_register", msg, function(msg) {
_this.sally_queue = msg["registerdocumentresponse"]["sallyqueue"];
return callback();
});
};
SallyClient.prototype.connect = function(interfaces, callback) {
var client,
_this = this;
this.interfaces = interfaces;
client = this.stompClient;
if (client.connected) {
return callback();
}
if (client.connection_div == null) {
client.connection_div = new EventEmitter();
}
return client.connection_div.on("onConnected", function(e) {
_this.privateQueue = "theo_" + Math.floor(Math.random() * 100000);
_this.stompClient.subscribe({
destination: "/queue/" + _this.privateQueue
}, _this.stompMsgHandler);
return _this.registerDocument(_this.interfaces, callback);
});
};
SallyClient.prototype.sendSally = function(msg, callback, headers) {
return this.send(this.sally_queue, msg, callback, headers);
};
SallyClient.prototype.send = function(destination, msg, callback, headers) {
var corrid, queue_post, sub,
_this = this;
if (typeof msg === "object") {
msg = builder.buildObject(msg);
}
if (callback != null) {
corrid = Math.random();
queue_post = "/temp-queue/editor_exchange" + corrid;
sub = this.stompClient.subscribe({
destination: queue_post
}, function(msg) {
return xml2js.parseString(msg, function(err, body) {
if ((body.html == null) && callback(body, msg) === true) {
return;
}
return _this.stompClient.unsubscribe({
destination: queue_post
});
});
});
if (headers == null) {
headers = {};
}
headers["reply-to"] = queue_post;
headers["correlation-id"] = corrid;
}
headers["destination"] = destination;
headers["body"] = msg;
return this.stompClient.send(headers);
};
SallyClient.prototype.stompMsgHandler = function(msg, msgHeaders) {
var body,
_this = this;
msg = msg[0];
return body = xml2js.parseString(msg, function(err, body) {
if ((body["heartbeatrequest"] != null) && body["heartbeatrequest"]["$"]["xmlns"] === "http://kwarc.info/sally/comm/core") {
_this.send(msgHeaders["reply-to"], {
"heartbeatresponse": {
"$": {
"xmlns": "http://kwarc.info/sally/comm/core"
}
}
}, null, {
"correlation-id": msgHeaders["correlation-id"]
});
return;
}
return _this.msgHandler(body, msg, function(sendBack) {
return _this.send(msgHeaders["reply-to"], sendBack, null, {
"correlation-id": msgHeaders["correlation-id"]
});
});
});
};
return SallyClient;
})();
exports.SallyClient = SallyClient;
coffee -c app.coffee
node/bin/node --harmony app.js
\ No newline at end of file
...@@ -7,6 +7,8 @@ import org.apache.camel.Exchange; ...@@ -7,6 +7,8 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.slf4j.Logger; import org.slf4j.Logger;
import com.sun.xml.txw2.annotation.XmlNamespace;
public class EnrichMessageProperties implements Processor { public class EnrichMessageProperties implements Processor {
static final public String MessageType = "XMLMessageType"; static final public String MessageType = "XMLMessageType";
...@@ -15,14 +17,15 @@ public class EnrichMessageProperties implements Processor { ...@@ -15,14 +17,15 @@ public class EnrichMessageProperties implements Processor {
Logger log; Logger log;
Pattern xmlNamespace = Pattern.compile("<(\\w+)\\s+xmlns=\"([\\w/:.]+)\"/>"); Pattern xmlNamespace = Pattern.compile("<(\\w+)\\s+xmlns=\"([\\w/:.]+)\"/>");
Pattern xmlNamespace2 = Pattern.compile("<((\\w+):)?(\\w+)\\s+xmlns(:(\\w+))?=\"([\\w/:.]+)\">");
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
XMLMessageWithTypeInfo result = new XMLMessageWithTypeInfo(); XMLMessageWithTypeInfo result = new XMLMessageWithTypeInfo();
String body = exchange.getIn().getBody(String.class); String body = exchange.getIn().getBody(String.class);
Matcher m = xmlNamespace.matcher(body); Matcher m = xmlNamespace2.matcher(body);
if (m.find()) { if (m.find()) {
String msgType = m.group(1); String msgType = m.group(3);
String namespace = m.group(2); String namespace = m.group(6);
result.setXmlMessageNamespace(namespace); result.setXmlMessageNamespace(namespace);
result.setXmlMessageType(msgType); result.setXmlMessageType(msgType);
exchange.getIn().setBody(result); exchange.getIn().setBody(result);
...@@ -31,4 +34,13 @@ public class EnrichMessageProperties implements Processor { ...@@ -31,4 +34,13 @@ public class EnrichMessageProperties implements Processor {
} }
} }
public static void main(String[] args) {
String t = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:onsallyframe xmlns:ns2=\"http://kwarc.info/sally/comm/select\">";
Pattern xmlNamespace2 = Pattern.compile("");
Matcher m = xmlNamespace2.matcher(t);
if (m.find()) {
System.out.println(m.group(3));
System.out.println(m.group(6));
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment