WebService Learning notes-cxf adding interceptors

Source: Internet
Author: User

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

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.