How can I add namespace decalarations in SOAP Envelope

最后都变了- 提交于 2019-12-01 18:49:10

After digging on cxf forums, I found the answer.

Map<String, String> nsMap = new HashMap<>();

nsMap.put("prefix1", "url1");
nsMap.put("prefix2", "url2");
nsMap.put("prefix3", "url3");
nsMap.put("prefix4", "url4");
nsMap.put("prefix5", "http://www.w3.org/2001/04/xmlenc#");

Client client = ClientProxy.getClient(port);   
client.getRequestContext().put("soap.env.ns.map", nsMap);

I would be appreciated if anyone know on how to do the same for <soap:Header>

You can add headers like this:

UserCredentials authHeader = new UserCredentials();
    authHeader.setUsername(username);
    authHeader.setPassword(password);
    ArrayList<Header> headers = new ArrayList<Header>(1);
    try {
        Header soapHeader = new Header(new QName(TQIntegrationV2.TQIntegrationV2Soap.getNamespaceURI(), "UserCredentials"), authHeader, new JAXBDataBinding(UserCredentials.class));
        headers.add(soapHeader);
    } catch (JAXBException ex) {
        LOGGER.error("Exception trying to serialize header: {}", ex);
    }
    client.getRequestContext().put(Header.HEADER_LIST, headers);

you can leave setUsername/setPassword if you dont want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!