Apache CXF Header 转换 %gt;到 > 在有效载荷中

Apache CXF Header transform %gt; to > in payload

我需要将此 headers 设置为 XML 负载:

    <soap:Header>
      <wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">uuid:C112C31F-04056-4567-T554-02A7CUAI01E1</wsa:MessageID>
      <wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">urn:es:request</wsa:Action>
      <Context xmlns="urn:es:context"><parameter></parameter></Context>
    </soap:Header>

通过这次调用:

ClientProxy.getClient(data)
           .getRequestContext()
                 .put(Header.HEADER_LIST,soapHeaders.getHeaders());

SoapHeader class:

public class SoapHeaders {

    private static final String NAMESPACE_URI   = "http://www.w3.org/2005/08/addressing";
    private static final String PREFIX  = "wsa";
    private static final String MESSAGE_LOCAL_NAME      = "MessageID";
    private static final String ACTION_LOCAL_NAME      = "Action";

    
    public List<Header> getHeaders() {
        try {
           List<Header> soapHeaders = new ArrayList<Header>();
           Header messageHeader = new Header(new QName(NAMESPACE_URI, MESSAGE_LOCAL_NAME, PREFIX), "uuid:C112C31F-04056-4567-T554-02A7CUAI01E1", new JAXBDataBinding(String.class));
           Header actionHeader = new Header(new QName(NAMESPACE_URI, ACTION_LOCAL_NAME, PREFIX), urn, new JAXBDataBinding(String.class));
           Header contextHeader = new Header(new QName("urn:es:context", "Context"), "<parameter></parameter>", new JAXBDataBinding(String.class));     
           soapHeaders.add(messageHeader);
           soapHeaders.add(actionHeader);   
           soapHeaders.add(contextHeader);      
           return soapHeaders;
        }catch (JAXBException ex) {
            ex.printStackTrace();
        }
    }
}

但是这一行是我遇到问题的地方:

Header contextHeader = new Header(new QName("urn:es:context", "Context"), "<parameter></parameter>", new JAXBDataBinding(String.class));        

因为发送为:

 <Context xmlns="urn:es:context">&lt;parameter&gt;&lt;/parameter&gt;</Context>

我需要“<、>、

有什么想法可以转换为 xml 标签吗?

提前致谢。

任何可以帮助解决问题的人:

我添加了 child:

           SOAPFactory sf = SOAPFactory.newInstance();
           SOAPElement contextElement = sf.createElement(new QName("urn:es:context", "Context"));
           SOAPElement paramElement = sf.createElement("parameter");
           contextElement.addChildElement(paramElement);
           Header  contextHeader = new Header (new QName("urn:es:context", "Context"), contextElement);         

所以最后的代码是:

public class SoapHeaders {

    private static final String NAMESPACE_URI   = "http://www.w3.org/2005/08/addressing";
    private static final String PREFIX  = "wsa";
    private static final String MESSAGE_LOCAL_NAME      = "MessageID";
    private static final String ACTION_LOCAL_NAME      = "Action";

    
    public List<Header> getHeaders() {
        try {
           List<Header> soapHeaders = new ArrayList<Header>();
           Header messageHeader = new Header(new QName(NAMESPACE_URI, MESSAGE_LOCAL_NAME, PREFIX), "uuid:C112C31F-04056-4567-T554-02A7CUAI01E1", new JAXBDataBinding(String.class));
           Header actionHeader = new Header(new QName(NAMESPACE_URI, ACTION_LOCAL_NAME, PREFIX), urn, new JAXBDataBinding(String.class));         
           SOAPFactory sf = SOAPFactory.newInstance();
           SOAPElement contextElement = sf.createElement(new QName("urn:es:context", "Context"));
           SOAPElement paramElement = sf.createElement("parameter");
           contextElement.addChildElement(paramElement);
           Header  contextHeader = new Header (new QName("urn:es:context", "Context"), contextElement);         
           soapHeaders.add(messageHeader);
           soapHeaders.add(actionHeader);   
           soapHeaders.add(contextHeader);      
           return soapHeaders;
        }catch (JAXBException ex) {
            ex.printStackTrace();
        }
    }
}