繁体   English   中英

使用Axis 2将自定义标头发送到SOAP Web服务

[英]sending custom header to SOAP web service with Axis 2

我必须通过标头发送令牌。 这是我正在尝试的代码。

            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);

我在响应中收到NullpoinException。

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

如何解决这个问题? 除此之外,我需要指定POST / GET

这是发送自定义标头的代码段。

            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);

在此之前,我一直在将其他信息(例如Content-type)发送到客户标头。 但是,如果要发送它们,则可以使用API​​方法作为示例,

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");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM