/* * $Id: ReceivingServlet.java */ package JAXMInvoicing.customer; import javax.xml.messaging.*; import javax.xml.soap.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import javax.xml.parsers.*; import javax.xml.transform.dom.*; import org.w3c.dom.*; import javax.naming.*; import javax.activation.DataHandler; import java.util.*; import java.net.*; public class ReceivingServlet extends JAXMServlet implements ReqRespListener { private final String attachmentRef = "href"; static MessageFactory fac = null; static { try { fac = MessageFactory.newInstance(); } catch (Exception ex) { ex.printStackTrace(); } }; public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); } /** Searches and returns the first node if finds in the inputted DOM tree for an element with an attribute called href. It performs depth first search @param root the inputted DOM representation of the SOAPMessage body @return returns null if no element with a href attribute is found otherwise it returns a reference to the first matching element found **/ public org.w3c.dom.Node findAttachmentNode(org.w3c.dom.Node root){ //This is the entirenode org.w3c.dom.Node attachmentNode = null; //If the element has attributes check if it has a href attribute //if it does then return root as the node which has the href attribute if(root.hasAttributes()){ NamedNodeMap elementAttrs = root.getAttributes(); org.w3c.dom.Node attributeNode = elementAttrs.getNamedItem(attachmentRef); if(attributeNode != null){ System.out.println("href found for element"+root.getNodeName()); return root; } } //Check if root has any children if not return null; if(!(root.hasChildNodes())) return null; //If root has children, and no href is found continue searching root's children NodeList childNodes = root.getChildNodes(); int noChildren = childNodes.getLength(); for (int i = 0; i