Home > Back-end >  CXF achieve WebService SOAPHeader added and passed to the server authentication problem
CXF achieve WebService SOAPHeader added and passed to the server authentication problem

Time:09-20

This is my Header element encapsulated class
 
Public class AddSoapHeader extends AbstractSoapInterceptor {
Public AddSoapHeader () {
Super (Phase. WRITE);
}

Public void handleMessage (SoapMessage message) throws Fault {
//SoapHeader section to add node
QName QName=new QName (" AuthorizationSoapHeader ");

Document doc=DOMUtils. CreateDocument ();
//validate user name
Element id=doc. The createElement method (" userName ");
Id. SetTextContent (" zhou ");
//verify password
Element PWD=doc. The createElement method (" password ");
The PWD. SetTextContent (" 123456 ");
//verify password
Element company=doc. The createElement method (" company ");
Company. SetTextContent (" 880 ");

Element root=doc. CreateElementNS (" http://tempuri.org/", "SoapHeaderMD");
Root. The appendChild (id);
Root. The appendChild (PWD);
Root. The appendChild (company);
//create SoapHeader content
SoapHeader header=new SoapHeader (qName, root);
//add SoapHeader content
List
Headers=message. GetHeaders ();
Headers. The add (header);
}
}

The following is my client
 
Public static void main (String [] args) {
String service_url="HTTP://http://192.168.9.91:8012/BaanWebService/StdJournalVoucher.asmx? WSDL ";
Long st=(new Date ()). The getTime ();
QName SERVICE_NAME=new QName (" http://tempuri.org/", "StdJournalVoucher");
URL the URL=null;
Try {
Url=new url (service_url);
} the catch (MalformedURLException e) {
e.printStackTrace();
}
StdJournalVoucher service=new StdJournalVoucher (url, SERVICE_NAME);
StdJournalVoucherSoap lnService=(StdJournalVoucherSoap) service. GetPort (StdJournalVoucherSoap. Class);
String json="[{ttyp: 'F02 leac:' 66020103 ', dim1: '880', DBCR: '1', amth: '10000.25', user: '55135'}]".
System. The out. Println (json);
The Client Client=ClientProxy. GetClient (lnService);
Client. GetOutInterceptors (). The add (new AddSoapHeader ());

String reponseText=lnService. IJournalVoucher (json);

System. The out. Println (reponseText);

Long et=(new Date ()). The getTime ();
System. Out.println ("... Use time="+ (et - st));
}

My problem is I by the client. GetOutInterceptors (). The add (new AddSoapHeader ()); Add the Header information to the client interface communication, but the server can't receive my Header information, could you tell me how can I put my package Header information to the server, thank you! Please advice a lot

CodePudding user response:

 client. Invoke 
what is the function of this method? Parameter is what meaning?

CodePudding user response:

Plus, to solve!

CodePudding user response:

The client reference: the server reference page2
https://www.javatips.net/blog/how-to-add-http-headers-to-a-soap-request-using-cxf? Page=3

CodePudding user response:

I and your code is almost the same, but I could not get the headers! Inquire of ~ ~

CodePudding user response:

Upstairs solved?????

CodePudding user response:

Has been solved, need to understand how to deal with a friend, please add my QQ: 358653471
  • Related