?? activitypoendpointbean.java
字號:
/* Copyright 2004 Sun Microsystems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistribution in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility. $Id: ActivityPOEndpointBean.java,v 1.7 2003/11/25 19:15:21 vijaysr Exp $ */package com.sun.j2ee.blueprints.activitysupplier.powebservice;import javax.ejb.*;import java.rmi.*;import javax.jms.*;import java.util.*;import com.sun.j2ee.blueprints.activitysupplier.JNDINames;import com.sun.j2ee.blueprints.servicelocator.*;import com.sun.j2ee.blueprints.servicelocator.ejb.*;/** * This class is the entry point for purchase orders submitted * by OPC to the activity suppliers; */public class ActivityPOEndpointBean implements SessionBean { private SessionContext sc; public ActivityPOEndpointBean(){} public void ejbCreate() throws CreateException {} /** * Receive an order, preprocess the request, submit request to workflow * and return the order id so that the caller can have a correlation id * for the order */ public String submitActivityReservationDetails(String xmlPO) throws InvalidOrderException, OrderSubmissionException, RemoteException { // Do Interaction layer processing ActivityOrder order = preProcessInput(xmlPO); // Submit request thro JMS Queue submitRequest(order); // Return reference id - dummy ID for now return("ACT1234"); } private ActivityOrder preProcessInput(String po) throws InvalidOrderException { // XML doc should be ideally validated against its schema here; // Similar scenario already shown in OPC module; // Here it is skipped in this sample - we will convert doc to obj return(ActivityOrder.fromXML(po)); } private void submitRequest(ActivityOrder act) throws OrderSubmissionException { QueueConnectionFactory queueConnectionFactory = null; Queue queue = null; QueueConnection queueConnection = null; QueueSession queueSession = null; QueueSender queueSender = null; try { ServiceLocator sl = new ServiceLocator(); queueConnectionFactory = (QueueConnectionFactory) sl.getQueueConnectionFactory(JNDINames.ACT_QUEUECONNECTIONFACTORY); queue = sl.getQueue(JNDINames.ACT_QUEUE); queueConnection = queueConnectionFactory.createQueueConnection(); queueSession = queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE); queueSender = queueSession.createSender(queue); ObjectMessage message = queueSession.createObjectMessage(); message.setObject(act); queueSender.send(message); } catch (ServiceLocatorException se) { throw new OrderSubmissionException("Error while sending a message:" + se.getMessage()); } catch (JMSException e) { throw new OrderSubmissionException("Error while sending a message:" + e.getMessage()); } finally { // close all JMS resources if (queueSender != null) { try { queueSender.close(); } catch (JMSException e) { throw new OrderSubmissionException("Error sender close"); } } if (queueSession != null) { try { queueSession.close(); } catch (JMSException e) { throw new OrderSubmissionException("Error session close"); } } if (queueConnection != null) { try { queueConnection.close(); } catch (JMSException e) { throw new OrderSubmissionException("Error Connection close"); } } } } public void setSessionContext(SessionContext sc) { this.sc = sc; } public void ejbRemove() throws RemoteException {} //empty for Stateless EJBs public void ejbActivate() {} //empty for Stateless EJBs public void ejbPassivate() {}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -