Adding dependencies in the Pom.xml file in the client service
<Dependencies> <Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-rt-frontend-jaxws</Artifactid> <version>3.2.5</version> </Dependency> <Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-core</Artifactid> <version>3.2.5</version> </Dependency> <Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-rt-transports-http-jetty</Artifactid> <version>3.2.5</version> </Dependency> </Dependencies>
To add a log interceptor to the Server service
PackageCom.rg2.webservice.impl;ImportJavax.xml.ws.Endpoint;ImportOrg.apache.cxf.interceptor.LoggingInInterceptor;ImportOrg.apache.cxf.jaxws.JaxWsServerFactoryBean;ImportCom.rg2.webservice.HelloWorld; Public classServer { Public Static voidMain (string[] args) {System.out.println ("Web Service Start"); HelloWorld implementor=NewHelloworldimpl (); String Address= "Http://localhost/helloWorld";//endpoint.publish (address, implementor);//JDK implementation exposes WebService interfaceJaxwsserverfactorybean Factorybean =NewJaxwsserverfactorybean (); Factorybean.setaddress (address);//set the exposure addressFactorybean.setserviceclass (HelloWorld.class);//Interface ClassFactorybean.setservicebean (implementor);//Setting the implementation classFactorybean.getininterceptors (). Add (NewLoggingininterceptor ());//Add in Interceptor log blockerFactorybean.getoutinterceptors (). Add (NewLoggingininterceptor ());//add an Out interceptor log interceptorFactorybean.create ();//creating the WebService interfaceSYSTEM.OUT.PRINTLN ("Web service Started"); }}
Adding a log interceptor to the client service
PackageCom.rg2.webservice;Importjava.util.List;ImportOrg.apache.cxf.frontend.ClientProxy;ImportOrg.apache.cxf.interceptor.LoggingInInterceptor; Public classClient { Public Static voidMain (string[] args) {HelloWorldService service=NewHelloWorldService (); HelloWorld Helloworldport=Service.gethelloworldport (); Org.apache.cxf.endpoint.Client Client=clientproxy.getclient (Helloworldport); Client.getininterceptors (). Add (NewLoggingininterceptor ());//Add in Interceptor log blockerClient.getoutinterceptors (). Add (NewLoggingininterceptor ());//add an Out interceptor log interceptorMyrolearray getroles=Helloworldport.getroles (); List<MyRole> rolelist =Getroles.item; for(inti = 0; I < rolelist.size (); i++) {Myrole my=Rolelist.get (i); System.out.print (My.key+ ":"); for(Role role:my.value) {System.out.print (Role.getid ()+","+role.getrolename ()); } System.out.println ("==============="); } }}
Learn WebService's CXF (6): cxf log Blocker