java.lang.ClassCastException when trying to send mail using weblogic(EntityBean)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   beula_sc
Posted On:   Wednesday, April 11, 2001 04:31 AM

To deploy mail bean in weblogic I made some changes in "weblogic.properties" as weblogic.httpd.MailSession.testBean= mail.from=myname@mycompany.com, mail.host=mailserver part of the program is as follows: Properties h = new Properties(); Message pmsMsg=null; try{ h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); h.put(Context.PROVIDER_URL, "t3://localhost:7001"); InitialContext ic = new InitialContext(h); Session session = (Session)ic.lookup("testBean"); Properties props = new Properties(); props.put("mail.transport.protocol","smtp");    More>>

To deploy mail bean in weblogic I made some
changes in "weblogic.properties" as

			
weblogic.httpd.MailSession.testBean=
mail.from=myname@mycompany.com,
mail.host=mailserver


part of the program is as follows:
			
Properties h = new Properties();
Message pmsMsg=null;
try{
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
InitialContext ic = new InitialContext(h);
Session session = (Session)ic.lookup("testBean");
Properties props = new Properties();
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.host", "myserver"); props.put("mail.from", "myname@mycompany.com");
Session session2 = session.getInstance(props);
pmsMsg = new MimeMessage(session2);
}catch(Exception ess)
{
System.out.println("Exception in context: "+ess);
}

Exception is:

java.lang.ClassCastException: occuring in the place of
"Session session = (Session)ic.lookup("testBean");"

if anyone has come across this please help me    <<Less

Re: java.lang.ClassCastException when trying to send mail using weblogic(EntityBean)

Posted By:   AlessandroA_Garbagnati  
Posted On:   Wednesday, April 11, 2001 10:12 AM

Hi,

I think that the problem is the 'illegal' way (illegal object) that you use for casting the bean that you're looking for. Try this:



Object obj = ic.lookup("testBean");

TestBeanHome home = (TestBeanHome)PortableRemoteObject.narrow(obj, TestBeanHome.class);




Then, for example, if you need to create a new entity, do something like:

TestBean testBean = home.create(...);



Or, to find, something like:

TestBean testBean = home.findByPrimaryKey(...);
About | Sitemap | Contact