/* * @(#)PurchaseConfirmer.java * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms * */ package com.sun.bookprovider.async; import javax.xml.messaging.*; import javax.xml.soap.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.net.*; import java.util.Enumeration; import com.sun.xml.messaging.jaxm.ebxml.*; import javax.activation.*; /** * PurchaseConfirmer.java follows JAXM Asynchronous invocation model. * This class gets an asynchronous confirmation message to confirm * book purchase. * It sends an asynchronous message back to the origin * @author Bhakti Mehta and Ramesh Mandava * */ public class PurchaseConfirmer extends JAXMServlet implements OnewayListener { private ProviderConnectionFactory pcf; private ProviderConnection pc; private MessageFactory mf; String from = "http://localhost:8080/funbooks/bookordering"; String to = "http://www.employeeportal.com/bookordering"; public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); try { pcf = ProviderConnectionFactory.newInstance(); pc = pcf.createConnection(); ProviderMetaData metaData = pc.getMetaData(); mf = pc.createMessageFactory("ebxml"); setMessageFactory(mf); }catch (Exception e) { e.printStackTrace(); } } public void onMessage(SOAPMessage message) { System.out.println("Asynchronous On message call in receiving servlet"); try { System.out.println("Here's the message: "); message.saveChanges(); message.writeTo(System.out); System.out.println("Sending an asynchronous message to origin "); EbXMLMessageImpl ebxmlMsg = (EbXMLMessageImpl)message; Party from = ebxmlMsg.getSender(); Party to = ebxmlMsg.getReceiver(); ebxmlMsg.setReceiver(from); ebxmlMsg.setSender(to); ebxmlMsg.saveChanges(); pc.send(ebxmlMsg); ebxmlMsg.writeTo(System.out); System.out.println("***Sent message from ReceivingServlet"); } catch(Exception e) { e.printStackTrace(); } } }