How to properly format a SOAP message envelope using a custom SOAPHandler

后端 未结 3 665
花落未央
花落未央 2021-02-06 14:31

I have a class that implements the SOAPHandler interface. The handleMessage is defined as:

public boolean handleMessage(SOAPMessageContext context) {

  SOAPMes         


        
3条回答
  •  [愿得一人]
    2021-02-06 14:58

    There's enough problems in this code that I'm thinking it's a troll, but heres a start:

    The line :

    element = envelope.addHeader().addChildElement(qname);
    

    should read:

    SOAPHeaderElement secHdrElement = envelope.addHeader().addHeaderElement(qname);
    

    next, instead of:

    qname = envelope.createName("mustUnderstand");
    element.addAttribute(qname, "1");
    

    probably:

    secHdrElement.setMustUnderstand(true);
    

    and

    qname = envelope.createName("UsernameToken", "sse", "http://example.com/user.xsd");
    element = envelope.getHeader().addHeaderElement(qname);
    element.addTextNode("user1");
    

    should be something like:

    qname = envelope.createName("UsernameToken", "sse", "http://example.com/user.xsd");
    element = secHdrElement.addHeaderElement(
              envelope.createName("UsernameToken", "sse", "http://example.com/user.xsd"));
    

    and so on...

提交回复
热议问题