JMSBEANBean.java~6~
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package com.cwj.userjmssesenbdb;
- import javax.ejb.*;
- import javax.jms.*;
- import javax.naming.*;
- import javax.rmi.*;
- import com.cwj.userjmssesenbdb.*;
- import java.util.*;
- public class JMSBEANBean implements MessageDrivenBean, MessageListener {
- MessageDrivenContext messageDrivenContext;
- com.cwj.userjmssesenbdb.SessHome sessHome;
- public void ejbCreate() throws CreateException {
- /**@todo Complete this method*/
- }
- public void ejbRemove() {
- /**@todo Complete this method*/
- }
- public void onMessage(Message msg) {
- try{
- TextMessage TMS=(TextMessage)msg;
- String a1=TMS.getText();
- String b1=a1+"cwj";
- System.out.println("Message getted Is:"+a1+">>>>>>>>>>>>>>OK");
- Context context=getInitialContext();
- Object ref=context.lookup("SessBean");
- sessHome=(SessHome)javax.rmi.PortableRemoteObject.narrow(ref,SessHome.class);
- sessHome.create().insTableAa11(a1,b1);
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
- }
- public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) {
- this.messageDrivenContext = messageDrivenContext;
- }
- private Context getInitialContext() throws Exception {
- String url = "t3://TsingHuaSQL:7001";
- String user = null;
- String password = null;
- Properties properties = null;
- try {
- properties = new Properties();
- properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
- properties.put(Context.PROVIDER_URL, url);
- if (user != null) {
- properties.put(Context.SECURITY_PRINCIPAL, user);
- properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
- }
- return new InitialContext(properties);
- }
- catch(Exception e) {
- throw e;
- }
- }
- }