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