Apache Axis2 + Eclipse Development WebService

Source: Internet
Author: User

First, Introduction

Apache Axis2 is the next generation of Apache Axis. Although supported by the Axis 1.x handler model, AXIS2 is more flexible and extensible to the new architecture. Axis2 is written on a new architecture and is not using the usual code of Axis 1.x. The power to support the development of AXIS2 is to explore a more modular, flexible, and efficient architecture that can easily be plugged into implementations of other relevant WEB service standards and protocols such as Ws-security, ws-reliablemessaging, and so on. Apache Axis2 is a subsequent version of Axis and is a new generation of soap engines. Official website: http://axis.apache.org/axis2/java/core/index.html

Second, download

Apache Axis2 download page: http://axis.apache.org/axis2/java/core/download.cgi (current 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 the services code into a plug-in with a suffix. aar file):

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 for the service code and to parse the plug-in that generates the client code for 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

To install the plugin:

I use MYECLIPSE10, take my environment as an example: Unzip the two plug-ins and put them under the D:\sdk\MyEclipse\MyEclipse 10\dropins directory, start the MyEclipse

File-new-other can find:

Iii. deployment of the Axis2 War

Unzip the downloaded Axis2-1.6.2-war.zip to get a Axis2.war file, drop the file into the Tomcat\webapps directory, launch the Tomcat access Http://localhost:8080/axis2

See the following interface to deploy successfully.


Iv. Writing Service Code

[Java]View Plaincopy
  1. Package com.xcy;
  2. /**
  3. * @author Siuon
  4. * @version 1.0
  5. * @create 2012-7-19 8:23:49
  6. */
  7. Public class AXIS2WB {
  8. /** 
  9. * Provides a service that says hello
  10. * @return
  11. */
  12. Public string SayHello (string name) {
  13. return "Hello" +name;
  14. }
  15. /** 
  16. * Provides a service to do addition
  17. * @param a
  18. * @param b
  19. * @return
  20. */
  21. public int Add (int A,int b) {
  22. return a + B;
  23. }
  24. }

Five. Package the service code into ARR files:

Eclipse Menu-New-file-other-axis2 Service archiver

class file location: The bin directory for the project where the AXIS2WB class was just written

Select Skip WSDL

If your AXIS2WB has a reference jar package, select it here. I didn't write it, so next.

Since we did not write service.xml, tick let it be generated automatically, next

Enter the service name (optional), class full name, load, next

Set the AAR file name and store the directory (I'm on the desktop)--finish:

When you're done, you can see a Axis2wb.aar file on the desktop, and we'll open it with WinRAR:

Did you feel familiar? Much like a jar package, we click on the Meta-inf directory to go in, you can see the plugin to our generated a service.xml, open to see (is not understand what the plugin did):

  

Vi. Release

Drop the Axis2wb.aar file to the Web-inf\services\ directory of the previously deployed AXIS2 app and restart Tomcat

Re-visit http://localhost:8080/axis2/Click Service

See that the announcement was successful

Vii. Generating Client code

You can generate the client code with JDK6 's own Wsimport tool: Java 6 development WebService

You can also generate client code from AXIS2 's Eclipse plug-in:

Eclipse Menu-file-new-other-axis2 Code Generator

Generate Java source code from a WSDL file: Generates Java code for WebService client based on WSDL. (Here, we choose this)
Generate a WSDL from a Java source file: Generates a WSDL file based on a Java sources (this source file is a Java source file intended to be published as a Web service, such as the Axis2wb.java in this demo).

After the code is generated, you will find an error because of the lack of the associated jar package.

Unzip the Axis2 downloaded in the first step Binary.zip all the jar packages below lib in the extracted directory and add them to the class path:

8. Invoking the Web service

[Java]View Plaincopy
  1. Package test;
  2. Import java.rmi.RemoteException;
  3. Import Com.xcy.Add;
  4. Import Com.xcy.AddResponse;
  5. Import Com.xcy.Axis2WB;
  6. Import com.xcy.Axis2WBStub;
  7. Import Com.xcy.SayHello;
  8. Import Com.xcy.SayHelloResponse;
  9. /**
  10. * @author Siuon
  11. * @version 1.0
  12. * @create 2012-7-19 9:18:23
  13. */
  14. Public class Test {
  15. public static void Main (string[] args) throws remoteexception {
  16. //Create client Object
  17. AXIS2WB AXIS2WB = new Axis2wbstub ();
  18. //new A parameter sayhello that calls the SayHello method and sets the name
  19. SayHello SayHello = new SayHello ();
  20. Sayhello.setname ("Siuon");
  21. //Invoke Web service
  22. Sayhelloresponse sayhelloresponse = Axis2wb.sayhello (SayHello);
  23. //Get back results
  24. System.out.println (Sayhelloresponse.get_return ());
  25. Add add = new Add ();
  26. Add.seta (5);
  27. ADD.SETB (3);
  28. Addresponse Addresponse = Axis2wb.add (add);
  29. System.out.println (Addresponse.get_return ());
  30. }
  31. }


Results:

Apache Axis2 + Eclipse Development WebService

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.