Axiom XMLHttpRequest - Enterprise XML Web Framework
by Thomas Merten

| "Solo ya pie... Admirable peregrino, todos siguen tu camino" Manuel Machado |
Axiom XMLHttpRequest Project on java.net
Axiom XMLHttpRequest is an Enterprise XML Web Framework enables XML Transformations in Java Server using Streaming API for XML (StAX) & Axis2 Databinding Framework(ADB). The Framework extends the client-side JavaScript DOM XMLHttpRequest with XMLHttpRequestSchema and high performance StAX XML Processing on server-side. Parsing XMLHttpRequest to org.apache.axis2.databinding.ADBBean and serialize org.apache.axis2.databinding.ADBBean to HttpServletResponse in ServletContainer while JavaScript Request processing is implemented. Based on supported SchemaCompiler Tool we generate ADBBean from XMLHttpRequestSchema. A Demo Web Application is included in the Framework - explains how to progress JavaScript-XMLHttpRequest in Java Server Page.
The Axiom XMLHttpRequest Enterprise XML Web Framework can be easily deployed over axiom-xmlhttprequest.jar registration in Web-Inf/lib directory of the Web Application. The Axiom XMLHttpRequest runs on all Java Web Containers without any modification and requires additional libraries from Apache ADB Project axiom_libs.
More Information about Axis2 Databinding Framework is on Apache Axis2 Website http://axis.apache.org/axis2/java/core/docs/adb/adb-howto.html .

Architecture Axiom XMLHttpRequest - Enterprise XML Web Framework
Axiom XMLHttpRequest - Demo Web Application
Demo Web Application is included in the Framework - show progress a JavaScript-XMLHttpRequest in Java Server Page. Assembled Demo Web Application for use in any Java Servlet WebContainer is located in Source Code Repository of Axiom XMLHttpRequest. Demo Web Application
Start URL for Demo: http://host:Port/WebContent/operation/addition.jsp

