newday
newday

Reputation: 3878

sending custom header to SOAP web service with Axis 2

I have to send the tokens through header. This is the code I am trying.

            ServiceClient _serviceClient = new ServiceClient();
            SOAPHeaderBlock header = new SOAP11HeaderBlockImpl();

            header.addAttribute("Content-Type", "text/xml; charset=utf-8", null);
            header.addAttribute("LocationToken", "vdsadfafdasfsdas==", null);
            header.addAttribute("AccessToken", "zxfadfasfasdfasdfsadf", null);
            header.addAttribute("Content-Length", String.valueOf(input), null);
            header.addAttribute("SOAPAction","http://example.com/CalculateOrder",null);
            _serviceClient.addHeader(header);
            owesbservice._setServiceClient(_serviceClient);

I get NullpoinException in the response.

            CalculateOrderResponseDocument responseDoc = null;
            responseDoc = owesbservice.calculateOrder(calculateOrder8);

How to fix this? Apart from this I need to specifiy POST/GET

Upvotes: 1

Views: 2608

Answers (1)

newday
newday

Reputation: 3878

Here is code snipt that send the custom header.

            Map<String, String> property = new HashMap<>();
            property.put("LocationToken", "vbdffdssgsdf==");
            property.put("AccessToken", "fgfsdfsdfddfdfdf==");

            options.setProperty( org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS , property);

Before that, I have been sending other information such Content-type to customer header. But If you want to send them, you can use API methods as an example,

options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING ,"UTF-8");
            options.setProperty(org.apache.axis2.transport.http.HTTPConstants.HEADER_CONTENT_TYPE, "text/xml");

Upvotes: 1

Related Questions