Soap Web服务客户端添加多个头元素Apache Axis

时间:2019-11-25 05:59:39

标签: soap axis2

我使用Apache Axis生成Web服务客户端。 我需要在请求中添加多个标头元素。请在下面找到Soap UI请求正文。

cat inputFile.txt|awk 'BEGIN {FS="\t"}; NR>1 {print $4}'|awk '{split($1,a,","); if (max(a)>0.5) print $0}'

能否请您指导我一种方法。预先感谢。

1 个答案:

答案 0 :(得分:0)

您可以从SOAPEnvelope获取SOAPHeader(也可以从MessageContext获取SOAPEnvelope)。

然后,您可以将SOAPHeaderBlock,OMAttribute或子元素添加到SOAPHeader。我不确定您需要哪个。

还有其他重载方法可用于创建上述元素,因此可以随时尝试。下面的示例肯定不是完美的,因为我不必对标题进行许多此类修改,因此我没有经验。但是,我前段时间做了一些操作,因此请以该示例为基础进行更深入的研究。

public void addHeaders(MessageContext msgContext) {
        SOAPEnvelope envelope = msgContext.getEnvelope();
        SOAPHeader header = envelope.getHeader();
        // adding HeaderBlock
        header.addHeaderBlock(new QName("http://some.name.space","localPartName"));
        // adding OMAttribute
        OMAttributeImpl omAttribute = new OMAttributeImpl();
        omAttribute.setAttributeType("type_of_attribute");
        omAttribute.setAttributeValue("some_value");
        omAttribute.setOMNamespace(new OMNamespaceImpl("http://some.uri", "somePrefix"));
        header.addAttribute(omAttribute);
        // add a child created with OMFactory
        OMNamespace omNamespace = new OMNamespaceImpl("http://some.other.uri", "someOtherPrefix");
        OMElement element = OMAbstractFactory.getOMFactory().createOMElement("sth", omNamespace);
        element.addAttribute("attr1", "attr1_Value", omNamespace);
        element.addAttribute("attr2", "attr2_Value", omNamespace);
        header.addChild(element);
    }