Learn WebService's CXF (6): cxf log Blocker

Source: Internet
Author: User

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

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.