In this hello word example, the loading of a web page causes the message “helloworld” to appear.
This example can be downloaded here
The message appears as a result of an invocation of the JXS service which is configured to use config.xml. This example config.xml looks like this,
<Config>
<appId>helloworld</appId>
<requestdetails>
<jmsTopicConfig>
<topicname>DEMO_INPUT</topicname>
<connectionfactory>embedded</connectionfactory> <providerurl>tcp://localhost:61616</providerurl>
<initialcontextfactory>org.apache.activemq.jndi.ActiveMQInitialContextFactory </initialcontextfactory>
</jmsTopicConfig>
</requestdetails>
<token>$</token>
<xpathtoken>?</xpathtoken>
<actions>
<Action>
<xmlaction>
<xquery>
<actionid>
<id><IdStr>displayresults</IdStr></id>
</actionid>
<xqueryaction>
<![CDATA[ <displayresults>
<response>
{
let $doc := .
let $doc1 := "helloworld"
return $doc1
}
</response>
</displayresults>
]]>
</xqueryaction>
</xquery>
</xmlaction>
<result>
<jmsTopicConfig>
<topicname>DEMO_OUPUT</topicname>
<connectionfactory>embedded</connectionfactory> <providerurl>tcp://localhost:61616</providerurl>
<initialcontextfactory>org.apache.activemq.jndi.ActiveMQInitialContextFactory </initialcontextfactory>
</jmsTopicConfig>
</result>
</Action>
</actions>
</Config>
The sections below describes the main area of the config.xml , now referred to as JXS code.
appid
This is where you enter the unique application identifier. This is an extremely important attribute which must be populated and unique.
requestdetails
Contains the description of the input interface. Currently only JMS is supported which is why the fields within these tags are JMS specific attributes. Other interfaces will be added in the future
actions
A configuration can contain one or more actions. Actions form the heart of JXS
xmlaction
A configuration can contain one or more actions. Actions form the heart of JXS
xquery
Within this action user can enter XQuery code.
Finally the sample client HTML/JavaScript is shown below,
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Autocomplete - XML data parsed once</title>
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css"
/>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<style> .ui-autocomplete-loading {
background:
white url('images/ui-anim_basic_16x16.gif')
right center no-repeat; }
</style>
<script>
$(document).ready(function(){
var urlPrefix = location.protocol + '//' + location.host;
var path = location.pathname.split('/');
if (path[path.length-1].indexOf('.')> -1) {
path.length = path.length - 1;
}
var apppath = path[path.length-2];
var appid_temp = path[path.length-1];
var appid = appid_temp.replace("_html","");
var urlval
= apppath ? urlPrefix + "/"
+ apppath + "/" + appid : urlPrefix + "/" + appid;
$.ajax({
type: "GET",
dataType: "xml",
url: urlval + "/getdata",
success: function(xml){
$(xml).find("displayresults").each(function(){
$("#output").append($(this).find("response").text()
+ "<br/>");
});
}
});
});
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>
The table below provides an explanation of some the highlights of the client HTML/JavaScript.
application path parser
This area of code determines the location of the getdata location. This should not be modified
getdata servlet
This is the heart of the synchronous client which calls the servlet interface API invoking the JXS service. Data can also be passed to the service which is then wrapped in <data></data> tags
displayresults
This is an example of how you may use the results of a call to the service. Notice that the resulting XQuery expression references the 'displayresult' tag as defined by the XQuery action
To try out the API follow these steps,
1. Register at webandserver.com here
2. Read Email with password
3. Download eclipse package from this link
4. unzip the package into your given location
5. Update config.xml , javascript and html files (Using the above example as a guide)
6. Execute the build script or run ' jar cvfm ../jxs.helloworld_1.0.2.jar META-INF/MANIFEST.MF *'
7. Login into Deployer cloud service
8. Deploy package and execute.
Note, this is Alpha-release software so expect there to be a few issues. I shall be creating an issue tracker site , but in the mean time the contacts page (Jxs Issues) can be used. The Alpha nature of the software is also the reason why only registered users can run and try-out with the demo.