Skip to main content
Last updated February 07, 2014 14:10, by java.sun
Feedicon  

Axiom XMLHttpRequest - Enterprise XML Web Framework based on AJAX & Axis2

by Thomas Merten

Figure 0. Architecture Axiom XMLHttpRequest - Enterprise XML Web Framework

"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.

Enterprise XML Web Framework->Downloads

More Information about Axis2 Databinding Framework is on Apache Axis2 Website http://axis.apache.org/axis2/java/core/docs/adb/adb-howto.html .

Figure 1. Axiom XMLHTTPRequest Sequenz(UML)

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

Browser=JavaScript Web Controls <=>XMLHttpRequest <=>XMLHttpRequestSchema<=>StAX-ADBBeans=Java Server

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

jQuery(JavaScript) & Java ServerPages

<!-- Java Server Page JavaBean Definition -->
<jsp:useBean id="bean" scope="request" class="operation.Addition" />

<HEAD>
<script src="../js/jquery-1.10.1.js"></script>
<script src="../js/xmlhttp.js"></script>
</HEAD>

<%
	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" >
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]"  />
</form>
Code Snippets 3.Java Server Page HTML Formular addition.jsp

<!-- 
jQuery JavaScript function: 
Send asynchron POST XMLHTTPRequest to JavaServer Page
-->
$(document).ready(function() {
	$("#addition :button").click(function(event) {
		try{
		event.preventDefault();
		var form = $( "#addition" );
		var summand_1 = form.find( 'input[name="summand_1"]' ).val();
		var summand_2 = form.find( 'input[name="summand_2"]' ).val();
		var summe     = form.find( 'input[name="summe"]' ).val();

		var xmlDocument = ['<Addition>',
					        '<Summand>',
					        summand_1,
					        '</Summand>',
					        '<Summand>',
					        summand_2,
					        '</Summand>',
					        '<Summe>',
					        summe,
					        '</Summe>',
					        '</Addition>'].join('');

		$.ajax({
			url : "addition.jsp",
			type : "POST",
			dataType : "xml",
			processData : false,
			data : xmlDocument
		})
		.done(function(data) {
					if ($(data).find('Exception').length != 0) {
						alert($(
								data)
								.find(
										'Exception')
								.text());
					} else {
						if ($(data).find('Summe').text() != summe) {
							alert("ERROR: "
									+ summand_1
									+ " + "
									+ summand_2
									+ " is not "
									+ summe
									+ " !");
						} else {
							alert("OK: "
									+ summand_1
									+ " + "
									+ summand_2
									+ " is "
									+ summe
									+ " !");
							window.location.href = 'addition.jsp';
						}
					}
				})
		.fail(function(xhr,	textStatus,	msg) {
					alert(textStatus
							+ " : "
							+ msg
							+ " !");
		});
	} catch (e) {
		alert(e.message);
	}
	});
});
Code Snippets 4. jQuery(Ajax) - 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:

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:

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.

License

Resources & References


  • Tomcat Copyright ©  1999-2011, The Apache Software Foundation
  • java.net Copyright ©  2011, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
  • Axiom XMLHttpRequest Project Copyright ©  2012 Thomas Merten. All rights reserved.(http://www.enterprise-systems-integration.de)
  • Axis2 Databinding Framework Copyright ©  2004-2012 The Apache Software Foundation. All Rights Reserved.
  • Ignatian Exercises, EB Nr.22 ©  Ignacio de Loyola

Bottom Axiom XMLHttpRequest Project ©  2012 Thomas Merten.

 
 
Close
loading
Please Confirm
Close