Time for action - integrating with the Java server
One of the qooxdoo contribution projects is RPCJava (http://qooxdoo.org/contrib/project#rpcjava). In early versions of qooxdoo, the server components were also bundled as the backend in the qooxdoo SDK. As it evolved, the server components have been separated into contribution projects to allow those components to grow independently from the qooxdoo client framework.
Let's set up the server development environment. To do so, just follow these steps:
Copy the contents of C:\RpcJava\trunk\lib to C:\teamtwitter-server\lib
Copy the contents of C:\RpcJava\trunk\rpc to C:\teamtwitter-server\src
Copy the contents of C:\RpcJava\trunk\webapp to C:\teamtwitter-server\webapp
Copy C:\RpcJava\trunk\build.properties.sample to C:\teamtwitter-server\build.properties.sample
Copy C:\RpcJava\trunk\build.xml to C:\teamtwitter-server\build.xml
Copy C:\teamtwitter-server\build.properties.sample to C:\teamtwitter-server\build.properties
Download the following tools or software required for the server project and install them:
Download the Ant tool to run the build file. Either you can download Ant from http://ant.apache.org/ and install it or use the Ant plugin that comes with Eclipse.
In C:\teamtwitter-server, edit the build.xml file to add the necessary targets to build the Team Twitter client source and server source. The build. xml file reads the properties from build.properties and sets the value for the various directories such as build.dir, dist.dir, application.dist.dir, and web.dir.
The target clean wipes out the old classes and creates classes and dist directories.
The target compile compiles the team twitter server code with the libraries kept under the lib directory. All the output classes are saved under the classes directory.
The target client.generate-source generates the development version of the Team Twitter client application.
The target client.generate-build generates the deployment version of the Team Twitter client application.
The target copy.web depends on targets compile and client.generate-source.
After completing the dependency targets, it copies the Team Twitter client application deployment version into the dist directory, creates the WEB-INF directory in the dist directory, copies all the library files except servlet-api.jar under the WEB-INF/lib directory, copies the Team Twitter server classes under the WEB-INF/classes directory, and copies the web.xml under WEB-INF. The servlet-api.jar file will be available in the Tomcat common/lib directory.
The target dist depends on the copy.web target. After completing the dependency target, it creates the Web application ARchive (WAR) file which contains both the client application and server code for the Team Twitter application.
The target deploy deploys the dist directory in the Tomcat webapps directory.
Now, let's build the Team Twitter application. Run the following build command:
C:\teamtwitter-server>ant dist
The preceding build command will build everything and generate the web application directory as well as the WAR file. Now, we have the server development environment.
Let's make changes in the Team Twitter client application to integrate with the server code. RPCJava comes with a qooxdoo.test remote service, which implements all the test methods of the qooxdoo RPC server. We can call the echo method from the test remote service to verify the client server communication.
Open the Team Twitter client application JavaScript file (C:\teamtwitter\source\class\teamtwitter\Application.js).
Edit the listener implementation for the button and add the following code to integrate with the RPCJava server.
// Add an event listener
button1.addListener("execute", function(e) {
var rpc = new qx.io.remote.Rpc();
rpc.setCrossDomain( false );
rpc.setTimeout(1000);
var host = window.location.host;
var proto = window.location.protocol;
var webURL = proto + "http://" + host + "/teamtwitter/.qxrpc";
rpc.setUrl(webURL);
rpc.setServiceName("qooxdoo.test");
rpc.callAsync(function(result, ex, id){
if (ex == null) {
alert(result);
}
else
{
alert("Async(" + id + ") exception: " + ex);
}
}, "echo", "Hello to qooxdoo World!");
});
Now, run the build again to rebuild the application:
C:\teamtwitter-server>ant dist
The dist target builds the client application code, compiles the server code, and builds the web application.
Now, run the following command to deploy the Team Twitter web application in Tomcat.
Let's deploy the application:
C:\teamtwitter-server>ant deploy
Now, start Tomcat by running the following command (<TOMCAT_HOME> is where you installed the Tomcat server):
<TOMCAT_HOME>\bin\startup.bat
Let's check the application from the browser. Once the Tomcat server is up and running, try to access the primitive Team Twitter application by accessing the following URL:
http://localhost:8080/teamtwitter/
Click on the First Button button; you'll get a response from the Team Twitter server. The server method just echoes whatever the client passed with the prefix Client said.
In the JSON-RPC call, the following data is sent as the request and received in the response.
The data sent in the request to the server is as follows:
{"service":"qooxdoo.test","method":"echo","id":1,"params":["Hello to qooxdoo World!"]}
The data received in response from the server is as follows:
{"id":"1","result":"Client said: Hello to qooxdoo World!"}
Working with Eclipse IDE
If you want to use any IDE such as Eclipse IDE, carry out the following steps (you can download the Eclipse IDE from http://www.eclipse.org/):
Create a Java project and set the project name as teamtwitter-server. Set the location as C:\teamtwitter-server, which was created earlier in step 1 in the Time for action integrating with the Java server section. Click on the Finish button. It will automatically set everything for the project.
Now, set up the Ant view. If you have not enabled the Ant view, enable it by going to Window | Show View | Ant. In the Ant view of Eclipse, add the build.xml file, which is present in C:\teamtwitter-server. Then, you can run the Ant targets from the Eclipse IDE. The Ant tasks in the server application also build the client application based on the build.properties configuration, generates the final web application, and deploys it in Tomcat:
What just happened?
We have set up the RPCJava server and the server development environment. We have integrated the client application with the server, built the code, deployed the web application, and tested it.
Pop quiz
qooxdoo needs the following tools
a. ActivePython and Cygwin
b. ActivePython or Cygwin
Components in the qooxdoo SDK are
a. The qooxdoo applications for the end users
b. The qooxdoo internal applications used by the framework
Applications in the qooxdoo SDK are
a. The qooxdoo applications for the end users
b. The qooxdoo internal applications used by the framework
qooxdoo is a
a. Client-side framework
b. Server-side framework
c. Both
qooxdoo prefers to send the data for communication between the client and the server in the format of
a. XML
b. Text
c. JSON
The qooxdoo client application can communicate with the server implemented in
a. Java only
b. Java, Python, and Perl
c. Any language abiding to the qooxdoo JSON-RPC server guidelines