WebService Interceptor viewing message packets (SOAP)

Source: Internet
Author: User
Tags auth soap

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)

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.