Using Axis2 and JIBX to convert Java classes to Web services, part 1th

Source: Internet
Author: User
Tags data structures web services wsdl

Using Axis2 and JIBX to convert Java classes to Web services, part 1th: Defining Web Services through Java classes using XML

This article supporting source code

Brief introduction

Web services are becoming increasingly important in daily development, and Axis2 has become a popular open source platform for developing Web services. Axis2, written in the Java language, leverages the freedom of JiBX, a framework that binds XML and Java together. Suppose you have a Java project with a large number of Java classes and data structures, and you don't want to disrupt or change them. JiBX will help you achieve this by binding the XML data used in Axis2 to Java classes. The advantage of this is that the code is easy to maintain because the WEB service uses only the developed, reliable, real Java classes.

This article describes the Java classes that will be used in this series and explains how to generate Web Service description languages (Web Services Description language,wsdl) and JiBX definitions that accurately describe these Java classes. Part 2nd of this series will use WSDL and the JiBX XML document to create a Java implementation of a Web service that uses this Java class as data binding.

System Requirements

To learn this two-part series, you need the following software:

The Axis2,binary and WAR Edition is available for download from the Axis2 home page.

JIBX 1.1, which can be downloaded from the Jibx SourceForge page.

Geronimo 1.1.1, can be downloaded from the Geronimo home page.

After downloading all of the above software, unzip Geronimo and type: Java-jar <geronimo-home>/bin/server.jar.

Then, to deploy the Axis2.war file, copy the Axis2 file to the <geronimo-home>/deploy directory.

Unzip the AXIS2 binaries and set the AXIS2_HOME environment variable to the directory extracted by the Axis2 binary file (set to c:\apps\axis2-1.1 in this example). Then unzip JiBX and copy all JAR files for the <jibx-home>/lib directory (except Stax-api.jar files, because Axis2 already contains stax-api.jar files) to <axis2-home> The/lib directory.

This is where the environment is set up.

Java class

Java classes are provided here to form a simple Web Services Java project. There are no major barriers to using Java classes, and you can use the Java classes that you create yourself. The items used in this article contain three classes: The Onewayrequest class, the Twowayrequest class, and the Twowayresponse class. Looking at each class in order, we start with the Onewayrequest class (see Listing 1).

Listing 1. Onewayrequest Java Class

package com.ibm.devWorks.xml.simpleService;
public class OneWayRequest {
protected String requestData;
public String getRequestData() {
return this.requestData;
}
public void setRequestData(String requestData) {
this.requestData = requestData;
}
}

The above code contains only one field, RequestData, which contains the requested data. The class has two methods: one for setting field values and the other for retrieving field values.

Then take a look at the Twowayrequest class in Listing 2.

Listing 2. Twowayrequest Java Class

package com.ibm.devWorks.xml.simpleService;
public class TwoWayRequest {
protected String echoString;
protected boolean booolean;
public boolean getBooolean() {
return this.booolean;
}
public void setBooolean(boolean booolean) {
this.booolean = booolean;
}
public String getEchoString() {
return this.echoString;
}
public void setEchoString(String echoString) {
this.echoString = echoString;
}
}

This class is a bit longer, and it defines two fields: one is echostring and the other is Booolean. As with the first class, the class defines a getter and a setter method for each field.

Listing 3 shows the last class, the Twowayresponse class.

Listing 3. Twowayresponse Java Class

package com.ibm.devWorks.xml.simpleService;
public class TwoWayResponse {
protected String echoString;
protected boolean invertedBoolean;
public boolean getInvertedBoolean() {
return this.invertedBoolean;
}
public void setInvertedBoolean(boolean invertedBoolean) {
this.invertedBoolean = invertedBoolean;
}
public String getEchoString() {
return this.echoString;
}
public void setEchoString(String echoString) {
this.echoString = echoString;
}
}

This class is quite similar to the previous Twowayrequest class, but it is not necessary. A response class may contain some data items from a database record. In this way, the Java class is complete! Next, we'll describe the WSDL used to expose these classes as WEB services.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.