I created client Java objects using JAX-WS RI. I am trying to make a SOAP request to a web service. The service requires authentication in the header, which looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <xsd:authHeader> <xsd:user> username@gmail.com </xsd:user> <xsd:password>password1</xsd:password> </xsd:authHeader> </soapenv:Header> <soapenv:Body> <ns:searchAssetsParam> <ns:includeSubfolders>true</ns:includeSubfolders> <ns:resultsPage>2</ns:resultsPage> </ns:searchAssetsParam> </soapenv:Body> </soapenv:Envelope>
Generated Java objects have methods for calling a service, creating objects, and constructing a header. But when making a call, I am having problems setting the header.
Here is the code I'm using:
IpsApiService service = new IpsApiService(); IpsApiPortType port = service.getIpsApiSoapPort(); SearchAssetsParam searchAssetsParam = buildSearchAssetsParam(); SearchAssetsReturn response = port.searchAssets(searchAssetsParam);
buildSearchAssetsParam () creates a query object. I created the header object as follows:
AuthHeader header = new AuthHeader(); header.setUser(" username@gmail.com "); header.setPassword("password1");
How to configure this AuthHeader to request a service?
Thanks Venu
source share