⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmsdelegate.java

📁 我在加拿大学习的一个比较复杂的在线银行程序.
💻 JAVA
字号:
package com.ebusiness.ebank.servicedelegate;/** * <p>Title: </p> * <p>Description:  This class delegate all visa payment to an asynchronous JMS call. JMS *                  is provided by another department within eBusiness Inc.. The ePayment application *                  will process the request asynchronously once the message has been sent to JMS server * *                  Since the Delegate can be used either within eBank application *                  or by other applications, please do not use struts and Log service *                  within the delegate classes. *                  </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: eBusiness Inc., All right reserved</p> * @author * @version 1.0 */import com.ebusiness.ebank.bean.StatementValue;import com.ebusiness.ebank.exception.SystemException;import javax.jms.QueueConnectionFactory;import javax.jms.QueueConnection;import javax.jms.QueueSession;import javax.jms.Session;import javax.jms.QueueSender;import javax.jms.Queue;import javax.jms.TextMessage;import javax.naming.InitialContext;import java.util.Calendar;import java.math.BigDecimal;import java.io.StringWriter;import javax.xml.bind.JAXBContext;import javax.xml.bind.Marshaller;import com.ebusiness.epayment.xmlbinding.*;/** * The class is used to send messages to the queue. * */public class JMSDelegate{    private static QueueConnectionFactory qconFactory;    private static Queue queue;    private static Marshaller m;    private static ObjectFactory objFactory;    /**     * Creates all the necessary objects for sending message     */    static    {        try        {           //  Hashtable h = new Hashtable();           //  h.put(Context.INITIAL_CONTEXT_FACTORY,             //      "weblogic.jndi.WLInitialContextFactory");             //h.put(Context.PROVIDER_URL, "iiop://localhost:9001");             //h.put(Context.SECURITY_PRINCIPAL, "rbcJMS");             //h.put(Context.SECURITY_CREDENTIALS, "admin1234");             InitialContext ctx = new InitialContext();             qconFactory = (QueueConnectionFactory) ctx.lookup("jms/ebank/QueueConnectionFactory");             System.out.println(qconFactory == null? "QconFactory is Null" : "QconFactory is NOT Null");             queue = (Queue) ctx.lookup("jms/ebank/Queue");             System.out.println(queue == null? "Que is Null" : "Que is NOT Null");              JAXBContext jc = JAXBContext.newInstance("com.ebusiness.epayment.xmlbinding");              m = jc.createMarshaller();              m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);              objFactory = new ObjectFactory();        }        catch (Exception e)        {            e.printStackTrace();            System.out.println("FATAL: JMS static block" + e.getMessage());        }    }    /**     * Sends a message to a JMS queue.     *     * @param message  message to be sent     * @exception JMSException if JMS fails to send message due to internal error     */    public static void sendPayment(StatementValue sValue) throws SystemException    {        QueueConnection qCon = null;        QueueSession qSession = null;        QueueSender qSender = null;        try        {            System.out.println(qconFactory == null? "QconFactory is Null" : "QconFactory is NOT Null");            qCon = qconFactory.createQueueConnection();            System.out.println(qCon == null? "Qcon is Null" : "Qcon is NOT Null");            //qCon.start();            qSession = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); //transacted            System.out.println(qSession == null? "Que is Null" : "Que is NOT Null");            qSender = qSession.createSender(queue);            TextMessage msg = qSession.createTextMessage();            msg.setText(createXMLMsg(sValue));            qCon.start();            qSender.send(msg);        }        catch (Exception e)        {            e.printStackTrace();            throw new SystemException(e);        }        finally        {            try            {                //there is no need to close session, producer when the connnection                //object is closed.                if (qCon != null)                   qCon.close();            }            catch(Exception e)            {                e.printStackTrace();            }        }    }    private static String createXMLMsg(StatementValue sValue) throws Exception    {       BankingValue bValue = objFactory.createBankingValue();       StringWriter sr = new StringWriter();       Calendar bankingDate = Calendar.getInstance();       bankingDate.setTime(sValue.getBankingDate());       bValue.setBankingDate(bankingDate);       bValue.setDescription(sValue.getDescription());       bValue.setWithdrawal(new BigDecimal(sValue.getWithdrawal()));       bValue.setDeposit(new BigDecimal(sValue.getDeposit()));       bValue.setAccountNo(sValue.getAccountNo());       bValue.setClientCardNo(sValue.getClientCardNo());       m.marshal(bValue, sr);       return sr.toString();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -