Publishing a service using the CXF API
Package server; Import Javax.xml.ws.Endpoint; Import Org.apache.cxf.interceptor.LoggingInInterceptor; Import Org.apache.cxf.jaxws.EndpointImpl; public class Server_textcxfapi {Server_textcxfapi () {Myhelloworldimpl implementor = new Myhelloworldimpl (); String address = "Http://localhost:9000/myHelloWorld"; Endpoint Endpoint = endpoint.publish (address, implementor); Jaxws API go to CXF API Add Log Interceptor Endpointimpl Jaxwsendpointimpl = (endpointimpl) endpoint; Org.apache.cxf.endpoint.Server Server = Jaxwsendpointimpl.getserver (); Org.apache.cxf.endpoint.Endpoint cxfendpoint = Server.getendpoint (); Loggingininterceptor logging = new Loggingininterceptor (); Cxfendpoint.getininterceptors (). Add (logging); public static void Main (string[] args) throws interruptedexception {new Server_textcxfapi (); System.out.println ("Server ready ..."); Thread.Sleep (5*60*1000); System.out.println ("Server exiting"); System.exit (0); } }
Make client calls using CXF api
Package client; Import java.net.MalformedURLException; Import Java.net.URL; Import Javax.xml.namespace.QName; Import Javax.xml.ws.Service; Import Org.apache.cxf.interceptor.LoggingOutInterceptor; Import server. Myhelloworld; public class Client3_textcxfapi {public static void main (string[] args) {URL wsdlurl = null; try {wsdlurl = new URL (HT Tp://localhost:9000/myhelloworld?wsdl "); catch (Malformedurlexception e) {e.printstacktrace ();} final QName service_name = new QName ("http://server/", "Fhdhell Oworld "); Service service = Service.create (Wsdlurl, service_name); Myhelloworld HW = Service.getport (myhelloworld.class); Jaxws API go to CXF API Add log Interceptor Org.apache.cxf.endpoint.Client Client =org.apache.cxf.frontend.clientproxy.getclient (HW ); Org.apache.cxf.endpoint.Endpoint cxfendpoint = Client.getendpoint (); Loggingoutinterceptor logging = new Loggingoutinterceptor (); Cxfendpoint.getoutinterceptors (). Add (logging); Hw.sayhi ("Fuhaidong"); System.out.println ("Client:fuhaidong"); }} &NBSp