Based on the CXF framework, the WebService simple SC two-terminal access interceptor is implemented.

Source: Internet
Author: User
Tags wsdl

Development tools: ECLIPSE (EE) + CXF (2.5.9)


(I) You can now use the JDK in eclipse to create a WebService base service. (WebService without CXF frame)


(1) Create a new Java project. (named FirstWebService)

Create a new interface interface. Change the interface is equivalent to the SEI in the webservice.

(Use the JDK to bring WebService comments before the interface class definition [email protected]

The Sei method uses the @webmethod life method. )

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/74/wKioL1V9cWPhsIC3AAE2cY6sRaA447.jpg "title=" 2015-06-14_201215.jpg "alt=" Wkiol1v9cwphsic3aae2cy6sraa447.jpg "/>

(2) in defining an SEI implementation class. (This class requires the use of @webservice annotations)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/78/wKiom1V9cFCjHANPAAGl_KSvKSo723.jpg "title=" 2015-06-14_201448.jpg "alt=" Wkiom1v9cfcjhanpaagl_ksvkso723.jpg "/>


(3) Create a new class to test the WebService service. Use endpoint to publish the service. (The address after the IP can be fully customizable, note that the port does not conflict.) )

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/78/wKiom1V9cP6TH4CoAAFWiUsDBMI720.jpg "title=" 2015-06-14_201749.jpg "alt=" Wkiom1v9cp6th4coaafwiusdbmi720.jpg "/>


(4) The running program can see the service open. Also available through 650 in eclipse) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M01/6E/74/wKioL1V9c7GSDDHfAAAjzWVOwNk233.jpg "Title=" faststoneeditor1.jpg "alt=" wkiol1v9c7gsddhfaaajzwvownk233.jpg "/> Icon to test: (The following test is in WebService runtime ...)


Click on the icon---"Click on the icon in the top right corner 650) this.width=650;" Src= "http://s3.51cto.com/wyfs02/M01/6E/78/ Wkiom1v9cmfaqd0maaagwgza4-o030.jpg "title=" faststoneeditor2.jpg "alt=" Wkiom1v9cmfaqd0maaagwgza4-o030.jpg "/>-- -"Click on the left blue font WSDL Main. (If the response is slow, you can click the refresh button)-----"The following interface appears:


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/74/wKioL1V9dNCwf78SAADeiQsVM_I553.jpg "title=" 2015-06-14_202638.jpg "alt=" wkiol1v9dncwf78saadeiqsvm_i553.jpg "/>---" and then copy the address in (3) and add the following to the URL ? wsdl

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6E/74/wKioL1V9dczQTRa3AACyIHdWVVI534.jpg "title=" Qq20150614203110.png "alt=" Wkiol1v9dczqtra3aacyihdwvvi534.jpg "/>

Click Go to get the interface provided by WebService: that is, the SayHello method defined in the interface:


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/78/wKiom1V9c9Swr_7NAAF8WbkxFIw083.jpg "title=" Qq20150614202945.png "alt=" Wkiom1v9c9swr_7naaf8wbkxfiw083.jpg "/>





In fact, you can not define the SEI to achieve webservice, usually we can directly access the network of third-party WebService service interface. In a project similar to the custom: http://10.10.57.53:8989/FirstWebService/hellows?wsdl

After you get the WebService service, you can use the tool command that comes with the JDK

Msimport-keep http://10.10.57.53:8989/FirstWebService/hellows?wsdl

The corresponding Java source code can be generated automatically. (Use this command under DOS to enter the SRC directory of a new Java project)




(II) through the CXF framework in WebService, details how to use the framework to implement a simple out/log interceptor.

(1) Realize CXF integration based on the above project.

(2) Add CXF Runtime runtime class library. Right-click the project name---->build Path--->Libraries--> click on the right

ADD Library---> select cxf Runtime---> select version (click: config if not installed). ) will add the CXF home directory.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6E/74/wKioL1V9b3Cjn4lPAAKEl7U1tuI894.jpg "title=" 2015-06-14_200106.jpg "alt=" Wkiol1v9b3cjn4lpaakel7u1tui894.jpg "/>


(3) After adding, you can get the directory structure:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/78/wKiom1V9d3bg99hgAACLEhmYcfU645.jpg "title=" Qq20150614204441.png "alt=" Wkiom1v9d3bg99hgaaclehmycfu645.jpg "/>

(4) write the entry and exit settings for the log interceptor in the test class: (Note to convert the endpoint type to Endpointimpl.) The class has a method definition for the log interceptor)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6E/79/wKiom1V9eBCDwf8AAALuwG30Gf8745.jpg "title=" Qq20150614204720.png "alt=" Wkiom1v9ebcdwf8aaaluwg30gf8745.jpg "/>


(5) When running through step fourth (4) above (I), you can see that the console has a record of the WebService log Access interceptor.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/79/wKiom1V9eSbAPGvhAAHeeFoopGQ034.jpg "title=" Qq20150614205231.png "alt=" Wkiom1v9esbapgvhaaheefoopgq034.jpg "/>

[Email protected]

Release WebService success!!


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/75/wKioL1V9ewbTo30cAAIRltiNON4026.jpg "title=" Qq20150614205325.png "alt=" Wkiol1v9ewbto30caairltinon4026.jpg "/>



In fact, it is easy to create a project based on the WebService service interface after CXF. As long as the specified WebService service interface is obtained, the built source code can be obtained directly through the CXF command tool Wsdl2java.


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/79/wKiom1V9e2qQFkVSAAChKDoKq-E614.jpg "title=" Qq20150614210203.png "alt=" Wkiom1v9e2qqfkvsaachkdokq-e614.jpg "/>

(1) After downloading the CXF library file. Configure the bin path of the library in the environment variable path. (not required, for ease of use in Dos)

(2) Enter the source folder of a created Java project under SRC: (Remember the wsdlafter the URL)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/79/wKiom1V9ewrQgzoGAAEz2z6uN0M751.jpg "title=" Qq20150614210041.png "alt=" Wkiom1v9ewrqgzogaaez2z6un0m751.jpg "/>


At the same time, the client side of the interceptor implementation is roughly the same. Just the client is getting a client by Clientproxy the proxy class. The setting of the interceptor is implemented by the client.



This article is from "_ practice-driven thinking." "Blog, be sure to keep this provenance http://8567779.blog.51cto.com/8557779/1661841

Based on the CXF framework, the WebService simple SC two-terminal access interceptor is implemented.

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.