Use axis to publish a WebService operation guide under Tomcat

Source: Internet
Author: User

Recently, Webservice interfaces are always required to be provided to other project teams. Since the initial requirement is not very clear, the interface definition often needs to be changed, from wsdl to Java, repeat the deploy service on tomcat Based on the wsdd file. some problems often occur in this process, especially when axis is not used for a long time and then suddenly used for this purpose, there are always more or less problems, the detailed operation steps of the above process have been sorted out for reference.

To use Axis to publish a Webservice under Tomcat, follow these steps:

(1) Use JavaBean to write the definition of the service to be released.

(2) Use the Java2WSDL command to generate a WSDL File Based on the JavaBean

(3) use the Wsdl2Java command to generate the Server Source Code and the deploy. wsdd File Based on the WSDL file.

(4) Publish the Webservice Service under tomcat according to the deploy. wsdd File

(1) Use Javabean to write the definition of the service to be released.

Take user registration as an example. You must provide the following user registration service. The input parameter is com. huawei. mtv. commons. services. schemas. userRegisterEvt. The output parameter is com. huawei. mtv. commons. services. schemas. userRegisterResp.

UserManage interface file definition:

Package COM. huawei. MTV. commons. services; <br/> Import COM. huawei. MTV. commons. services. schemas. userregisterevt; <br/> Import COM. huawei. MTV. commons. services. schemas. userregisterresp; <br/> public class usermanage <br/>{< br/> Public userregisterresp register (userregisterevt EVT) <br/>{< br/> return NULL; <br/>}< br/>}

Enter the UserRegisterEvt source code:

Package COM. huawei. MTV. commons. services. schemas; <br/> public class userregisterevt implements Java. io. serializable {<br/> private int accesscode; <br/> private Java. lang. string level; <br/> private Java. lang. string userid; <br/> Public userregisterevt () {<br/>}</P> <p> Public int getaccesscode () {<br/> return accesscode; <br/>}</P> <p> Public void setaccesscode (INT accesscode) {<br/> This. accesscode = accesscode; <br/>}</P> <p> Public Java. lang. string getlevel () {<br/> return level; <br/>}</P> <p> Public void setlevel (Java. lang. string level) {<br/> This. level = level; <br/>}</P> <p> Public Java. lang. string getuserid () {<br/> return userid; <br/>}</P> <p> Public void setuserid (Java. lang. string userid) {<br/> This. userid = userid; <br/>}< br/>}

Source code of output parameter UserRegisterResp:

Package COM. huawei. MTV. commons. services. schemas; <br/> public class userregisterresp implements Java. io. serializable {<br/> private Java. lang. string description; <br/> private Java. lang. string returncode; <br/> Public Java. lang. string getdescription () {<br/> return description; <br/>}</P> <p> Public void setdescription (Java. lang. string description) {<br/> This. description = description; <br/>}</P> <p> Public Java. lang. string getreturncode () {<br/> return returncode; <br/>}</P> <p> Public void setreturncode (Java. lang. string returncode) {<br/> This. returncode = returncode; <br/>}< br/>}

Export the above definition file as a mtv-common.jar package in Eclipse environment. So far the first step is complete.

(2) Use the java2wsdl command to generate a WSDL File Based on the JavaBean

Here I am using the axis-1_4 version, specifically using the jar package (only using the jar package self-contained in the lib directory in the axis-1_4) and the command refer to the following code.

Java2wsdl. bat:

Set axis_home = D:/software/axis2/axis-1_4/lib <br/> set axis_path = % axis_home %/axis-ant.jar <br/> set axis_path = % axis_path %; % axis_home %/axis. jar <br/> set axis_path = % axis_path %; % axis_home %/commons-discovery-0.2.jar <br/> set axis_path = % axis_path %; % axis_home %/ commons-logging-1.0.4.jar <br/> set axis_path = % axis_path %; % axis_home %/jaxrpc. jar; <br/> set axis_path = % axis_path %; % axis_home %/log4j-1.2.8.jar <br/> set axis_path = % axis_path %; % axis_home %/ mtv-common.jar <br/> set axis_path = % axis_path %; % axis_home %/SAAJ. jar <br/> set axis_path = % axis_path %; % axis_home %/wsdl4j-1.5.1.jar <br/> set classpath = % classpaht %; % axis_path % <br/> JAVA Org. apache. axis. WSDL. java2wsdl-n "urn: usermanage"-P "com. huawei. MTV. commons. services "" urn: usermanage "-o" usermanage. WSDL "-l" http: // localhost: 8080/axis/services/usermanage "com. huawei. MTV. commons. services. usermanage </P> <p>

After the above batch file is executed, the UserManage. wsdl file is generated.

The meanings of the parameters of the Java2WSDL command are as follows:

-O: Specifies the name of the output WSDL file. </P> <p>-L: Specifies the service location. </P> <p>-N: target namespace of the WSDL file. </P> <p>-P: Specifies the packing from package to namespace. Multiple mappings can be found here.

Note the following:

-O-l-N-P is recommended to have no space between these options and the values corresponding to the following options, especially the-p parameter. If there is space, an error will be reported when the WSDL file is generated.

 

 (3) use the wsdl2java command to generate the Server Source Code and the deploy. WSDD File Based on the WSDL file.

 Use the following wsdl2java. bat batch file to generate the WebService server and client source code.

