0
votes
  • We exposed an Apache camel-cxf webservice. Using camel processor we are trying to get the soap header that we passed in the soap request from the soapUi client.
  • The exchange object contains the body of soap message(not soap header). In the exchange.getIn.getHeader() we are only getting the HTTP Headers we passed, not the SOAP Header.

  • How to retrieve the SOAP header from exchange obeject in Camel ?

  • Following are the soap header passed:

<soapenv:Header>
  <ns1:info xmlns:ns1="http://www.w3schools.com/transaction/">
    <ns1:TransactionID>01</ns1:TransactionID>
    <ns1:AppUserID>52</ns1:AppUserID>
    <ns1:AppPass>ab</ns1:AppPass>
  </ns1:info>
</soapenv:Header>
  • We tried using,

    • exchange.getIn().getHeaders();
    • exchange.getIn().getHeader(“TransactionID”);

      However it was not able to extract the SOAP header which was sent.

  • How to add custom soap headers in Payload mode ?
2

2 Answers

0
votes

If cxf endpoint configured to working in DataFormat.PAYLOAD so:

 .process(exchange -> {
                CxfPayload body = exchange.getIn().getBody(CxfPayload.class);
                for (Object header : body.getHeaders()) {
                    SoapHeader soapHeader = (SoapHeader) header;
                    org.w3c.dom.Element element = (Element) soapHeader.getObject();
                    //parse elements
                }
            });

If in raw mode, just read input stream and parsing data as xml using xpath

UPD:

Example route:

CxfEndpoint endpoint = new CxfEndpoint();
    endpoint.setDataFormat(DataFormat.PAYLOAD);
    endpoint.setWsdlURL("etc/Proxy.wsdl");
    endpoint.setAddress("http://localhost:8089/wsservice/");
    getContext().getRegistry().bind("cxfend", endpoint);
    from("cxf:bean:cxfend")
            .process(exchange -> {
                CxfPayload body = exchange.getIn().getBody(CxfPayload.class);
                for (Object header : body.getHeaders()) {
                    SoapHeader soapHeader = (SoapHeader) header;
                    org.w3c.dom.Element element = (Element) soapHeader.getObject();
                    Element transactionID = (Element) element.getElementsByTagName("ns1:TransactionID").item(0);
                    log.info("Header TransactionID with value:{}", transactionID.getTextContent());
                }
            });

Output:

2020-03-03 11:43:03,327 [main           ] INFO  Server                             
- jetty-9.4.21.v20190926; built: 2019-09-26T16:41:09.154Z; git:     
72970db61a2904371e1218a95a3bef5d79788c33; jvm 1.8.0_232-b18
2020-03-03 11:43:03,377 [main           ] INFO  AbstractConnector              
- Started ServerConnector@b016b4e{HTTP/1.1,[http/1.1]}{localhost:8089}
2020-03-03 11:43:03,377 [main           ] INFO  Server                         
- Started @3403ms
2020-03-03 11:43:03,400 [main           ] INFO  ContextHandler                 
- Started o.e.j.s.h.ContextHandler@1b15f922{/wsservice,null,AVAILABLE}
2020-03-03 11:43:03,400 [main           ] INFO  DefaultCamelContext            
- Route: route1 started and consuming from: cxf://bean:cxfend
2020-03-03 11:43:03,406 [main           ] INFO  DefaultCamelContext            
- Total 1 routes, of which 1 are started
2020-03-03 11:43:03,408 [main           ] INFO  DefaultCamelContext            
- Apache Camel 3.0.1 (CamelContext: camel-1) started in 1.953 seconds
2020-03-03 11:43:10,068 [tp1299661385-22] INFO  TypeUtil                       
- JVM Runtime does not support Modules
2020-03-03 11:43:10,196 [tp1299661385-22] INFO  RouteTest                      
- Header TransactionID with value:01
-1
votes

That was my solution:

    List<SoapHeader> soapHeaders = (List)exchange.getIn().getHeader("org.apache.cxf.headers.Header.list");
    Element header = ((Element)soapHeaders.get(0).getObject());
    String eventType = (String)header.getElementsByTagName("TransactionID").item(0).getTextContent();
    exchange.getIn().setHeader("TYPE_EVENT",eventType);