Use axis to invoke WebService that require authentication

Source: Internet
Author: User
Tags soap

See my other blog post for a way to call WebService using axis Java calls WebService's method summary , where it only uses axis authentication.

1, verification information through the request packet header delivery

  The situation I encountered is that access to WebService requires Windows authentication by encrypting the user name and password information after the message is sent by adding "Authorization" request messages, so the Java code is implemented as follows:

/** Create New Service and call objects. These is the standard* Jax-RPC objects that is used to store metadata on the service* to invoke.*/Service Service=NewService (); Call Call=(call) Service.createcall ();
Hashtable<String,String> headers = (hashtable<string,string>) Call.getproperty (httpconstants.request_headers); if(Headers = =NULL) {headers=NewHashtable<string, string>(); Call.setproperty (Httpconstants.request_headers, HEADERS); } /*Put your header into the headers Hashtable*/Headers.put ("Authorization", "Basic mdmwndexmtuwojeymzq1ng==");

Listen for HTTP requests to see the following headers:

post/sap/bc/srt/rfc/sap/zwf_xmas//service http/1.0Content-type:text/xml; charset=utf-8accept:application/soap+xml, Application/dime, multipart/related, text/* user-agent:axis/1.4host:hdeccd.evergrande.com:8000cache-control:no-cachepragma:no-cachesoapaction: "" content-length:573authorization:basic mdmwndexmtuwojeymzq1ng== 

Reference: Http://www.jroller.com/cwap/entry/setting_http_headers_in_axis1

2. Verification information is written to the SOAP message


Java code:

Try  {                = "";                New Soapheaderelement (namespace, "Authentication");                Header.setprefix ("");                Header.addchildelement ("Username"). Addtextnode ("030411150");                Header.addchildelement ("Password"). Addtextnode ("123456");                Call.addheader (header);             Catch (SoapException E1) {                e1.printstacktrace ();            }

Listening for HTTP requests can see the following message information:

<?XML version= "1.0" encoding= "UTF-8"?>

<Soapenv:envelopexmlns:soapenv= "http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance">
<Soapenv:header>
    < authentication soapenv:actor = "Http://schemas.xmlsoap.org/soap/actor/next" Soapenv:mustunderstand = "0" xmlns = " >
< username > 030411150</ Span style= "color: #800000;" >username >
< password > 123456</ password >
</ authentication >
</Soapenv:header>
<Soapenv:body>
<ns1:zdefmwfmovegetbusinesstableSoapenv:encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/"xmlns:ns1= "Urn:sap-com:document:sap:soap:functions:mc-style">
<ItabnoXsi:type= "Xsd:string">1</Itabno>
<IwfnumXsi:type= "Xsd:string">1</Iwfnum>
<iwiidXsi:type= "Xsd:string">1</iwiid>
</ns1:zdefmwfmovegetbusinesstable>
</Soapenv:body>
</Soapenv:envelope>

Reference: http://shenxueliang.iteye.com/blog/1734414

  

Use axis to invoke WebService that require authentication

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.