Set axis_home = D:/software/axis2/axis-1_4/lib <br/> set axis_path = % axis_home %/axis-ant.jar <br/> set axis_path = % axis_path %; % axis_home %/axis. jar <br/> set axis_path = % axis_path %; % axis_home %/commons-discovery-0.2.jar <br/> set axis_path = % axis_path %; % axis_home %/ commons-logging-1.0.4.jar <br/> set axis_path = % axis_path %; % axis_home %/jaxrpc. jar; <br/> set axis_path = % axis_path %; % axis_home %/log4j-1.2.8.jar <br/> set axis_path = % axis_path %; % axis_home %/ mtv-common.jar <br/> set axis_path = % axis_path %; % axis_home %/saaj. jar <br/> set axis_path = % axis_path %; % axis_home %/wsdl4j-1.5.1.jar <br/> set CLASSPATH = % CLASSPAHT %; % axis_path % <br/> java org. apache. axis. wsdl. WSDL2Java -- server-side -- skeletonDeploy true UserManage. wsdl

After the above batch file is executed, the directory and structure of the source code will be generated as follows:

The file generated under the usermanage_pkg package is as follows:

Deploy. WSDD <br/> undeploy. WSDD <br/> usermanage. java <br/> usermanageservice. java <br/> usermanageservicelocator. java <br/> usermanagesoapbindingimpl. java <br/> usermanagesoapbindingskeleton. java <br/> usermanagesoapbindingstub. java

In addition, a com package is generated. The Java file under this package is basically the same as the file we first defined in step 1.

Use eclipse to compile the above-generated Java code, export as a mtv-service.jar

(4) Publish the WebService Service under Tomcat according to the deploy. WSDD File 

Copy axis under the axis-1_4/webapps directory directly to the tomcat/webapps directory, and then put the mtv-service.jar package under the tomcat/webapps/axis/Web-info/lib directory, start Tomcat, run the following command: deploy. the bat batch processing command can be used to publish the usermanage service.

Deploy. BAT:

Set axis_home = D:/software/axis2/axis-1_4/lib <br/> set axis_path = % axis_home %/axis-ant.jar <br/> set axis_path = % axis_path %; % axis_home %/axis. jar <br/> set axis_path = % axis_path %; % axis_home %/commons-discovery-0.2.jar <br/> set axis_path = % axis_path %; % axis_home %/ commons-logging-1.0.4.jar <br/> set axis_path = % axis_path %; % axis_home %/jaxrpc. jar; <br/> set axis_path = % axis_path %; % axis_home %/log4j-1.2.8.jar <br/> set axis_path = % axis_path %; % axis_home %/SAAJ. jar <br/> set axis_path = % axis_path %; % axis_home %/wsdl4j-1.5.1.jar <br/> set classpath = % classpaht %; % axis_path % <br/> JAVA Org. apache. axis. client. adminclient-L "http: // localhost: 9000/axis/services/usermanage" deploy. WSDD

After the above four steps, our usermanage service was successfully released.

Http: // localhost: 9000/axis/servlet/axisservlet can be used to view the usermanage service just released.

 

Note:

When a server-config.wsdd file exists, the WebService Service is published in the above way, and then we can rename the original server-config.wsdd file, follow the steps above(4)The service is published in a way that generates new server-config.wsdd files again. We can copy the code block similar to the following in the new file to the original server-config.wsdd file to merge the new services to be released into the original service, so that the new and old services can coexist.

<Service name = "usermanage" provider = "Java: RPC "> <br/> <parameter name =" allowedmethods "value =" * "/> <br/> <parameter name =" typemappingversion "value =" 1.2 "/> <br/> <parameter name = "wsdlporttype" value = "usermanage"/> <br/> <parameter name = "classname" value = "usermanage_pkg.usermanagesoapbindingskeleton"/> <br/> <parameter Name = "wsdlserviceport" value = "usermanage"/> <br/> <parameter name = "wsdltargetnamespace" value = "urn: usermanage "/> <br/> <parameter name =" wsdlserviceelement "value =" usermanageservice "/> <br/> <parameter name =" schemaunqualified "value =" http://schemas.services.commons.mtv.huawei.com "/> <br/> <typemapping deserializer = "org. apache. axis. encoding. ser. beandeserializerfactory "encodingstyle =" http://schemas.xmlsoap.org/soap/encoding/ "QNAME =" NS1: userregisterevt "serializer =" org. apache. axis. encoding. ser. beanserializerfactory "type =" Java: COM. huawei. MTV. commons. services. schemas. userregisterevt "xmlns: NS1 =" http://schemas.services.commons.mtv.huawei.com "/> <br/> <typemapping deserializer =" org. apache. axis. encoding. ser. beandeserializerfactory "encodingstyle =" http://schemas.xmlsoap.org/soap/encoding/ "QNAME =" NS2. userregisterresp "serializer =" org. apache. axis. encoding. ser. beanserializerfactory "type =" Java: COM. huawei. MTV. commons. services. schemas. userregisterresp "xmlns: NS2. =" http://schemas.services.commons.mtv.huawei.com "/> <br/> </service>

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.