WebService-Java implementation CXF (add system pre-defined Interceptors)

Source: Internet
Author: User

1. overview

CXF allows us to add interceptors in the WebService In/out Location. Interceptors have two major classifications, one for which the system is predefined, and the other for custom Interceptors.

2. Add interceptors on the server Side.
Jaxwsserverfactorybean Wssvrfactorybean =NewJaxwsserverfactorybean (); String Address= "http://127.0.0.1/helloWorld";        Wssvrfactorybean.setaddress (address); Wssvrfactorybean.setserviceclass (HelloWorld.class); HelloWorld implementor=NewHelloworldimpl ();        Wssvrfactorybean.setservicebean (implementor); //add in Out logging interceptors        wssvrfactorybean.getininterceptors (). Add (new loggingininterceptor ()); Wssvrfactorybean.getoutinterceptors (). Add (new loggingoutinterceptor ()); Wssvrfactorybean.create ();
3. Add interceptors to client Side. 3.1 Adding CXF references in the client project
<dependencies>    <dependency><groupId>org.apache.cxf</groupId><artifactId> Cxf-core</artifactid><version>3.1.5</version></dependency>  <dependency>< Groupid>org.apache.cxf</groupid><artifactid>cxf-rt-frontend-jaxws</artifactid><version >3.1.5</version></dependency><dependency><groupId>org.apache.cxf</groupId> <artifactid>cxf-rt-transports-http-jetty</artifactid><version>3.1.5</version></ Dependency>  </dependencies>
3.2 Adding interceptors using Clientproxy objects
HelloWorld helloworldclient = new HelloWorldService (). gethelloworldport ();//add on Inteceptorsorg.apache.cxf.endpoint.Client Client = clientproxy.getclient (helloworldclient); Client.getininterceptors (). Add (new loggingininterceptor ()); client.getoutinterceptors (). Add (new Loggingoutinterceptor ());
4. Client/server Output Information

--client--

December 30, 2016 11:25:45 pm Org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildservicefromwsdl info: Creating Service {http://webservice.tuo.example.com/}helloworldservice from wsdl:http://127.0.0.1/helloworld? WSDL December 30, 2016 11:25:46 pm Org.apache.cxf.services.HelloWorldService.HelloWorldPort.HelloWorld info: Outbound Message---------------------------id:1address:http://127.0.0.1/helloworldencoding:utf-8http-method: Postcontent-type:text/xmlheaders: {accept=[*/*], soapaction=[""]}payload: <soap:envelope xmlns:soap= "/http/ Schemas.xmlsoap.org/soap/envelope/"><soap:body><ns2:sayhello xmlns:ns2="/http Webservice.tuo.example.com/"><arg0>tony</arg0></ns2:sayhello></soap:body></soap: Envelope>--------------------------------------December 30, 2016 11:25:47 pm Org.apache.cxf.services.HelloWorldService.HelloWorldPort.HelloWorld information: Inbound Message----------------------------id:1response-code:200encoding:utf-8content-type:text/xml;Charset=utf-8headers: {content-type=[text/xml; charset=utf-8], date=[fri, Dec 15:25:46 GMT], server=[jetty ( 9.2.11.v20150529)], transfer-encoding=[chunked]}payload: <soap:envelope xmlns:soap= "http://schemas.xmlsoap.org /soap/envelope/"><soap:body><ns2:sayhelloresponse xmlns:ns2=" http://webservice.tuo.example.com/" ><return>hello world,tony</return></ns2:sayhelloresponse></soap:body></soap: Envelope>--------------------------------------Hello World,tony

--server--

Information: Inbound message----------------------------id:1address:http://127.0.0.1/helloworld?wsdlhttp-method: Getcontent-type:text/xmlheaders: {accept=[*/*], cache-control=[no-cache], connection=[keep-alive], content-type=[ text/xml], host=[127.0.0.1], pragma=[no-cache], User-agent=[apache CXF 3.1.5]}------------------------------------- -December 30, 2016 11:25:46 pm Org.apache.cxf.services.HelloWorldService.HelloWorldPort.HelloWorld info: Inbound Message----------------------------id:2address:http://127.0.0.1/helloworldencoding:utf-8http-method: postcontent-type:text/xml; Charset=utf-8headers: {accept=[*/*], cache-control=[no-cache], connection=[keep-alive], Content-Length=[202], content-type=[text/xml, charset=utf-8], host=[127.0.0.1], pragma=[no-cache], soapaction=["" ", User-Agent=[Apache CXF 3.1.5]}payload: <soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" ><soap:Body> <ns2:sayhello xmlns:ns2= "http://webservice.tuo.example.com/" ><arg0>tony</arg0></ns2:sayHello></soap:Body></soap:Envelope>--------------------------------------December 30, 2016 11:25:47 pm Org.apache.cxf.services.HelloWorldService.HelloWorldPort.HelloWorld info: Outbound Message---------------------------id:2response-code:200encoding:utf-8content-type:text/xmlheaders: {}payload: <soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" ><soap:body><ns2: Sayhelloresponse xmlns:ns2= "http://webservice.tuo.example.com/" ><return>hello world,tony</return> </ns2:sayHelloResponse></soap:Body></soap:Envelope>--------------------------------------

  

WebService-Java implementation CXF (add system pre-defined 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.