AXIS2 Study Notes

Source: Internet
Author: User
Tags wsdl

Axis2Study Notes

Directory:

1. Preparation

2. Publish Service

3. Generating client code

1.     Prepare

Download axis2 's bin and war two release versions.

the Bin version is used to generate client code using the commands that are brought in.

The files in the Web-inf directory in the War package are used by the service provider.

2.     PublishService

Create a new Maven Project, add the following dependencies in Pom.xml:

        <dependency>             <groupId>org.apache.axis2</groupId>             <artifactId>axis2-kernel</artifactId>             <version>1.7.3</version>         </dependency>        < Dependency>            <groupid> org.apache.axis2</groupid>            < artifactid>axis2-ant-plugin</artifactid>             <version>1.7.3</version>        </ Dependency>        <dependency>            < groupid>org.apache.axis2</groupid>             <artifactId>axis2-corba</artifactId>             <version>1.7.3</version>        </ dependency>        <dependency>             <groupId>org.apache.axis2</groupId>             <artifactId>axis2-jaxws</artifactId>             <version>1.7.3</version>         </dependency>         <dependency> &nBsp;          <groupid>org.apache.axis2</groupid >            <artifactId>axis2-spring< /artifactid>            <version>1.7.3 </version>        </dependency>


in this example , with spring integration with Axis2 , there is axis2-spring dependency.

Add a axis2 servlet in Web. Xml , with the following code:

<servlet> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.apache.axis2.tra Nsport.http.axisservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>


configuration servlet-mapping:

<servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*& Lt;/url-pattern></servlet-mapping>


Copy the Conf,services,modules folders from the Web-inf directory in the downloaded War package to the project the Web-inf directory.

Create a new Service Pojo class:

Publicclass Nameservice {publicvoid print (String name) {System.err.println ("Print:" +name);    public string Getfullname (string name) {return ' Your name is ' +name; } }

Register The Nameservice class as a bean in spring.

<bean name= "Nameservice" class= "Com.hikvision.ws.service.NameService" ></bean>

Create a new Meta-inf directory under the Services directory and create a new Services.xml file in the Meta-inf directory to describe the service.


Services.xml:

<servicename= "Nameservice" >    <description>         NameService    </description>    < Parametername= "Serviceobjectsupplier" >        org.apache.axis2.extensions.spring.receivers.springservletcontextobjectsupplier    </ parameter>     <messagereceivers>         <messagereceivermep= "Http://www.w3.org/ns/wsdl/in-only"              class= "Org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>         <messagereceivermep= "Http://www.w3.org/ns/wsdl/in-out"              class= " Org.apache.axis2.rpc.receivers.RPCMessageReceiver "/>    </messagereceivers>&Nbsp;    <parametername= "Springbeanname" >         nameService    </parameter></service>


which

<parameter name= "Springbeanname" >

notice, don't appear in services.xml

<?xml version= "1.0" encoding= "UTF-8"?>

in the command line , enter the services directory, input command:JAR–CVF Nameservice.arr./meta-inf

This command is the current directory where the the files in the Meta-inf are packaged into a nameservice.arr file.

Note: This command is a jar command in the JDK and requires that you install the JDK locally and set environment variables.


This generates the corresponding arr file in the Services directory , which is the Nameservice.arr file generated in this example . the arr file is actually similar to the jar file, and the difference is:

*.jar: Contains only the class file and the manifest file, does not contain the resource file, the slice and so on all res files.

*.aar: Contains all resources,class , and res resource files.

The Nameservice.arr file contains services.xml, whichis a description of the service.

at this point, Nameservice Service configuration is complete. Start tomcatand enter the http://localhost:port/ Project publish directory /services/nameservice?wsdl in the browserto get the service WSDL.

3.     Generate client Code

Save the WSDL file obtained in the previous section as nameservice.xml.

Unzip The bin version of Axis2 , switch to the current directory on the command line, and execute the following command:

D:\axis2-1.7.3\bin\wsdl2java-uriNameService.xml-p Com.test.webservice.stub–s

where " D:\axis2-1.7.3\"is the Axis2 bin version extracted to the directory. -uri Specifies the WSDL file,-P Specifies the package name, and- s represents synchronous execution.

the command generates the SRC folder in the current directory , with the *stub.java file in the folder and the call to WS with this file .

Create a new Maven Project, add the following dependencies in Pom.xml:

        <dependency>             <groupId>org.apache.axis2</groupId>             <artifactId>axis2-kernel</artifactId>             <version>1.7.3</version>         </dependency>        < Dependency>            <groupid> org.apache.axis2</groupid>            < artifactid>axis2-ant-plugin</artifactid>             <version>1.7.3</version>        </ Dependency>        <dependency>            < groupid>org.apache.axis2</groupid>             <artifactId>axis2-jaxws</artifactId>             <version>1.7.3</version>        </ Dependency>


Copies the generated stub.java file to the specified package in the project (refers to the package –p specified when the stub was generated ).

Create a new Nameserviceclient.java File:

import java.rmi.remoteexception; import com.hikvision.ws.stub.caculateservicestub;import  com.hikvision.ws.stub.caculateservicestub.plus;import com.hikvision.ws.stub.nameservicestub;import  com.hikvision.ws.stub.nameservicestub.getfullname; publicclass nameserviceclient {             publicstatic string getfullname (String  name) throwsremoteexception    {         Nameservicestub stub=new nameservicestub ("Http://127.0.0.1:8011/Axis2/services/NameService");         getfullname getfull=new getfullname ();         getfull.setname (name);         return  stub.getfullname (Getfull). Get_return ();    }         publicstaticvoid&nbSp;main (String[] args) throwsremoteexception {                 system.err.println (Getfullname ("12313416546-************************ "));             } }


The call to WebService is completed by running the file .


This article is from the "Flying Fish Technology" blog, please be sure to keep this source http://flyingfish.blog.51cto.com/9580339/1789661

AXIS2 Study Notes

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.