Previously introduced the use of JAX-WS to publish WebService, today a brief introduction to cxf.
Step 1: Create a Java Project
Various jar packages related to cxf provide a variety of functions, just create a Java Project
Step 2, introduce the relevant jar package http://download.csdn.net/detail/duanml61/5068049
1. commons-logging-1.1.1.jar
2. geronimo-activation_1.1_spec-1.0.2.jar (or Sun's activation jar)
3. geronimo-annotation_1.0_spec-1.1.1.jar (JSR 250)
4. geronimo-javamail_1.4_spec-1.6.jar (or Sun's javamail jar)
5. geronimo-servlet_2.5_spec-1.2.jar (or Sun's servlet jar)
6. geronimo-ws-metadata_2.0_spec-1.1.2.jar (JSR 181)
7. geronimo-jaxws_2.1_spec-1.0.jar (or Sun's jaxws-api-2.1.jar)
8. geronimo-stax-api_1.0_spec-1.0.1.jar (or other Stax-API jar)
9. jaxb-api-2.1.jar
Jaxb-impl-2.1.12.jar
11. jetty-6.1.21.jar
Jetty-util-6.1.21.jar
13. neethi-2.0.4.jar
14. saaj-api-1.3.jar
Saaj-impl-1.3.2.jar
16. wsdl4j-1.6.2.jar
17. wstx-asl-3.2.8.jar
18. XmlSchema-1.4.5.jar
19. xml-resolver-1.2.jar
Cxf-2.2.2.jar
21. commons-logging-1.1.1.jar
22geroni1_activation_1.1_spec-1.0.2.jar (or Sun's activation jar)
23. geronimo-annotation_1.0_spec-1.1.1.jar (JSR 250)
24. geronimo-javamail_1.4_spec-1.6.jar (or Sun's javamail jar)
25. The geronimo-servlet_2.5_spec-1.2.jar (or Sun's servlet jar)
26. geronimo-ws-metadata_2.0_spec-1.1.2.jar (JSR 181)
27. geronimo-jaxws_2.1_spec-1.0.jar (or Sun's jaxws-api-2.1.jar)
28. geronimo-stax-api_1.0_spec-1.0.1.jar (or other Stax-API jar)
29. jaxb-api-2.1.jar
30. jaxb-impl-2.1.12.jar
31. jetty-6.1.21.jar
32. jetty-util-6.1.21.jar
33. neethi-2.0.4.jar
Saaj-api-1.3.jar
5. saaj-impl-1.3.2.jar
Wsdl4j-1.6.2.jar
37. wstx-asl-3.2.8.jar
38. XmlSchema-1.4.5.jar
39. xml-resolver-1.2.jar
40. cxf-2.2.2.jar
Step 3: Create a WebService Interface
Package COM. xjtu. broadcast;/***** <p> * Title: Test code/P> *** <p> * description: example business class * </P> ** <p> * copyright: Copyright (c) 2012 * </P> ** @ author DML @ 2013-1-11 * @ version 1.0 */public interface broadcastservice {public void sendbroadcastmsg (string message, string groupname );}
Step 4: implement the WebService Interface
Package COM. xjtu. broadcast; import Org. jivesoftware. smack. connection; import Org. jivesoftware. smack. connectionconfiguration; import Org. jivesoftware. smack. xmppconnection; import Org. jivesoftware. smack. xmppexception; import Org. jivesoftware. smack. packet. message;/***** <p> * Title: Test code/P> *** <p> * description: example business class * </P> ** <p> * copyright: Copyright (c) 2012 * </P> ** @ author DML @ 2013-1-11 *@ Version 1.0 */public class broadcastserviceimpl implements broadcastservice {/*** get connection ** @ return connection */public static connection getconnection () {string IP = "127.0.0.1 "; integer Dk = 5222; connectionconfiguration Config = new connectionconfiguration (IP, DK); connection = new xmppconnection (config); return connection ;} /*** send broadcast message ** @ Param message * [message content] * @ Param groupname * [Group Name] */Public void sendbroadcastmsg (string message, string groupname) {try {connection con = broadcastserviceimpl. getconnection (); con. connect (); con. loginanonymously (); // Anonymous logon. System. out. println ("Authenticated =" + con. isauthenticated () + "" + con. getuser (); message m = new message (); M. setbody (Message); // sets the message. M. setto (groupname + "@ broadcast. xjtu "); // [groupname] @ [servicename]. [servername] con. sendpacket (m);} catch (xmppexception e) {// todo auto-generated catch blocke. printstacktrace ();}}}
Step 5: Create a server
Package COM. xjtu. broadcast; import Org. apache. cxf. frontend. serverfactorybean;/***** <p> * Title: Test code/P> ** <p> * description: example business class * </P> ** <p> * copyright: Copyright (c) 2012 * </P> ** @ author DML @ 2013-1-11 * @ version 1.0 */public class server {public static void main (string [] ARGs) {broadcastserviceimpl BSI = new broadcastserviceimpl (); serverfactorybean factorybean = new serverfactorybean (); factorybean. setaddress ("http: // localhost: 8080/broadcast"); factorybean. setserviceclass (broadcastservice. class); factorybean. setservicebean (BSI); factorybean. create ();}}
Step 6: run the server program, open the browser, and enter http: // localhost: 8080/broadcast? WSDL
Step 7: Create a client and call Related Services
Dml@2013.2.17