Axis and cxf of the WebService pop frame

Source: Internet
Author: User
Tags wsdl

Transferred from: http://www.cnblogs.com/snake-hand/archive/2013/06/09/3129915.html

Objective

In the last lesson , we gave a brief introduction to WebService, and we have a certain understanding of the technology applied to it. Today the main explanation is the two popular frames of the WebService Axis and the CXF.

Business

First, the service side release WebService

Before we talk, let's take a look at what this blog mainly explains:

Each framework has its own characteristics, with its own focus, but what they have in common is the encapsulation of the release WebService , so we just need to write a configuration file or use @WebService annotations to publish WebService, here we highlight their respective characteristics:

1.axis1

There are two ways to publish Axis1:

1)JWS method

A. this is simple, just put the source Java file under Axis_home, and then change the suffix to . JWs, so that AXIS The. JWs file is automatically compiled and automatically added to the Java Webservie service.

b. However, the disadvantage of this approach is that it can only be Java source code, and the class cannot contain the package name.

2)WSDD mode

1. Write a Java class (need to introduce the jar package of axis)

2. Configure the Web. xml file (config axisservlet,adminservlet, Soapmonitorservice, and Axishttpsessionlistener)

3. Write a DELOY.WSDD file, deploy the project (Tomcat launches to deploy the project)

Install Axis1 to Tomcat:

1.Axis Official website: http://ws.apache.org/axis/, you can download the latest 1.4 package on the website: axis-bin-1_4.zip

2. Test the Axis directory under the extracted axis-1_4\webapps\ to the%tomcat_home%/webapps/directory

3. Enter Http://localhost:port/axis in the browser after booting tomcat

4. Click on the Validataion link, the page will prompt the existing package and the missing package information, according to the prompt to download the necessary package,

Copy these class packages into the%tomcathome%/webapps/axis/web-inf/lib/directory

Restart Tomcat until the validation page does not see the message with error and warning.

2.axis2

There are two ways to call a client for different data types: Rpcserviceclient and Omabstractfactory mode

1) RPC mode:

Handle basic data types such as String,int, etc.

2)OM method:

Can handle basic data types and custom data types (such as Java entity Objects): pass through the XML parameter form (the passed arguments need to be converted to omelement)

Note: If the parameter or return value is a list type, you need to do a manual conversion (manually write a service side to process the passed arguments, convert the omelement manually to the List type, invoke the Execute method, and then return the the List type is then converted to omelement back to the client)

Axis2 Publishing Files ( writing services.xml)

1. The Axis2.war package is copied to Tomcat_home/webapps under the flag network, the operation will decompress

2. Copy its conf,modules and Services folder to the Web-inf under the project and copy the jar package under Lib to Web-inf/lib

3. configuring Web. Xml(configuration axisservlet and axisadminservlet)

4. write the Services.xml file under Services to specify the class to be published

3.CXF

CXF Release WebService There are three ways:main Way, based on and not published to Container based on Spring

1)main mode

Introduce jar packages, use @WebService on interfaces and implementation classes , access URLs in your browser after publishing is complete, andno need to start services like Tomcat.

2) do not publish to container based on Spring mode

A) introduce the CXF jar Package and write Web. XML (Configure custom Cxfservlet, which Cxfservlet need to inherit Cxfnonspringservlet)

b) Writing entity classes, business classes and service classes (entity class needs and service classes under the same package, otherwise error)

C) launch Tomcat to publish the service

3) Publish to container based on Spring method

A) Web . XML configuration (Spring configuration, cxfservlet configuration of the CXF package)

b) applicationcontext-server.xml configuration

<!--Import Apache CXF Bean definition Fixed--

<importresource= "Classpath:meta-inf/cxf/cxf.xml"/>

<importresource= "Classpath:meta-inf/cxf/cxf-extension-soap.xml"/>

<importresource= "Classpath:meta-inf/cxf/cxf-servlet.xml"/>

<!--Services Interface configuration--

<beanid= "Helloservicesbean" class= "Com.ms.services.impl.HelloServicesImpl"/>

<!--CXF configuration webservices service name and access address--

<jaxws:serverid= "Helloservices" address= "/helloservices"

serviceclass= "Com.ms.services.IHelloServices" >

<!--to expose WebService services--

<jaxws:serviceBean>

<refbean= "Helloservicesbean"/>

</jaxws:serviceBean>

</jaxws:server>

C) Writing classes

Entity class

Service interface (class header using @webservice)

Service implementation (class header using @webservice (endpointinterface= "com.ms.services.IHelloServices"))

The above is about Axis and CXF release characteristics and need to pay attention to the place, is I do the summary of examples, interested students can download the source code .

Second, the client calls WebService

After the server has successfully published the interface, it waits for the client to make the call, how and by what means does the client invoke the WSDL file that our server publishes ?

1. Invoke The essence of a WebService:

1. The client invokes the method parameter, transforms the generated XML document fragment (SOAP message,input message, the document fragment must conform to the WSDL definition Format), through the network, the XML document Fragments to the server

2. The server receives an XML document fragment, parses an XML document fragment, extracts the data from it, and converts the data to the parameter values required by the WebService.

3. server execution methods.

4. The return value obtained from the execution method is converted into an XML document fragment (SOAP message,output message)-The document fragment must conform to the WSDL- defined format, The XML document fragment is passed to the client.

5. The client receives the fragment of the XML document, parses the fragment of the XML document, extracts the data from it, and invokes the data transformation to call The return value of WebService.

From the above call essence, to a language support WebService, the only requirement is: The language supports XML document parsing, generation, support network transport.

2. Client Invocation method:

There are three ways in which a client invokes a server-side approach:

1)DII(Dynamic invocation Interface)

The use of direct invocation, you can set a number of call properties in the program, using more flexible, but the call process is relatively cumbersome and complex, easy to cause code bloat and low reusability, each call to different Web Service to repeat a lot of coding.

This is one of the more common methods, that is, call the invoke method, the method name and method parameters can be passed.

2)stubs

JAX-RPC uses a static stub to wrap calls to the underlying interface, providing a simpler way to call. Using this approach requires the implementation code of the WebService client to be pre-generated from the WSDL using the tools provided by the support environment (such as axis). Therefore, if the WSDL for the service changes, you must regenerate the new client code and redeploy it.

The method needs to use the Wsdl2java command to pre-generate the WebService client code, and in order to support the command, some environments need to be installed.

3)Dynamic Proxy

The dynamic proxy method implements a dynamic call to a Web Service that can create an adaptation object at run time based on a user -defined client interface. This avoids the direct operation of the underlying interface, reduces the redundancy of the client, and masks the complexity of the call.

This method mainly consists of the client interface, which needs to inherit the Java.rmi.Remote interface and then copy the methods in the interface of the server.

Summary:

From a historical point of view, it is easy to understand their focus,Axis 1 is the earliest, so the focus is simply the release interface, then the Axis2 to optimize it, can support the custom parameters, but not perfect, so CXF The advent of this feature has been refined and adapted to the current, to achieve the integration with Spring, compared with these,EJB3 in the support of WebService only need to use a @ WebService can be done, so software development is to make users dull, and we learn these to understand its principles and nature.

Axis and cxf of the WebService pop frame

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.