Configuration file Configuration
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:jaxws= "Http://cxf.apache.org/jaxws"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd Http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> <ImportResource= "Classpath:meta-inf/cxf/cxf.xml" /> <ImportResource= "Classpath:meta-inf/cxf/cxf-extension-soap.xml" /> <ImportResource= "Classpath:meta-inf/cxf/cxf-servlet.xml" /> <Context:component-scanBase-package= "Com.test.inf" /> <Jaxws:endpointID= "Syncuserservice"implementor= "Com.test.inf.testServiceImpl"Address= "/testinf"> <jaxws:ininterceptors> <Beanname= "Loggingininterceptor"class= "Org.apache.cxf.interceptor.LoggingInInterceptor"/> <Beanname= "Weblogininterceptor"class= "Com.test.inf.WebLogInInterceptor" /> </jaxws:ininterceptors> <jaxws:outinterceptors> <Beanname= "Loggingoutinterceptor"class= "Org.apache.cxf.interceptor.LoggingOutInterceptor" /> <Beanname= "Weblogoutinterceptor"class= "Com.test.inf.WebLogOutInterceptor" /> </jaxws:outinterceptors> </Jaxws:endpoint> </Beans>
Weblogininterceptor for input interceptors
Weblogoutinterceptor for output interceptors
PackageCom.test.inf;ImportJava.io.ByteArrayInputStream;ImportJava.io.InputStream;Importorg.apache.cxf.helpers.IOUtils;ImportOrg.apache.cxf.interceptor.Fault;ImportOrg.apache.cxf.message.Message;ImportOrg.apache.cxf.phase.AbstractPhaseInterceptor;Importorg.apache.cxf.phase.Phase; Public classWeblogininterceptorextendsAbstractphaseinterceptor<message> { PublicMessageininterceptor () {Super(phase.receive); } Public voidHandlemessage (Message message)throwsFault {Try{String xml; InputStream is= Message.getcontent (InputStream.class); String encoding=(String) message.get (message.encoding); XML=ioutils.tostring (IS); System.out.println ("Input message is:" +XML); Message.setcontent (InputStream.class,NewBytearrayinputstream (xml.getbytes (encoding))); Message.getexchange (). Put ("Idtest", XML); } Catch(Exception e) {e.printstacktrace (); } }}
Message.setexchage (). Put ("Idtest", XML); Store the input information
PackageCom.test.inf;ImportJava.io.ByteArrayInputStream;ImportJava.io.InputStream;ImportJava.io.OutputStream;Importorg.apache.cxf.helpers.IOUtils;ImportOrg.apache.cxf.interceptor.Fault;ImportOrg.apache.cxf.io.CachedOutputStream;ImportOrg.apache.cxf.message.Message;ImportOrg.apache.cxf.phase.AbstractPhaseInterceptor;Importorg.apache.cxf.phase.Phase; Public classMessageoutinterceptorextendsAbstractphaseinterceptor<message>{@SuppressWarnings ("Unused") PrivateString Mmessage; PublicMessageoutinterceptor () {Super(Phase.pre_stream); } Public voidHandlemessage (Message message)throwsFault {String xml; Try{String Inputxml= (String) message.getexchange (). Get ("Idtest"); System.out.println ("Input information::::" +inputxml); OutputStream OS= Message.getcontent (outputstream.class); Cachedstream CS=NewCachedstream (); Message.setcontent (OutputStream.class, CS); Message.getinterceptorchain (). dointercept (message); Cachedoutputstream csnew= (Cachedoutputstream) message.getcontent (outputstream.class); InputStream in=Csnew.getinputstream (); XML=ioutils.tostring (in); System.out.println ("Output Information:" +XML); Ioutils.copy (NewBytearrayinputstream (Xml.getbytes ()), OS); Cs.close (); Os.flush (); Message.setcontent (OutputStream.class, OS); } Catch(Exception e) {e.printstacktrace (); } } }
String inputxml = (string) message.getexchange (). Get ("Idtest"); Get input information
Record WebService interface logs, inputs and outputs can be recorded together