Figure 2. Axiom XMLHttpRequest - Demo Web Application
Architecture & Design - Demo Web Application
We divide in HTTP-GET and HTTP-POST Request:
- HTTP-GET Request is used for Site Loading and Navigation.
- HTTP-POST Request is used for Form Data Processing.
Here Axiom XMLHttpRequest Framework is active. Loosely coupled high interactivity client-side JavaScript Web Controls interact with high performance server-side StAX Objects based on XMLHttpRequestSchema communication.
XMLHttpRequest: XMLMessage & XMLSchema
<!-- XMLHTTPRequest-Communication-XMLMessage --> <!-- based on client-side JavaScript:DOMRequest --> <Addition> <Summand>27</Summand> <Summand>6</Summand> <Summe>33</Summe> </Addition>Code Snippet 1. XMLHTTPRequest-Communication-XMLMessage XMLHTTPRequest.xml
<!-- XMLHTTPRequest-Communication-XMLSchema -->
<!-- based on client-side JavaScript:DOMRequest -->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Addition">
<xs:complexType>
<xs:sequence>
<xs:element name="Summand" maxOccurs="unbounded"
minOccurs="2">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:element>
<xs:element type="xs:string" name="Summe" maxOccurs="1" minOccurs="0"/>
<xs:element type="xs:string" name="Exception" maxOccurs="1" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Code Snippet 2. XMLHTTPRequest-Communication-XMLSchema XMLHTTPRequestSchema.xsd
JavaScript & Java ServerPages
<!-- Java Server Page JavaBean Definition --> <jsp:useBean id="bean" scope="request" class="operation.Addition" /> <% bean.processRequest(request,response); //!!! getOutputStream() has already been called for this response if(request.getMethod() == "POST") return; %> <!-- Java Server Page HTML Formular --> <!-- Request Definition Elements --> <form name="addition" action="javascript:void"> Solve this math question and enter the solution with digits: <jsp:getProperty name="bean" property="summand_1"/>+<jsp:getProperty name="bean" property="summand_2"/> = <input type="hidden" NAME="summand_1" VALUE='<jsp:getProperty name="bean" property="summand_1"/>' /> <input type="hidden" NAME="summand_2" VALUE='<jsp:getProperty name="bean" property="summand_2"/>' /> <input size="3" NAME="summe" TYPE="text" /> <input TYPE="button" VALUE="Validate Math Question[POST Request]" onclick="lookupAddition(document.addition)" /> </form>Code Snippets 3.Java Server Page HTML Formular addition.jsp
<!--
JavaScript function:
1.)build DOM XML
2.)Serialize DOM -> XMLString
3.)Send asynchron POST XMLHTTPRequest to JavaServer Page
4.)Deserialize XMLHTTPResponseString -> DOM
-->
function lookupAddition(element) {
try {
if (!element.working) {
var http = element.http;
var doc = getDomDocument("Addition");
var item = doc.createElement("Summand");
var text = doc.createTextNode(element.summand_1.value);
item.appendChild(text);
doc.childNodes.item(0).appendChild(item);
var item2 = doc.createElement("Summand");
var text2 = doc.createTextNode(element.summand_2.value);
item2.appendChild(text2);
doc.childNodes.item(0).appendChild(item2);
var item3 = doc.createElement("Summe");
var text3 = doc.createTextNode(element.summe.value);
item3.appendChild(text3);
doc.childNodes.item(0).appendChild(item3);
var xmlString = serializeXML(doc);
http.open("POST", encodeURI("addition.jsp"), true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", xmlString.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {// Call a functionality when the state changes.
if (http.readyState == 4 && http.status == 200) {
try {
doc = XML2DOM(http.responseText);
if (doc.getElementsByTagName("Exception").length != 0) {
alert("ERROR: "
+ doc.getElementsByTagName("Exception")[0].textContent);
element.working = false;
} else {
var summe = doc.getElementsByTagName("Summe")[0];
var summeServer = summe.textContent;
if (element.summe.value != summe.textContent) {
alert("ERROR: " + element.summand_1.value
+ " + " + element.summand_2.value
+ " is not " + element.summe.value
+ " !");
} else {
alert("OK: " + element.summand_1.value + " + "
+ element.summand_2.value + " is "
+ element.summe.value + " !");
window.location.href = 'addition.jsp';
}
}
element.working = false;
return true;
} catch (e) {
alert(e.message);
element.working = false;
}
}
}
http.send(xmlString);
element.working = true;
return false;
} else {
return false;
}
} catch (e) {
alert(e.message);
return false;
}
}
Code Snippets 4. XMLHTTPRequest-JavaScript-JavaServer Page Communication xmlhttp.js
SchemaCompiler & Axiom Databinding Framework(ADB)
SchemaCompiler - How to
Axiom XMLHttpRequest Enterprise XML Web Framework enables ADBBean generation from XMLHttpRequestSchema.
ADBBeans are used by StAX for Axiom Databinding Framework(ADB). So client-side JavaScript DOM XMLHttpRequest is progressed
with high performance StAX XML Processing on Java Server server-side.
XML-Schema Compiler Source: axiom.xml.httprequest.XSD2JavaADBBean.java
Based on supported SchemaCompiler command-lineTool we generate these ADBBeans with following console command:
java
-Dorg.apache.adb.properties=/axiom/xml/httprequest/schema-compile.properties
-cp /axiom-xmlhttprequest.jar;axiom_libs
axiom.xml.httprequest.XSD2JavaADBBean
XSD_FILE
OUTPUT_FOLDER
CLASS_PACKAGE
Import required libraries and Objects:
- axiom-xmlhttprequest.jar - Axiom XMLHttpRequest - Enterprise XML Web Framework
- axiom_libs - additional axiom libraries from Apache Axis2 Project
3 Input Arguments:
- XSD_FILE- Path to your XMLHttpRequestSchema File[derived from your XMLHttpRequest Message Pattern: Your Task]
- OUTPUT_FOLDER- OUTPUT_FOLDER [Your source directory] -> ADBBean Package with your schema-compiled objects
- CLASS_PACKAGE- Your ADBBean Package name
Example for Input Arguments:
- "C:/XML/axiom-xmlhttprequest/DemoWebApplication/XMLHTTPRequest-XMLSchema/XMLHTTPRequestSchema.xsd"
- "C:/XML/axiom-xmlhttprequest/DemoWebApplication/src"
- "schema.adbbean"
java
-Dorg.apache.adb.properties=/axiom/xml/httprequest/schema-compile.properties
-cp ./axiom-api-1.2.12.jar;./axiom-dom-1.2.12.jar;./axiom-impl-1.2.12.jar;./axiom-xmlhttprequest.jar;./axis2-adb-1.5.6.jar;./axis2-adb-codegen-1.5.6.jar;./axis2-codegen-1.5.6.jar;./axis2-kernel-1.5.6.jar;./commons-logging-1.1.1.jar;./xmlbeans-2.3.0.jar;./XmlSchema-1.4.3.jar
axiom.xml.httprequest.XSD2JavaADBBean
"C:/XML/axiom-xmlhttprequest/DemoWebApplication/XMLHTTPRequest-XMLSchema/XMLHTTPRequestSchema.xsd"
"C:/XML/axiom-xmlhttprequest/DemoWebApplication/src"
"schema.adbbean"

