Java JAX-WS Web Service calls Axis2 client, how do I add custom http request header?

162 Views Asked by At

I am using java 1.4 . axis2 version is 1.5.6 . What I want to do is to add username and password to htt_request_header while sending data to web service developed with JAX-WS RI 2.2.9.

I want to add two items in Headers tab in SOAP screenshot.

1

There are 1 best solutions below

0
fxbank On

The problem's been solved. Since the wsdl address was created as https, it was fixed as http in the stub file and the header was added with the following method.

ServiceClient serviceClient = stub._getServiceClient(); List headers = (List) serviceClient.getOptions().getProperty(HTTPConstants.HTTP_HEADERS);
if (headers == null){
headers = new ArrayList(); } headers.add(new Header("username", username)); headers.add(new Header("password", password)); serviceClient.getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headers);