1 37 38 package com.sun.j2ee.blueprints.airlinesupplier.powebservice; 39 40 import javax.ejb.*; 41 import java.rmi.*; 42 import javax.naming.*; 43 import javax.jms.*; 44 import com.sun.j2ee.blueprints.airlinesupplier.JNDINames; 45 import com.sun.j2ee.blueprints.servicelocator.*; 46 import com.sun.j2ee.blueprints.servicelocator.ejb.*; 47 48 52 public class AirlinePOEndpointBean implements SessionBean { 53 54 private SessionContext sc; 55 56 public AirlinePOEndpointBean(){} 57 58 public void ejbCreate() throws CreateException {} 59 60 65 public String submitAirlineReservationDetails(String xmlPO) 66 throws InvalidOrderException, OrderSubmissionException, 67 RemoteException { 68 69 AirlineOrder flightObj = preProcessInput(xmlPO); 71 72 submitRequest(flightObj); 74 75 return("FLIGHT1234"); 77 } 78 79 private AirlineOrder preProcessInput(String po) 80 throws InvalidOrderException { 81 return(AirlineOrder.fromXML(po)); 85 } 86 87 private void submitRequest(AirlineOrder flight) 88 throws OrderSubmissionException { 89 90 ConnectionFactory jmsConnectionFactory = null; 91 Destination dest = null; 92 Connection jmsConnection = null; 93 Session jmsSession = null; 94 MessageProducer jmsSender = null; 95 96 try { 97 ServiceLocator sl = new ServiceLocator(); 98 jmsConnectionFactory = (ConnectionFactory) 99 sl.getJMSConnectionFactory(JNDINames.AIRLINE_QUEUECONNECTIONFACTORY); 100 dest = sl.getJMSDestination(JNDINames.AIRLINE_QUEUE); 101 jmsConnection = jmsConnectionFactory.createConnection(); 102 jmsSession = jmsConnection.createSession(true, Session.AUTO_ACKNOWLEDGE); 103 jmsSender = jmsSession.createProducer(dest); 104 105 ObjectMessage message = jmsSession.createObjectMessage(); 106 message.setObject(flight); 107 jmsSender.send(message); 108 } catch (ServiceLocatorException se) { 109 throw new OrderSubmissionException("Error while sending a message:" 110 + se.getMessage()); 111 } catch (JMSException e) { 112 throw new OrderSubmissionException("Error while sending a message:" 113 + e.getMessage()); 114 } finally { 115 if (jmsSender != null) { 117 try { 118 jmsSender.close(); 119 } catch (JMSException e) { 120 throw new OrderSubmissionException("Error sender close"); 121 } 122 } 123 if (jmsSession != null) { 124 try { 125 jmsSession.close(); 126 } catch (JMSException e) { 127 throw new OrderSubmissionException("Error session close"); 128 } 129 } 130 if (jmsConnection != null) { 131 try { 132 jmsConnection.close(); 133 } catch (JMSException e) { 134 throw new OrderSubmissionException("Error Connection close"); 135 } 136 } 137 } 138 } 139 140 141 public void setSessionContext(SessionContext sc) { 142 this.sc = sc; 143 } 144 145 public void ejbRemove() throws RemoteException {} 146 147 148 public void ejbActivate() {} 150 151 public void ejbPassivate() {} 153 } 154 | Popular Tags |