WebService interceptors: Data for dynamic operation of requests and responses during WebService requests
Classification
Points by Location: server-side Interceptor Client Interceptor
According to the direction of the message: Into the interceptor out of the interceptor
By definition: System Interceptor Custom Interceptor
Adding interceptors on the server side
package com.demo;//attention to the introduction of the class must be correct import javax.xml.ws.endpoint;import org.apache.cxf.interceptor.loggingininterceptor;import org.apache.cxf.jaxws.endpointimpl;public Class webserviceapp {public static void main (String[] args) { System.out.println ("starting web service... "); Helloworldimpl implementor = new helloworldimpl (); string address = "Http://localhost:8080/helloWorld"; Endpoint endpoint = endpoint.publish (address, implementor);// jaxws api go to cxf API Add log Blocker endpointimpl jaxwsendpointimpl = (Endpointimpl) endpoint;o Rg.apache.cxf.endpoint.server server = jaxwsendpointimpl.getserver (); O Rg.apache.cxf.endpoint.endpoint cxfendpoint = server.getendpoint (); Loggingininterceptor logging = new loggingininterceptor (); CxfEndpoint.getInInterceptors (). Add (logging); System.out. println ("web service started");}}
Client
package com.demo.client;import org.apache.cxf.interceptor.loggingoutinterceptor;import org.apache.cxf.jaxws.jaxwsproxyfactorybean;import com.demo.helloworld;import com.demo.user;//Reference http ://blog.csdn.net/fhd001/article/details/5778915public class helloworldclient {public Static void main (String[] args) {JaxWsProxyFactoryBean svr = new Jaxwsproxyfactorybean (); Svr.setserviceclass (Helloworld.class); Svr.setaddress ("Http://localhost:8080/helloWorld "); helloworld hw = (HelloWorld) svr.create ();// jaxws api go to cxf api Add log Blocker 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); User user = neW user (); User.setusername ("Umgsai"); User.setdescription ("Test"); System.out.println (Hw.sayhitouser (user)); String sayhi = hw.sayhi ("test~~~"); System.out.println (Sayhi);}}
This article is from "Avatar" blog, please make sure to keep this source http://shamrock.blog.51cto.com/2079212/1563337
WebService Learning notes-cxf adding interceptors