Java 2EE and XML Development

Скачать в pdf «Java 2EE and XML Development»


AttachmentPart ap


= (AttachmentPart) attachmentIterator.next();


// match attachment’s content id to the // id specified above


if (mimeContentId.equals(ap.getContentId())) {


}


}


Listing 4.5 contains the full source code for the JAXM servlet that accepts inbound SOAP messages.


Listing 4.5 A JAXM servlet for inbound SOAP messaging


import javax.xml.messaging.*;


import javax.xml.soap.*;


import javax.activation.DataHandler;


import org.jdom.*;    jAXM js bum on


import java.io.*;    top of JDOM


import java.util.*;


/**


*    A JAXM servlet that receives asynchronous


*    image updates for products from a supplier.


Handles image o ate


*/


public class ImageUpdateServlet extends JAXMServlet { public SOAPMessage onMessage(SOAPMessage message) {


try {


Element productIdElem =    Gets the SOAp b|°ck


message.getSOAPPart()    c°ntajnjng the


.getSOAPEnvelope()    pduct ID


.getSOAPBody()


.getChild(«productImage»,


Namespace


.getNamespace(«myco»,


«http://schemas.mycompany.com/Product-Images«));


// get the product ID corresponding to // the image file


String productId


= productIdElem.getAttributeValue(«id»);


// get the image type String imageType


= productIdElem.getAttributeValue(«type»);


// get the attachment’s MIME id


String mimeContentId


= productIdElem.getChild(«imageData») .getAttributeValue(«href»);


// go get the attached image data Iterator attachmentIterator = message.getAttachments();


// iterate the attachments — should only be one while (attachmentIterator.hasNext()) { AttachmentPart ap


= (AttachmentPart) attachmentIterator.next();


// match attachment’s content id to the // id specified above


if (mimeContentId.equals(ap.getContentId())) {


// obtain a data handler for the type of content // see javax.activation.DataHandler for details DataHandler dh = ap.getDataHandler();

Скачать в pdf «Java 2EE and XML Development»