JAXRPC Handler to modify incoming SOAP
shin.tai Dec 11, 2005 4:37 PMHi all,
Has anyone out there managed to successfully use a JAXRPC handler to modify an incoming SOAP message?
My incoming SOAP message does not have the xsi type attribute (dodgy client?) so I'm writing a handler to insert it for me if it's not present.
I've had numerous problems already and I've copied over fixes from JBWS-464
http://jira.jboss.org/jira/browse/JBWS-464.
Spefically I've patched my JBoss to use
src/main/org/jboss/axis/Attic/MessagePart.java 1.1.2.4
src/main/org/jboss/axis/message/Attic/SOAPElementAxisImpl.java 1.1.2.8
src/main/org/jboss/axis/message/Attic/SOAPElementAxisImpl.java 1.1.2.8
But not JavaProvider.java rev 1.1.2.3 because the changes got reverted soon after
And here's the handler code I'm using:
public boolean handleRequest(MessageContext msgContext) { SOAPMessageContext smc = (SOAPMessageContext)msgContext; SOAPMessage msg = smc.getMessage(); try { SOAPBody sb = msg.getSOAPBody(); NodeList list = sb.getElementsByTagName("multipart"); if (list == null || list.getLength() == 0) return true; else { for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); String ns = "http://www.w3.org/2001/XMLSchema-instance"; NamedNodeMap attributes = node.getAttributes(); if (attributes == null) continue; Node type = attributes.getNamedItem("type"); if (type == null) { Document doc = list.item(i).getOwnerDocument(); Attr attr = doc.createAttribute("xsi:type"); attr.setValue("n1:Array"); Node nn = attr.cloneNode(false); Node n = attributes.setNamedItem(nn); } } } } catch (SOAPException e) { e.printStackTrace(); } return true; }
I can see my attribute being added to the NamedNodeMap object (and the NamedNodeMap is live in the DOM so any changes should be reflected) but if I do a subsequent check on the SOAP message. My changes are not there. For brevity I haven't included above the code to check the SOAP message but here it is below:
// Create transformer try { TransformerFactory tff = TransformerFactory.newInstance(); Transformer tf = tff.newTransformer(); // Get reply content Source sc = msg.getSOAPPart().getContent(); // Set output transformation StreamResult result = new StreamResult(System.out); tf.transform(sc, result); System.out.println(); } catch (Exception e) { throw new JAXRPCException(e); }
Thanks,
Shin