Search code examples
javaweb-servicessoapjax-wshandler

correlation between inbount and outbound xml in soap handler


I am using org.apache.cxf:cxf-codegen-plugin to create web services from my wsdl files. For these services, i wrote a simple SOAPHandler< SOAPMessageContext > to log inbound and outbound xml.

Here i can check that xml is outbound or inbound:

(Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

But there is a problem about correlation between them. How do i know that any inbound xml is corresponding to the any outbound xml? What is the best way to check that? For example, is there a way to do it in MessageContext modification?

Thanks in advance.


Solution

  • Since SOAPMessageContext is also a Map<String,Object> you could add a correlatio Id on the inbound side:

    String correlationID;
    
    if (!Boolean.TRUE.equals(messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))){
      correlationID=System.currentTimeMillis(); // Better use somtehing more unique
      messageContext.put("INBOUND_ID",correlationID);
    }else{
      correlationID= messageContext.get("INBOUND_ID",correlationID);
    }