Webserive Learning Record 2-CXF Framework Foundation use

Source: Internet
Author: User

  CXF is a webservice frame, similar to axis, the following is the basic use of CXF.

The first thing to do is to download the Cxf file, and then to introduce the jar package into the project, which can be managed by MAVEN, of course. I'm using the latest version of 3.2.1, jar pack a lot, not very clear, a brain of all introduced.

  Service side

Then write the service-side code, the structure of my server is as follows:

Standardtime is an entity object, the return value of my method, a custom standardtime is used to describe the object that can be returned with CXF, or it can return a collection type, a base type, a string, and so on.

Then there is the interface and implementation class, and finally WSServer is used to start webservice.

The interface and implementation classes are as follows:

The entity class and startup class are as follows

The startup class adds a log-out interceptor that can be used to print information returned to the client.

  Client

Unlike the framework that comes with the JDK, the code that generates the client uses the Wsdl2java tool, and the detailed use of the Wsdl2java, please Baidu itself.

Create a new client project, build a package such as cxf.base.client, into the project SRC directory, in the address bar input cmd and enter, will open a command line window, directory is src directory, execute the following command:

Wsdl2java-p cxf.base.client-client http://192.168.0.102:9999/synctimews?wsdl

The client code is generated, as follows:

Then you can test it, and the test class is as follows:

A log-out interceptor is also used to print out the information sent by the client, which returns a custom object.

The results of the test are as follows:

Webserive Learning Record 2-CXF Framework Foundation use

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.