CXF using the CXF API Publishing Service and making client calls

Source: Internet
Author: User

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

 

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.