/* * Copyright 2 1 by Sun Microsystems, Inc., * 9 1 San Antonio Road, Palo Alto, California, 943 3, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of Sun Microsystems, Inc. ("Confidential Information" . You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Sun. */ package com.sun.xml.messaging.examples; import javax.xml.messaging.*; import javax.xml.soap.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.activation.DataHandler; import java.io.InputStream; import java.io.IOException; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.SAXException; public class MyListener extends JAXMServlet { Connection connection; public void init(Connection connection) { this.connection = connection; } public void destroy() { } public void onMessage(Message message) { System.out.println(" onMessage of MyListener invoked"); try { //Get the first part which is the SOAPPart. SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getSOAPEnvelope(); DOMSource domSrc = (DOMSource) soapEnvelope.getContentAs(DOMSource.FEATURE); //Now use the dom tree to actually get traverse //and get some of the fields from it. Node node = domSrc.getNode(); //Now start manipulating the attachments int count = message.countAttachments(); System.out.println("No. of attachments " + count); AttachmentPart ap = null; for(int i = ; i < count; i++) { ap = message.getAttachmentPart(i) ; if(ap.getDataHandler().getContentType().equals("text/xml")) { StreamSource streamSource = (StreamSource) ap.getContent(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(streamSource.getInputStream()); } } } catch(JAXMException jxe { jxe.printStackTrace(); } catch(IOException ioe { ioe.printStackTrace(); } catch(ParserConfigurationException pce { pce.printStackTrace(); } catch(SAXException se { se.printStackTrace(); } catch(SOAPException spe { spe.printStackTrace(); } } }