I wanted to use spring Of AOP to webservice To add a section , But use around After slicing , The calling end can't get webservice Return result of , And the details of the message are not known , It's embarrassing , So I stole a lazy . But what we should do is to do , Don't ask to check the call log later , I can't take anything out , It's not an embarrassment that can be solved .

   What I use is based on cxf Of webservice, So the method of adding call logs is also based on cxf Of , The second is cooperation sping Development webservice. Basic webservice The implementation of the , It will not be explained here .

  One 、 Use LoggingInInterceptor Realization

   The first method , Is to use the log interception that has been implemented , Need to be configured log.properties.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> <jaxws:endpoint implementor="com.test.DepartServiceImpl" address="/departService">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
</jaxws:outInterceptors>
</jaxws:endpoint> </beans>
  <jaxws:inInterceptors> It's the input interceptor , It will be intercepted when the interface is called . Here is the log output after the interface is called .
----------------------------
ID: 1
Address: http://localhost:8080/test/ws/departService?wsdl
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=UTF-8
Headers: {Accept=[*/*], cache-control=[no-cache], connection=[keep-alive], Content-Length=[221], content-type=[text/xml; charset=UTF-8], host=[localhost:18080], pragma=[no-cache], SOAPAction=[""], user-agent=[Apache CXF 2.7.7]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:findEmployees xmlns:ns2="http://cxf.test.com/"><arg0> Zhang San </arg0><arg1></arg1></ns2:findEmployees></soap:Body></soap:Envelope>
--------------------------------------
  <jaxws:outInterceptors> It's the output interceptor , Intercepted at the end of the interface call . The following is the log output after the interface call is completed .
---------------------------
ID: 1
Encoding: UTF-8
Content-Type: text/xml
Headers: {}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:findEmployeesResponse xmlns:ns2="http://cxf.test.com/"><return><user_depart>IT</user_depart><user_name> Zhang San </user_name><user_state> on-the-job </user_state><user_tele></user_tele><user_type> Ordinary employees </user_type></return></ns2:findEmployeesResponse></soap:Body></soap:Envelope>
--------------------------------------

   We can see that the basic implementation has been very detailed , You can even see some important basic information . If this method doesn't meet your needs , Then look at the back .

  Two 、 Realization AbstractPhaseInterceptor

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException; public class WebserviceLogInterceptor extends AbstractPhaseInterceptor<Message> { public WebserviceLogInterceptor(){
super(Phase.RECEIVE);
} @Override
public void handleMessage(Message message) throws Fault {
StringBuffer sb = new StringBuffer();
// You can do convection here , Read data from stream , Then modify it to the data you want
InputStream is = message.getContent(InputStream.class);
String encoding = (String)message.get(Message.ENCODING);
int len = 0;
byte[] bytes = new byte[1024 * 4];
try {
while((len = is.read(bytes))!=-1){
sb.append(new String(bytes, 0, len, encoding));
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(sb.toString());
      // One thing to note here is , If the revised soap Message format does not match webservice Frame format , such as : The encapsulated format of the framework is
//<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" <soap:Body>
//< Here is the namespace for calling the server-side method >< This is the parameter name >
// Here's the real news
//</ Here is the namespace for calling the server-side method ></ This is the parameter name >
//</soap:Body>
//</soap:Envelope>
try {
message.setContent(InputStream.class, new ByteArrayInputStream(sb.toString().getBytes(encoding)));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}

   Add the corresponding interceptor to the configuration file .

<jaxws:endpoint implementor="com.test.cxf.impl.DepartServiceImpl" address="/departService">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
<bean class="com.test.interceptor.WebserviceLogInterceptor" />
</jaxws:inInterceptors>
</jaxws:endpoint>

   It should be noted that , After processing the data , You need to write back to the stream , Otherwise, the interface can't get the parameters .

import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase; import java.io.*; public class WebserviceLogInterceptor1 extends AbstractPhaseInterceptor<Message> { public WebserviceLogInterceptor1(){
super(Phase.PRE_STREAM);
} @Override
public void handleMessage(Message message) throws Fault {
StringBuffer sb = new StringBuffer();
OutputStream os = message.getContent(OutputStream.class); message.setContent(OutputStream.class, new CachedOutputStream()); message.getInterceptorChain().doIntercept(message); CachedOutputStream csnew = (CachedOutputStream) message.getContent(OutputStream.class);
try {
String encoding = (String)message.get(Message.ENCODING);
InputStream in = csnew.getInputStream(); int len = 0;
byte[] bytes = new byte[1024 * 4];
while((len = in.read(bytes))!=-1) {
sb.append(new String(bytes, 0, len, encoding));
}
System.out.println(sb.toString());
// Here to xml Do the processing , It's the same thing when it's done , Writing in reflow
IOUtils.copy(new ByteArrayInputStream(sb.toString().getBytes(encoding)), os); os.flush(); } catch (IOException e) {
e.printStackTrace();
} message.setContent(OutputStream.class, os);
}
}

   alike , After reading the data , Still need to write back into the stream , Otherwise, the caller will not get the result .

add to webservice More about call logs

  1. How to add WebService User authentication when calling

    scene : When the release of good WebService Address or WSDL When supplied to the caller , You need to authenticate the other party's identity before allowing progressive access to the interface . Instead of being public, anyone can call . solve : 1. stay IIS Set the directory access rights of the corresponding website in . ...

  2. C# dynamic webservice Call interface (JAVA,C#)

    C# dynamic webservice Call interface using System; using System.Collections; using System.IO; using System.Net; using ...

  3. Using custom signed https Of ssl Security problem solving and metro Of webservice call

    I've been working on new projects recently , Work overtime to 8 Some more , I haven't even blogged . The new project has a lot of problems , Now take advantage of the sudden blackout to record the call https The question of . Our service is mainly , We call the data source data , And then provide interface for external data call . I ...

  4. WebService call

    One .WebService call 1.webservice Four call modes are supported :SOAP 1.1,SOAP 1.2,GET,POST.           2. If you want to webservice Support GET,POST transfer ...

  5. WebService call 1(.Net)

    1. Create the simplest Web Service (1)   newly build - project -ASP.NET empty WEB Applications (2) Add a new item -WEB service By default, a HelloWorld Method : using System; us ...

  6. WebService Call three methods

    // source :http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html Do a project recently , Because it's developed in someone else's framework app, It leads to a lot of restrictions ...

  7. webservice Call and generate

    webservice brief introduction : Web Service technology , It can make different applications run on different machines without the aid of additional . Specialized third-party software or hardware , You can exchange data or integrate with each other . basis Web Service Between the application of specification implementation ...

  8. WebService call SSAS course

    WebService call SSAS course One . establish SSAS project Use SQL Server Business Intelligence Development Studio newly build Analysis Servic ...

  9. Client side Settings WebService Call timeout

    Rigid contact WebService, How to set up in the client WebService The call timeout looks up some information , It is summarized as follows : ============================================== ...

Random recommendation

  1. angular-ui-router Medium $stateProvider Set up

    $stateProvider .state('contacts.list', { url: '', templateUrl: 'contacts.list.html' }) .state('conta ...

  2. Coursera Machine learning course Fundamentals of machine learning : A case study certificate

    Completed the course 1   Fundamentals of machine learning : A case study Post a certificate , Continue to work hard to complete the following courses :

  3. Debug Don't break down Release One reason for a version crash

    There's a project today Debug It's normal ,Release collapse , Extremely depressed . Studied for a while in the afternoon , The reason is that a class member variable is not initialized in the constructor . and Debug There's no problem with the version . So define class members , You must not forget to initialize !!

  4. bzoj1624 [Usaco2008 Open] Clear And Present Danger Treasure Hunt

    Description      Farmer John is sailing in a small boat on the sea of niuleby .      There are N(1≤N≤100) An island , use 1 To N Number . John from 1 We're going to start from island number one , We finally reached N Island number one . One The treasure map says , If he's on his way ...

  5. kylin3

    RDBMS: Relational database management system (Relational Database Management System), It's a system that organizes data into related rows and columns , And the computer software that manages the relational database is the relational database management system , ...

  6. 690. Employee Importance

    There are several ways to write it , Post a few here The first one is : Violence solution , Remove the recursive stack , Spatial complexity O(1). The time complexity is slightly higher /* // Employee info class Employee { public: // It's ...

  7. [leetcode]163. Missing Ranges Missing range

    Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, up ...

  8. Linux Some basic orders one ( Learning notes 3 )

    Rookie record . One . Change host name hostname New host name hostname ln0491 Change the host name to ln0491 Log out and then log in , It becomes the new host name Two . New folder and delete Such as : Create a new... In the current path data file ...

  9. Python Value set operations

    list_l1 = [12,1,4,6,9,5,4,2,11] list_l1 = set(list_l1) print(list_l1,type(list_l1)) # Sets are also disordered list_2 ...

  10. session It doesn't have to be cookie Open to use . You can also use get Pass parameters

    session It doesn't have to be cookie Open to use . You can also use get Pass parameters Can be session_id(); Set to a constant . define(’s_id‘ ,$_COOKIE['session_nam ...