|
Publicité ' | |||||||||||||||||||||||
|
|
#1 |
|
Invité de passage
![]() Inscription : novembre 2012 Messages : 1 ![]() |
error jndi:null in send mail use Message Driven Bean
Hi everybody I try to write application send mail with MDB I have an error , please help me , give a clue or solution to fix it ------ 14:05:49,380 INFO [JBossASKernel] Created KernelDeployment for: g3_DVDShop_MDB_Module.jar 14:05:49,380 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=g3_DVDShop_MDB_Module.jar,name=SendMailMDB,service=EJB3 14:05:49,380 INFO [JBossASKernel] with dependencies: 14:05:49,380 INFO [JBossASKernel] and demands: 14:05:49,380 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService 14:05:49,380 INFO [JBossASKernel] and supplies: 14:05:49,380 INFO [JBossASKernel] jndi:null 14:05:49,380 INFO [JBossASKernel] Class:javax.jms.MessageListener 14:05:49,380 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=g3_DVDShop_MDB_Module.jar,name=SendMailMDB,service=EJB3) to KernelDeployment of: g3_DVDShop_MDB_Module.jar 14:05:49,401 INFO [EJBContainer] STARTED EJB: mdb.SendMailMDB ejbName: SendMailMDB --- My code file SendMailMDB.java --- view plaincopy to clipboardprint? /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package mdb; import dao.SendMailDAO; import eproject.dvdshop.entities.SendMail; import eproject.dvdshop.utils.EJBUtils; import java.util.logging.Level; import java.util.logging.Logger; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.ObjectMessage; import javax.jms.Queue; /** * * @author ACER */ @MessageDriven(mappedName = EJBUtils.JBOSS_JMS_JNDI, activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), // @ActivationConfigProperty(propertyName = "destination", propertyValue = EJBUtils.JBOSS_JMS_JNDI) @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/dvdshop_sendmail") }) public class SendMailMDB implements MessageListener { public SendMailMDB() { } public void onMessage(Message message) { try { ObjectMessage objectMessage = (ObjectMessage) message; SendMail mailObject = (SendMail) objectMessage.getObject(); String smtpServer = mailObject.getSmtpServer(); String to = mailObject.getTo(); String from = mailObject.getFrom(); String subject = mailObject.getSubject(); String body = mailObject.getBody(); String pwd = mailObject.getPwd(); SendMailDAO sendMail = new SendMailDAO(); System.out.print(smtpServer + "" + to + from + subject + body + pwd); try { sendMail.send(smtpServer, to, from, pwd, subject, body); } catch (Exception ex) { ex.printStackTrace(); } } catch (JMSException ex) { Logger.getLogger(SendMailMDB.class.getName()).log(Level.SEVERE, null, ex); } } } --- --- file SendMailDAO .java view plaincopy to clipboardprint? package dao; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author ACER */ import java.util.Date; import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendMailDAO { public static void send(String smtpServer, String to, String from, String psw, String subject, String body) throws Exception { final String login = from;//”nth001@gmail.com”;//usermail final String pwd = psw;//”password cua ban o day”; // java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); Properties props = System.getProperties(); props.put("mail.smtp.host", smtpServer); props.put("mail.smtp.port", "587"); props.put("mail.smtp.starttls.enable", "true"); Authenticator pa = null; //default: no authentication if (login != null && pwd != null) { //authentication required? props.put("mail.smtp.auth", "true"); pa = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(login, pwd); } }; }//else: no authentication Session session = Session.getInstance(props, pa); // — Create a new message – Message msg = new MimeMessage(session); // — Set the FROM and TO fields – msg.setFrom(new InternetAddress(from)); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse( to, false)); // — Set the subject and body text – msg.setSubject(subject); msg.setText(body); // — Set some other header information – msg.setHeader("X - Mailer", "LOTONtechEmail"); msg.setSentDate(new Date()); msg.saveChanges(); // — Send the message – Transport.send(msg); } } --- I use JBoss AS 5.0.1GA in folder deploy i have 2 file Xxx-service.xml file dvdshop-jms-destinations-service.xml --- <?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=jms/dvdshopqueue"> <attribute name="JNDIName">jms/dvdshop_sendmail</attribute> <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends> </mbean> </server> ----- file dvdshop-jms-connection-factories-service.xml view plaincopy to clipboardprint? <?xml version="1.0" encoding="UTF-8"?> --- <server> <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory" name="jboss.messaging.connectionfactory:service=dvdshop_jms_conectionfactory" xmbean-dd="xmdesc/ConnectionFactory-xmbean.xml"> <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends> <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=bisocket</depends> <depends>jboss.messaging:service=PostOffice</depends> <attribute name="SupportsFailover">false</attribute> <attribute name="SupportsLoadBalancing">false</attribute> <attribute name="JNDIBindings"> <bindings> <binding>dvdshop_jms_conectionfactory</binding> </bindings> </attribute> </mbean> </server> --- --- |
|
|
00
|
Copyright © 2000-2013 - www.developpez.com