JAX-WS - Adding SOAP Headers

后端 未结 10 2262
鱼传尺愫
鱼传尺愫 2020-12-05 02:11

I am trying to create a standalone client to consume some web services. I must add my username and password to the SOAP Header. I tried adding the credentials as follows:

10条回答
  •  臣服心动
    2020-12-05 02:50

    I struggled with all the answers here, starting with Pascal's solution, which is getting harder with the Java compiler not binding against rt.jar by default any more (and using internal classes makes it specific to that runtime implementation).

    The answer from edubriguenti brought me close. The way the handler is hooked up in the final bit of code didn't work for me, though - it was never called.

    I ended up using a variation of his handler class, but wired it into the javax.xml.ws.Service instance like this:

    Service service = Service.create(url, qname); service.setHandlerResolver( portInfo -> Collections.singletonList(new SOAPHeaderHandler(handlerArgs)) );

提交回复
热议问题