1 37 38 package com.sun.j2ee.blueprints.airlinesupplier.pomessagebean; 39 40 import java.io.Serializable ; 41 import java.rmi.RemoteException ; 42 import javax.ejb.*; 43 import javax.naming.*; 44 import javax.jms.*; 45 import javax.xml.rpc.*; 46 47 import com.sun.j2ee.blueprints.airlinesupplier.JNDINames; 48 import com.sun.j2ee.blueprints.airlinesupplier.powebservice.*; 49 import com.sun.j2ee.blueprints.airlinesupplier.purchaseorder.ejb.*; 50 import com.sun.j2ee.blueprints.servicelocator.*; 51 import com.sun.j2ee.blueprints.servicelocator.ejb.*; 52 53 public class AirlineMessageBean implements MessageDrivenBean, MessageListener { 54 55 private transient MessageDrivenContext mdc = null; 56 57 60 public AirlineMessageBean() {} 61 62 65 public void setMessageDrivenContext(MessageDrivenContext mdc) { 66 this.mdc = mdc; 67 } 68 69 72 public void onMessage(Message message) { 73 AirlineOrder alo = null; 74 75 try { 76 String messageID = message.getJMSMessageID(); 77 if (message instanceof ObjectMessage) { 78 ObjectMessage msg = (ObjectMessage)message; 79 alo = (AirlineOrder)msg.getObject(); 80 } else { 81 System.out.println("Wrong type message for AL order: " 82 + message.getClass().getName()); 83 } 84 } catch (JMSException e) { 85 e.printStackTrace(); 88 } 89 try { 90 doWork(alo); 91 } catch (OrderSubmissionException oe) { 92 oe.printStackTrace(); 95 } 96 97 } 98 99 public void doWork(AirlineOrder flight) throws OrderSubmissionException { 100 try { 101 persistOrder(flight); 102 } catch (Exception e) { 103 e.printStackTrace(); 106 } 107 sendInvoice(flight); 108 } 109 110 public void sendInvoice(AirlineOrder flight) { 111 Invoice inv = new Invoice("1234", flight.getOrderId(), 112 "AIRLINE_INVOICE", "AGENT-001234", 113 flight.getDepFlightDate(), 114 flight.getRetFlightDate(), 115 flight.getDepFlightId(), 116 flight.getRetFlightId(), 117 flight.getHeadCount(), 118 "COMPLETED", 119 "48 Hours Prior to Flight"); 120 try { 121 InitialContext ic = new InitialContext(); 122 WebServiceBroker svc = (WebServiceBroker) 123 ic.lookup(JNDINames.BROKER_SERVICE_NAME); 124 String endpointURI = (String ) 125 ic.lookup(JNDINames.BROKER_SERVICE_URL); 126 BrokerServiceIntf port= (BrokerServiceIntf) 127 svc.getPort(BrokerServiceIntf.class); 128 129 ((Stub)port)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, 131 endpointURI); 132 port.submitDocument(inv.toXML()); 133 } catch (Exception ne) { 134 ne.printStackTrace(); 137 } 138 } 139 140 141 144 public void persistOrder(AirlineOrder flight) 145 throws OrderSubmissionException { 146 147 try { 148 ServiceLocator sl = new ServiceLocator(); 149 150 AirlineOrderLocalHome flightLocalHome = (AirlineOrderLocalHome) 151 sl.getLocalHome(JNDINames.AIRLINE_ORDER_EJB); 152 AirlineOrderLocal flightLocal = 153 (AirlineOrderLocal) flightLocalHome.create(flight); 154 } catch (ServiceLocatorException je) { 155 throw new OrderSubmissionException("Error AL persisting order:" 156 + je.getMessage()); 157 } catch(CreateException ce) { 158 throw new OrderSubmissionException("Error AL persisting order:" 159 + ce.getMessage()); 160 } 161 } 162 163 164 167 public void ejbCreate() {} 168 169 172 public void ejbRemove() { 173 mdc = null; 174 } 175 } 176 | Popular Tags |