You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by hnt <ng...@gmail.com> on 2016/09/28 09:04:54 UTC

Add Header in CXF response

Hi,

I would like to add a customer header in CXF response.

In fact, at server, i use an OutInterceptor and i can see a "transactionID"
header in soap response message .

public RLECompressionOutInterceptor() {
    super(Phase.PRE_LOGICAL);}@Overridepublic void
handleMessage(SoapMessage paramT) throws Fault {
    // TODO Auto-generated method stub
    List<Header> head = new ArrayList<Header>();

    head.addAll(paramT.getHeaders());
    for (Iterator<Header> i = head.iterator(); i.hasNext();) {
        Header h = i.next();
        Element n = (Element) h.getObject();
        if (n.getLocalName().equals("transactionID")) {
            String transactionID = n.getTextContent();
            //transactionID is information of a "transactionID" header
        }
    }}

However, at Client, in InInterceptor, the header in the response message is
NULL.

public CompressingInInterceptor() {
    super(Phase.PRE_LOGICAL);}
@Overridepublic void handleMessage(SoapMessage arg0) throws Fault {
    List<Header> head = new ArrayList<Header>();
    head.addAll(arg0.getHeaders());
    for (Iterator<Header> i = head.iterator(); i.hasNext();) {
        Header h = i.next();
        Element n = (Element) h.getObject();
        if (n.getLocalName().equals("transactionID")) {
            transactionID = n.getTextContent();
            System.out.println("ID: "+transactionID);
        }
    }}

I do not know why the header is null in this case ? How to correct it,
please ?

Thanks,