How do you add a Soap Header defined in a wsdl to a web service client in CXF?

后端 未结 4 1796
自闭症患者
自闭症患者 2020-12-11 10:55

I have a wsdl that defines a soap header that needs to be passed when calling the web service.

The sample SOAP Header is:


   &         


        
4条回答
  •  长情又很酷
    2020-12-11 11:36

    Found myself in same situation: wsdl2java generated the header class, and I needed to add it as a SOAP header to the outgoing SOAP request.

    My solution in code was as follows (reusing original question's AuthenticationInfo as the header class name):

    import org.apache.cxf.frontend.ClientProxy;
    import org.apache.cxf.headers.Header;
    
    AuthenticationInfo ai = new AuthenticationInfo();
    ai.setUserName("User");
    ai.setPassword("");
    
    List
    soapHeaders = new ArrayList
    (); Header h1 = new Header(new QName("http://namespace/of/AuthenticationInfo", "AuthenticationInfo"), ai, new JAXBDataBinding(AuthenticationInfo.class)); soapHeaders.add(h1); ClientProxy.getClient(port).getRequestContext().put(Header.HEADER_LIST, soapHeaders);

提交回复
热议问题