"Dark Horse Android" (CXF) Introduction and the use of ant tools/cxf Summary

Source: Internet
Author: User

CXF introduction and use of ant tools


Ant tools: 1. Why use ant as a tool? Ant has been widely used as a tool and has a long history.
With Ant's built-in commands, you can compile Java source files (javac), run Java files (Java), Package class files (jar, war, ear),
You can also create (mkdir), delete (Del), copy (copy), and even use ant to execute SQL files.
Because Ant is a file written in an XML language, it is named Build.xml file by default.
So, in the future, you should know that this is an ant file when you see the file named Build.xml.


The Ant tool is followed by the name of the task


Ant server runs the server class and publishes a WebService


Ant client calls a webservice that has already been published


Ant clean clears the generated class file


Ant War to make a Java project into a war package


Ant deploy-dtomcat=true Copies the war into the WebApp under Tomcat.


Ant Undeploy-dtomcat=true; Uninstall the project under Tomcat:

CXF Summary Service side:
Publish a service with the class provided by the CXF framework
Use CXF to provide Serverfactorybean to publish WebService
The published class can not be labeled WebService annotations, the class can not contain a valid method,
If no valid method is included. It will provide an empty service.
Create a class to publish the service ...
Serverfactorybean bean=new Serverfactorybean ();
Bean.setaddress ("Http://192.168.9.100:8080/server");//service external access address
Bean.setserviceclass (Cxfwebservice.class);//sets the interface type of the service class, or the current class if there is no interface:
Bean.setservicebean (New Cxfwebservice ());//Set the implementation of the service class
Bean.create ();//Publish Service
The second method of publishing:
------------------------------------------------------------------------------------------
Use the class Jaxwsserverfactorybean provided by the CXF framework to publish WebService
Jaxwsserverfactorybean is a subclass of Serverfactorybean ...
Jaxwsserverfactorybean bean=new Jaxwsserverfactorybean ();
Bean.setaddress ("Http://192.168.9.100:8080/server");//service external access address
Bean.setserviceclass (Cxfwebservice.class);//sets the interface type of the service class, or the current class if there is no interface:
Bean.setservicebean (New Cxfwebservice ());//Set the implementation of the service class
Bean.create ();//Publish Service


-------------------------------------------------------------------------------------------
Client:
Invoke the service with the class provided by the CXF framework: (You need to rely on an interface to get the Wsimport generated code ...)
Create a class that calls the WebService service ...
Clientproxyfactorybean bean=new Clientproxyfactorybean ();
Bean.setaddress ("Http://192.168.9.100:8080/server");//set access address ...
Bean.setserviceclass (Cxfwebserviceporttype.class);//Set the interface of the service ...
Create interface Type ...
Cxfwebserviceporttype cxfwebserviceporttype= (Cxfwebserviceporttype) bean.create ();
Cxfwebserviceporttype.sayhello ();
----------------------------------------------------------------------------------
Use CXF to provide class Jaxwsproxyfactorybean to invoke the service side of WebService ....


Jaxwsproxyfactorybean is a subclass of Clientproxyfactorybean ...
Create a class that invokes the service ...
Jaxwsproxyfactorybean bean=new Jaxwsproxyfactorybean ();
Set Access Address
Bean.setaddress ("Http://192.168.9.100:7418/userService");
Set interface type ...
Bean.setserviceclass (Userservice.class);
UserService us= (UserService) bean.create ();


String Data=us.getuserbyid (1);


SYSTEM.OUT.PRINTLN (data);
---------------------------------------------
Invoke principle: Summarize ...
Service side: Client
Serverfactorybean------------Clientproxyfactorybean
Jaxwsserverfactorybean----------------Jaxwsproxyfactorybean
Jaxwsserverfactorybean can release the soap1.2 version of the protocol .... When publishing a service,
We'd better be publishing the service class to interface-oriented programming.


Command: Wsdl2java
Wsdl2java is the command given to us by the CXF framework, which functions like wsimport ...

Interceptors:
The mechanism of interceptors is provided in the CXF framework, and we can get the data format when the client interacts with the server through the interceptor.
Create a class to publish the service ...
Jaxwsserverfactorybean bean=new Jaxwsserverfactorybean ();
Set up an external access address
Bean.setaddress ("Http://192.168.9.100:7418/userService");
Bean.setserviceclass (Userservice.class);//set interface type ...
Bean.setservicebean (New Userserviceimpl ());//Set the implementation class of the interface ...
We can add a message blocker when publishing a service
Intercepting messages from clients for requests sent to the server
Bean.getininterceptors (). Add (New Loggingininterceptor ());
Intercept the message returned by the server to the client ...
Bean.getoutinterceptors (). Add (New Loggingoutinterceptor ());
Bean.create ();



"Dark Horse Android" (CXF) Introduction and the use of ant tools/cxf Summary

Related Article

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.