I am using WebClient to Post and Receive XML from a UK government service, the Government Gateway. They provide the schemas. In java terms I send and receive a GovTalkMessage which has a standard envelope and then it's Body contains one of many possible classes depending on which service you use on the Gateway. So I've set up a simple client in Spring 3 and it simply comes down to
public GovTalkMessage liveClient(GovTalkMessage body) { return webClient.post(body, GovTalkMessage.class); } But here comes the nasty problem. The protocol requires you to take the Body XML, format it in a certain way with a very specific set of namespace definitions and create a type of Hash of the actual text. This hash is embedded into the Body and used to prove that the message has not been tampered with. We already have this code from our legacy implementation that was built on raw DOM and URLConnection. The XML that the WebClient sends has to look exactly the same so the hash can be compared at the other end. Of course the default XML generated by Jaxb does not look like this XML. *What I need* <GovTalkMessage xmlns:ps1="http://www.w3.org/2000/09/xmldsig#"> <EnvelopeVersion>2.0</EnvelopeVersion> <Header> <MessageDetails> .......... </GovTalkDetails> <Body> <IRenvelope:IRenvelope xmlns:IRenvelope=" http://www.govtalk.gov.uk/taxation/PAYE/MOV/09-10/1"> <IRheader> *Default output* <ns2:GovTalkMessage xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:ns2=" http://www.govtalk.gov.uk/CM/envelope"> <ns2:EnvelopeVersion>2.0</ns2:EnvelopeVersion> <ns2:Header> ... <ns2:Body> <IRenvelope:IRenvelope xmlns:IRenvelope=" http://www.govtalk.gov.uk/taxation/PAYE/MOV/09-10/1" xmlns=" http://www.govtalk.gov.uk/taxation/PAYE/MOV/09-10/1"> <IRheader> <Keys> after a week of experiments and reading I have the following Spring for the client: @Bean public WebClient testClient() { WebClient client = WebClient.create(TEST_URL); //Logging code hidden //Code to eat all the namespaces Map<String, String> outTransformMap = new HashMap<String, String>(); outTransformMap.put("{http://www.w3.org/2000/09/xmldsig#}*", "*"); outTransformMap.put("{ http://www.govtalk.gov.uk/taxation/PAYE/MOV/09-10/1}*", "*"); outTransformMap.put("{http://www.govtalk.gov.uk/CM/envelope}*", "*"); org.apache.cxf.interceptor.transform.TransformOutInterceptor transformOutInterceptor = new org.apache.cxf.interceptor.transform.TransformOutInterceptor(); transformOutInterceptor.setOutTransformElements(outTransformMap); config.getOutInterceptors().add(transformOutInterceptor); return client; } When run this will produce xml with all namespaces stripped out which is good start. <GovTalkMessage> <EnvelopeVersion>2.0</EnvelopeVersion> <Header> ...... <Body> <IRenvelope/> I have two requirements *1 I need to add the namespace declations back with a very specific look as shown by my sample.* My XSL knowledge is very limited and I have tried a few things using XSLTJaxbProvider with no success. I have tried using JAXBElementProvider and it's namespacePrefixes methods with no useful result. There are also 7 types of data to put into the Body depending on what we send to the Gateway. All of them have a top level class called IRenvelope but obviously have different namespaces. *2 Write Dom code to extract the Body section to send off to the hashing algorithm and then use Dom methods to insert the generated hash into the right place.* I've written a skeleton Interceptor but am finding it very hard to know where to go with this as the code is so vast and there are so many options. In summary I'm just not sure how to do these things. There are so many options but none of them quite does what I want and I find the code pretty hard to get into. In some ways I'm a victim of the power of CXF (that's a complement). Please can you help me with getting started on these nasty tasks. For reference this code is for a payroll company submitting data for the RTI<http://www.hmrc.gov.uk/softwaredevelopers/rti/index.htm>project to the UK HMRC on the Government Gateway <http://www.hmrc.gov.uk/softwaredevelopers/govgateway/index.htm>. The hashing code is called IRmark<http://www.hmrc.gov.uk/softwaredevelopers/hmrcmark/index.htm> . Many thanks in advance Gareth Hughes