Use eclipse3.2 + myeclipse5.5m1 + axis2_1.1.1 + tomcat5.5 to develop Web Services

Source: Internet
Author: User

The "Apache Axis web services development step by step" written on the Internet by -- hubieshavip -- is followed.

Thanks very much to Hu Bisi, who wrote a lot of details.
However, my environment is not the same as the one in his text, so I rewrite it as follows based on my own environment.

I. Environment preparation

1.1 Software Download preparation
Tomcat 5.5:
Http://tomcat.apache.org/download-55.cgi#5.5.20

Axis war package:
Http://ftp.wayne.edu/apache/ws/axis2/1_1_1/axis2.war

Axis Eclipse plug-in (Code Generation and packaging tools ):
Http://apache.justdn.org/ws/axis2/tools/1_1_1/axis2-eclipse-codegen-wizard.zip
Http://apache.justdn.org/ws/axis2/tools/1_1_1/axis2-eclipse-service-archiver-wizard.zip

Eclipse 3.2:
Http://www.eclipse.org/

Myeclipse5.5m1:
Http://www.myeclipseide.com/

1.2 Installation

A. first set up the development environment, download eclipse decompress to a directory, D:/eclipse-SDK-3.2-win32.
B. decompress the two plug-ins of the downloaded axis to the D:/axis-plugin-DIR/Eclipse/Plugins directory.
C. create d:/eclipse-SDK-3.2-win32/Eclipse/links under the eclipse directory, new file name: axis-eclipse-plugin.link

Content:
Path = D: // axis-plugin-Dir


D. Install myeclipse5.5m1, point the eclipse directory to D:/eclipse-SDK-3.2-win32, and delete the org. Eclipse. Update directory under D:/eclipse-SDK-3.2-win32/Eclipse/configuration. Start myeclipse and select "file-> New-> Other". The following two interfaces are displayed.
1. axis2 plugins

2. Web servieces plugins

E. Set up the deployment environment for Web Services.

Decompress the downloaded tomcat5.5 to a directory D:/tomcat5.5.

F. Copy the axis2.war package to the webapps directory under the tomcat installation directory.

G. start Tomcat (D:/tomcat5.5/bin/startup. BAT), open the browser and enter and access: http: // 127.0.0.1: 8080/axis2 to view the result. If the result is shown, axis2 is working properly.

Ii. Quick Start

2.1 create a webapps Project

Start myeclipse, create a new webapps (file-> New-> Project-> Web project), and set the project name to sayhello.

2.2 Create a wsdl File

A. Select the file-> New-other menu, go to myeclipse-> Web Services, and select WSDL. For example:

B. Click "Next". The following figure is displayed:

C. Select the "src" directory as the "enter or select the parent folder" value, and set the "file name" value to sayhello. WSDL.

D. Set the default value for all interface content in "Next". Finish!

E. The interface for displaying the WSDL designer is as follows:

F. Modify the marked red part of the image:
Modify newoperation in the figure to sayhello;
Modify parameters in input to sayhellorequest;
Modify parameters in output to sayhelloresponse;
After modification, see:

The content in the red box is changed, and the WSDL file is modified.

2.3 generate Java code from WSDL

A. Select "file-> New-> Other" from the menu, and select "axis2 code generator" under "axis2 wizards" in the dialog box. Click "Next"

B. Go to the next page, keep "generate Java source code from WSDL file" selected, and click "Next" to go to the next step.
C. Click "Browse" to select the sayhello. WSDL file stored in the src directory, and "Next" to go to the next step.
D. First generate the client code and test code. The settings are as follows:

E. After the next step, select the sayhello/src directory, for example:

Finish!

F. Repeat the steps from A to C and then generate the server code. The settings are as follows:

Followed by E.

G. Refresh the project,

This is because the jar package of axis2 is not put into the class path and the package of the source code is not org. example. www. sayhello.

H. Modify the package name org. example. www. sayhello and load all jar packages to the classpath of the project from the axis2 web application WEB-INF/lib directory in Tomcat.

I. Introduce the JUnit package in sayhellotest. java.

2.4 Write Business Code

Open the sayhelloskeleton. Java file using the following methods:

Public org. tonyzhangcn. ws. sayhello. sayhelloresponse sayhello (Org. tonyzhangcn. ws. sayhello. sayhellorequest param0)

{

// Todo fill this with the necessary business logic

Throw new java. Lang. unsupportedoperationexception ();

}

To:

Public org. tonyzhangcn. ws. sayhello. sayhelloresponse sayhello (Org. tonyzhangcn. ws. sayhello. sayhellorequest request)
{
Try {sayhelloresponse response = new sayhelloresponse (); response. setout ("hi," + request. getin () + ". How are you? "); Return response;} catch (unsupportedoperationexception e) {Throw E ;}
}

2.5 Packaging

A. Select "file-> New-> Other" from the menu, and select "axis2 services Archive" under "axis2 wizards" in the dialog box. Click "Next" to go to the next page.

B. Select the directory where the compiled class file is located (this project should be the WEB-INF/classes under webroot) and "Next" to go to the next step.

C. Select the directory where the WSDL file is located. This is the sayhello. WSDL file under the src directory. "Next" and then "Next ". Select the services. XM file.

D. Click "Next", which will be recorded in the last page. There are two options: output directory and everywhere file name. The output file name is sayhello. Click "finish.

2.6 deployer

A. Copy the packaged file sayhello. jar to the WEB-INF/Services Directory of the deployed axis2 application in Tomcat.

B. Restart tomcat.

C. Open the browser, enter http: // 127.0.0.1: 8080/axis2, and click the "services" link to see that sayhello has been deployed. Click the connection provided by sayhello to view the corresponding WSDL.

2.7 call Test
A. modify the content of testsayhello in the sayhellotest. Java file:

Public void testsayhello () throws java. Lang. Exception {string url = "http: // localhost: 8080/axis2/services/sayhello ";
Org. example. www. sayhello. sayhellostub stub = new org. example. www. sayhello. sayhellostub (URL );
Org. example. www. sayhello. sayhellostub. sayhello request = (Org. example. www. sayhello. sayhellostub. sayhello) gettestobject (Org. example. www. sayhello. sayhellostub. sayhello. class );
Request. setin ("teamlet ");
System. Out. println (stub. sayhello (request). getout ());
Assertnotnull (stub. sayhello (request ));
}

Select "Run-> Run as-> JUnit test" from the menu to complete the test!

<EOF>

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.