Apache axis2 + eclipse WebService Development

Source: Internet
Author: User

I. Introduction

Apache axis2 is the next generation of Apache axis. Although supported by the Axis 1.x processor model, axis2 is more flexible and scalable to the new architecture. Axis2 is newly written based on the new architecture and does not use common code of axis 1.x. The motivation for supporting the development of axis2 is to explore a more modular, more flexible, and more effective architecture, this architecture can be easily inserted into other related web service standards and protocols (such as WS-Security, WS-reliablemessaging
. Apache axis2 is a later version of axis and a new generation of SOAP engine. Http://axis.apache.org/axis2/java/core/index.html

Ii. Download

Apache axis2 download page: http://axis.apache.org/axis2/java/core/download.cgi (Latest Version 1.6.2)

Apache axis2 binary distribution (1.6.2): http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip

War distribution: http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-war.zip

Eclipse Plugin:

Service Archive wizard-Eclipse plug-in (used to package service code into a plug-in with the extension name. AAR ):

Http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.6.2/axis2-eclipse-service-plugin-1.6.2.zip

Code Generator wizard-Eclipse plug-in (used to generate a WSDL file from the service code and parse the plug-in that generates the client code from the WSDL file ):

Http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.6.2/axis2-eclipse-codegen-plugin-1.6.2.zip

Install plug-ins:

I use myeclipse10. Take my environment as an example. decompress the two plug-ins and put them under the D: \ SDK \ myeclipse 10 \ dropins directory to start myeclipse.

File-New-Other can be found:

3. Deploy axis2 war

Decompress the axis2-1.6.2-war.zip file to get an axis2.war file. Then, drop the file to the Tomcat \ webapps directory and start Tomcat.
Access http: // localhost: 8080/axis2

The following page is displayed. The deployment is successful.


4. Write Service Code

Package COM. xcy;/*** @ author Xiao chunyong (siuon) * @ version 1.0 * @ create 2012-7-19 8:23:49 */public class axis2wb {/*** provides a hello-speaking Service * @ return */Public String sayhello (string name) {return "hello" + name;}/*** provides an addition Service * @ Param A * @ Param B * @ return */Public int add (int, int B) {return a + B ;}}

5. Package the service code into an arr file:

Eclipse menu-New-file-other-axis2 service archiver

Class File Location: bin directory of the project where the newly written axis2wb class is located

Select skip WSDL

If your axis2wb has a reference jar package, select here. I did not write, so next

Because we have not compiled service. XML, check to make it automatically generated, next

Enter the service name (random), full name of the class, load, and next

Set the AAR file name and storage directory (I put it on the desktop) -- finish:

After that, we can see that an axis2wb. AAR file is added to the desktop. We use WinRAR to open it:

Do you feel familiar? Like a jar package, we click the META-INF Directory into, you can see the plug-in for us to generate a service. XML, open to see (Do you understand what the plug-in has done ):

  

6. Release

Drop the axis2wb. AAR file to the WEB-INF \ Services \ directory of the previously deployed axis2 application and restart tomcat.

Access http: // localhost: 8080/axis2/and click Service.

The release is successful.

7. Generate client code

You can use the wsimport tool that comes with JDK 6 to generate the client code: Java 6 to develop WebService

You can also use the Eclipse plug-in of axis2 to generate the client code:

Eclipse menu-File-New-Other-Axis2 Code Generator

Generate Java source code from a WSDL file: generate the Java code of the WebService client according to the WSDL. (Here, we choose this)
Generate a WSDL from a Java source file: generate a wsdl file based on a Java source file (this source file is a Java source file intended to be published as a web service, such as axis2wb. Java in this demo ).

After the code is generated, you will find an error because the relevant jar package is missing.

Decompress the downloaded axis2 binary.zip file in step 1. Copy all the jar packages under Lib in the decompressed directory and add them to the class path:

8. Call Web Services

Package test; import Java. RMI. remoteException; import COM. xcy. add; import COM. xcy. addresponse; import COM. xcy. axis2wb; import COM. xcy. axis2wbstub; import COM. xcy. sayhello; import COM. xcy. sayhelloresponse;/*** @ author Xiao chunyong (siuon) * @ version 1.0 * @ create 2012-7-19 9:18:23 */public class test {public static void main (string [] ARGs) throws RemoteException {// create the client object axis2wb axis2wb = new axis2wbstub (); // a new parameter sayhello required to call the sayhello method, and set namesayhello sayhello = new sayhello (); sayhello. setname ("siuon"); // call the Web Service sayhelloresponse = axis2wb. sayhello (sayhello); // get the returned result system. out. println (sayhelloresponse. get_return (); Add add = new add (); add. seta (5); add. SETB (3); addresponse addrese = axis2wb. add (ADD); system. out. println (addresponse. get_return ());}}

Result:

Publish the WebService developed by axis2 to your own application (Supplement)

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.