Figure 3. SchemaCompiler XSD2JavaADBBean generated ADDBeans based on XMLHttpRequestSchema
Axiom Databinding Framework(ADB) using in Java Server Pages Beans
The Framework extends the client-side JavaScript DOM XMLHttpRequest with high performance StAX XML Processing on server-side. Parsing XMLHttpRequest to org.apache.axis2.databinding.ADBBean and serialize org.apache.axis2.databinding.ADBBean to HttpServletResponse in JavaServer Page Bean while JavaScript Request processing is implemented.
axiom.xml.httprequest.ADBBean4XMLHttpRequest.java is the most central Object.
Extend your Java Server Page Beans with this Class and use the following Methods for HTTP Post Processing:
- org.apache.axis2.databinding.ADBBean xmlHttpRequest2ADBBean(HttpServletRequest request,String Factory) -> Parse XMLHttpRequest to your ADBBean using ADBBean.Factory
- void ADBBean2xmlHttpResponse(org.apache.axis2.databinding.ADBBean bean,HttpServletResponse response) -> Serialize your ADBBean to HttpServletResponse
Import required libraries and Objects:
- axiom-xmlhttprequest.jar - Axiom XMLHttpRequest - Enterprise XML Web Framework Package[axiom.xml.httprequest]
- schema.adbbean - your ADBBean Package with your schema-compiled Objects
- axiom_libs - additional axiom libraries from Apache Axis2 Project
Using Axiom XMLHttpRequest your JavaServer Bean should implement Axiom Databinding Framework(ADB) like this example:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import axiom.xml.httprequest.ADBBean4XMLHttpRequest;
import schema.adbbean.Summand_type1;
public class Addition extends ADBBean4XMLHttpRequest {
public void processRequest(HttpServletRequest request, HttpServletResponse response) {
// Progress Question
if (request.getMethod() == "POST") {
try {
schema.adbbean.Addition addition =
(schema.adbbean.Addition) xmlHttpRequest2ADBBean(request,schema.adbbean.Addition.Factory.class.getName());
try {
Summand_type1[] summand = addition.getSummand();
int summe = Integer.valueOf(addition.getSumme());
summand_1 = Integer.valueOf(summand[0].getSummand_type0());
summand_2 = Integer.valueOf(summand[1].getSummand_type0());
if (summe != summand_1 + summand_2) {
addition.setSumme(String.valueOf(summand_1 + summand_2));
}
} catch (NumberFormatException e) {
if (addition != null) {
addition.setException(e.getMessage());
}
}
ADBBean2xmlHttpResponse(addition, response);
} catch (Exception e) {
e.printStackTrace();
}
}
Code Snippets 5. Axiom XMLHTTPRequest-JavaServer Page Implementation Addition.java
Pluggable StAX implementations & Jar Service Provider Interfaces
The Axiom XMLHTTPRequest Framework allows you to decide how to configure StAX. However, if you have multiple StAX implementations in your classpath (->jar service provider technologie), you may have to specifically set/override system properties in web.xml to point to the implementation you want. axiom.xml.httprequest.ADBBean4XMLHttpRequest Listener will initialize Axiom XMLHTTPRequest Framework with your local StAX-Factory Settings independent of your global StAX configuration.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd"
version="2.3">
...
<listener>
<listener-class>
axiom.xml.httprequest.ADBBean4XMLHttpRequest
</listener-class>
</listener>
<!--Setup StAX implementations from your classpath libraries , in this case
we use JDK 1.6 Standard Implementation -->
<context-param>
<param-name>javax.xml.stream.XMLInputFactory</param-name>
<param-value>com.sun.xml.internal.stream.XMLInputFactoryImpl</param-value>
</context-param>
</web-app>
Code Snippets 6. Axiom XMLHTTPRequest-Web Application Context StAX-Parameter web.xml
Prerequisites
Axiom XMLHttpRequest requires:
- Java Servlet Engine(Tomcat,...) with Servlet Specification 2.3 or later
- Java 1.6 or Java 1.5 with StAX Implementation
- Prefered pluggable StAX Implementation
- Axiom libraries from Apache Axis2 Project
About the Author
Figure 4. The Author
My professional activities currently concentrate on J2EE Profiling and Monitoring. I am also interested in EAI/EIM Software Systems Integration. Previously, I worked in the ICT industry as a Siebel Core Consultant. Presently I am working as a freelance consultant and software developer in Europe. I contribute to the open source community(java.net) with the Java EE LoadBalancer & Axiom XMLHttpRequest Projects.
Lizenz
Limited warranty: Axiom XMLHttpRequest Software and Documentation are "as is" without any warranty as to their performance, merchantability or fitness for any particular purpose. The licensee assumes the entire risk as to the quality and performance of the software. In no event shall Axiom XMLHttpRequest or anyone else who has been involved in the creation, development, production, or delivery of this software be liable for any direct, incidental or consequential damages, such as, but not limited to, loss of anticipated profits, benefits, use, or data resulting from the use of this software, or arising out of any breach of warranty. This includes, but is not limited to, interruption of service, loss of classroom time or loss of consulting profits from the use of these programs.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Resources & References
Axiom XMLHttpRequest Project © 2012 Thomas Merten.









Figure 5. The Author
Java EE LoadBalancer Project © 2011 Thomas Merten.