Comments inline…..

> On Mar 6, 2019, at 2:30 AM, Varun Singhal <varunsingha...@live.com> wrote:
> 
> Solution : 
> Examine the request, if "<wsa:MessageID>" is absent add it in the headers !
> 
> Solution Implementation : 
> Add 2 interceptors to the IN interceptor chain.
> First intereptor detects if a  "<wsa:MessageID>"  header is absent, if absent 
> then it adds a "transformInterceptor" in the interceptor chain to append a 
> bogus "<wsa:MessageID>" header
> 
> Solution Code (Also attached):
> Here is the code for first interceptor/MessageIdDetector 
> 
> public class MessageIdDetector extends AbstractSoapInterceptor {
> 
>   private static final String CXF_TRANSFORM_MESSAGE_ID_ELEMENT_KEY =
>       "{http://schemas.xmlsoap.org/soap/envelope/ 
> <http://schemas.xmlsoap.org/soap/envelope/>}Header/";
>   private static final String CXF_TRANSFORM_MESSAGE_ID_ELEMENT_VALUE =
>       "{http://schemas.xmlsoap.org/ws/2004/08/addressing 
> <http://schemas.xmlsoap.org/ws/2004/08/addressing>}MessageID=http://www.w3.org/2005/08/addressing/unspecified
>  <http://www.w3.org/2005/08/addressing/unspecified>";
> 
>   
>   public MessageIdDetector() {
>     super(Phase.READ);
>     addAfter(ReadHeadersInterceptor.class.getName());
>   }
> 
>   @Override
>   public void handleMessage(SoapMessage message) throws Fault {
>     QName messageIdQname = new 
> QName("http://schemas.xmlsoap.org/ws/2004/08/addressing 
> <http://schemas.xmlsoap.org/ws/2004/08/addressing>", "MessageID");
>     boolean isMessageIDheaderPresent = message.hasHeader(messageIdQname);
>     if (!isMessageIDheaderPresent) {
>       addMessageIdTransformInInterceptor(message);
>     }
>   }
> 


This part is perfect.   It would detect the presence of the messageID header 
and, if not present, does something….


>   /**
>    * Adds a transform interceptor to the chain in order to transform the 
> message
>    * 
>    * @param message
>    */
>   private void addMessageIdTransformInInterceptor(Message message) {
>     TransformInInterceptor transformInterceptor = new 
> TransformInInterceptor(Phase.PRE_PROTOCOL);
>     Map<String, String> inAppendMap = new HashMap<>();
>     // this map contains the messageID element that we want to append to 
> message
>     inAppendMap.put(CXF_TRANSFORM_MESSAGE_ID_ELEMENT_KEY, 
> CXF_TRANSFORM_MESSAGE_ID_ELEMENT_VALUE);
>     transformInterceptor.setInAppendElements(inAppendMap);
>     transformInterceptor.addBefore(SAAJInInterceptor.class.getName());
>     // add the interceptor to the current chain
>     message.getInterceptorChain()
>         .add(transformInterceptor);
>   }
>   
> }

This is where you are doing a bunch of stuff that isn’t necessary.    Instead 
of adding a second interceptor, create a new DOM element with your “fake” 
MessageID, wrapper it with a org.apache.cxf.headers.Header object, and just add 
it to the list of headers.   So something like:

Document doc =  org.apache.cxf.helpers.DOMUtils.getEmptyDocument();
Element el = doc.createElementNS(Names.WSA_NAMESPACE_NAME, “wsa:MessageID”);
el.appendChild(doc.createTextNode(newId);
Header header = new Header(Names.WSA_MESSAGEID_QNAME, el);
soapMessage.getHeaders().add(header);

That should be all that is necessary.   That gets the message ID into the list 
of headers that MAPCodec will process.     You would need to use the right 
namespaces and such to match the other addressing headers and such, but that 
should give you an idea how to handle it.



-- 
Daniel Kulp
dk...@apache.org <mailto:dk...@apache.org> - http://dankulp.com/blog 
<http://dankulp.com/blog>
Talend Community Coder - http://talend.com <http://coders.talend.com/>

Reply via email to