Service side:
1. Get the Endpointimpl object
2. Call the method in the Endpointimpl object to get the in interceptor
3. Call the method in the Endpointimpl object to get the out interceptor
4. Add your own in interceptor with an out interceptor
Logginininterceptor: Viewing received message packets
Loggoutinterceptor: Check out the sent message packet
Client:
7 jar packages to import CXF:
1. Get the Client object
Client client=clientproxy.getclient ("WS service component proxy object ")---The WS service component is the new service interface (). Getxxxport (); is the implementation class of the service-side service interface
2. Call the method in the client object to get the in interceptor
3. Call the method in the client object to get the out interceptor
4. Add your own in interceptor with an out interceptor
Logginininterceptor: Viewing received message packets
Loggoutinterceptor: Check out the sent message packet
------------------------Add a rights interceptor-----------------------------------
1. Add header elements to the SOAP package and carry the data with authentication permission
<Header>
<auth>
<auth_id> Account </auth_id>
<auth_pwd> Password </auth_pwd>
</auth>
</Header>
2. Client------To modify header header elements before sending a SOAP packet need to add an out interceptor
3. Server------Add in Interceptor Parse SOAP packet header header element
4. Custom interceptors-need to inherit Abstractphaseinterceprot;
----------------------------Custom Interceptor Case----------------------------
public class Headerinterceptor extends Abstractphaseinterceptor<soapmessage> {
Private String authId;
Private String pwd;
Public Headerinterceptor (String authId, string pwd) {
/** The Interceptor works before the SOAP packet is sent */
Super (Phase.prepare_send);
This.authid = authId;
This.pwd = pwd;
}
@Override
public void Handlemessage (SoapMessage soapmessage) throws Fault {
/**
* <auth>
<auth_id>admin</auth_id>
<auth_pwd>888888</auth_id>
</auth>
*/
Create document
Document doc = Domutils.createdocument ();
Create element
Element Authele = doc.createelement ("auth");
Element idele = doc.createelement ("auth_id");
Add text
Idele.settextcontent (AUTHID);
Element Pwdele = doc.createelement ("Auth_pwd");
Add text
Pwdele.settextcontent (PWD);
Append element
Authele.appendchild (Idele);
Authele.appendchild (Pwdele);
Creating header Headers
Header Header = new Header (New QName ("it"), Authele);
Get all Header headers, add header header
Soapmessage.getheaders (). Add (header);
}
Public String Getauthid () {
return authId;
}
public void Setauthid (String authId) {
This.authid = authId;
}
Public String getpwd () {
return pwd;
}
public void SetPwd (String pwd) {
This.pwd = pwd;
}
}
WebService Interceptor viewing message packets (SOAP)