Glassfish EJB Error

SEVERE: "DPL8011: autodeployment failure while deploying the application : Error loading deployment descriptors for module [CI] -- Cannot resolve reference Unresolved Ejb-Ref com.stryker.cmf.accountrolebean.AccountMgrBean/mailer@jndi: @null@com.stryker.cmf.cimailer.CIMailer@Session@null

This is the AccountMgrBean, atleast what I think is important

--

package com.stryker.cmf.accountrolebean;

import java.math.BigInteger;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

import java.util.Random;

import javax.ejb.EJB;

import javax.ejb.Stateless;

import com.stryker.cmf.cimailer.CIMailer;

import com.stryker.cmf.cimailer.CIMailerException;

/**

*

* @author tony.mattas

*

*/

@Stateless

public class AccountMgrBean implements AccountMgr {

@EJB UsersFacadeLocal userfacade;

@EJB CIMailer mailer;

//TODO - Generate new user e-mail.

public void addUser(String username, String eMail) throws AccountMgrException {

//Randomly generate a password.

String password = randomPassword();

Users iusername = userfacade.findById(username);

/* Check for data sanity before hitting the DB adapter to prevent internal error */

if (iusername != null) {

throw new AccountMgrException("The Account " + iusername.getUsername() + "already exists.");

}

/* Now we'll create a new User object, since it currently is null */

iusername = new Users();

iusername.setUsername(username);

//Setting a default group

iusername.setGroupname("users");

//If this fails we have big problems.

try {

iusername.setPassword(hash(password));

userfacade.save(iusername);

mailer.addRecipient(eMail);

mailer.setSubject("Stryker CranioMaxilloFacial Login Information");

mailer.setSender("CIAdministrators@stryker.com", "Stryker CranioMaxilloFacial");

mailer.setMessage("Dear User,\n\n" +

"Welcome to the Stryker CranioMaxilloFacial custom implant site. This e-mail contains your" +

"temporary username and password. You will be asked to change this password on first login.\n\n" +

"Username: " + username + "\n" +

"Password: " + password);

mailer.sendMessage();

} catch (NoSuchAlgorithmException e1) {

throw new AccountMgrException("MD5 Algorithm Does Not Exist.", e1);

} catch (RuntimeException e) {

throw new AccountMgrException("Unable to Commit Data.", e);

} catch (CIMailerException e) {

throw new AccountMgrException("Unable to mail password.", e);

}

}

Important Parts of CI Mailer Bean

-

package com.stryker.cmf.cimailer;

import java.io.UnsupportedEncodingException;

import java.util.ArrayList;

import java.util.Date;

import javax.annotation.Resource;

import javax.ejb.Stateless;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Multipart;

import javax.mail.internet.AddressException;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;

/**

*

* @author Anthony G. Mattas

*

*/

@Stateless

public class CIMailerBean {

@Resource private javax.mail.Session session;

private String subject;

private StringBuffer message;

/* Hash maps for e-mail address in the format Address, Name */

private ArrayList<String> recipient;

private ArrayList<String> cc;

private ArrayList<String> bcc;

private String senderaddress;

private String sendername;

/***

* General constructor just makes class usable

*/

CIMailerBean() {

this.message = new StringBuffer();

this.recipient = new ArrayList<String>();

this.cc = new ArrayList<String>();

this.bcc = new ArrayList<String>();

}

/**

* Sends a message

* @throws CIMailerException

*/

public void sendMessage() throws CIMailerException {

try {

Message msg = new MimeMessage(session);

if ((this.sendername != null) && (this.senderaddress != null))

msg.setFrom(new InternetAddress(this.senderaddress, this.sendername));

if (this.subject != null)

msg.setSubject(this.subject);

else

throw new CIMailerException("Subject is Null");

// Not allowing date spoofing

msg.setSentDate(new Date());

msg.setFrom();

if ((this.recipient.size() < 1) && (this.cc.size() < 1) && (this.bcc.size() < 1))

throw new CIMailerException("No Recipients");

for (String address: this.recipient) {

msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(address, false));

}

for (String address: this.cc) {

msg.addRecipients(Message.RecipientType.CC, InternetAddress.parse(address, false));

}

for (String address: this.bcc) {

msg.addRecipients(Message.RecipientType.BCC, InternetAddress.parse(address, false));

}

MimeBodyPart mbp = new MimeBodyPart();

if (this.message.toString() != null)

mbp.setText(this.message.toString());

Multipart mp = new MimeMultipart();

mp.addBodyPart(mbp);

msg.setContent(mp);

} catch (AddressException e) {

throw new CIMailerException("Internal Address Exception", e);

} catch (MessagingException e) {

throw new CIMailerException("Internal Messaging Exception", e);

} catch (UnsupportedEncodingException e) {

throw new CIMailerException("Unsupported encoding type", e);

}

}

Both beans of course have a local interface as well which matches.

[5951 byte] By [amattasa] at [2007-11-27 11:49:54]
# 1

Where is the association between the CIMailerBean bean class and its interface?This would typically

be coded as either

@Stateless

public class CIMailerBean implements CIMailer ...

or

@Local(CIMailer.class)

@Stateless

public class CIMailerBean ...

Although, it can also be specified via ejb-jar.xml.

One other thing to point out is it's not recommended to do anything within the

java constructor for the bean class.The java constructor is not considered a

first-class part of the bean initialization lifecycle. It's better to put such code within

a @PostConstruct method.

ksaksa at 2007-7-29 18:28:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Oh wow I'm an Idiot.

amattasa at 2007-7-29 18:28:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

I fixed that and now I get a different stack trace when I call the method in account manager bean, bare with me I'm a little new to EJB 3.0 still.

INFO: EJB5070: Exception creating stateless session bean : [{0}]

java.lang.IllegalAccessException: Class com.sun.ejb.containers.StatelessSessionContainer can not access a member of class com.stryker.cmf.cimailer.CIMailerBean with modifiers ""

at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)

at java.lang.Class.newInstance0(Class.java:344)

at java.lang.Class.newInstance(Class.java:303)

at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:509)

at com.sun.ejb.containers.StatelessSessionContainer.access$100(StatelessSessionContainer.java:111)

at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:772)

at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:199)

at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:486)

at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:1664)

at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1218)

at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:195)

at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)

at $Proxy29.addRecipient(Unknown Source)

at com.stryker.cmf.accountrolebean.AccountMgrBean.addUser(AccountMgrBean.java:40)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)

at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)

at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2884)

at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3975)

at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)

at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)

at $Proxy33.addUser(Unknown Source)

at com.stryker.cmf.admin.Register.add(Register.java:25)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at com.sun.el.parser.AstValue.invoke(AstValue.java:187)

at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)

at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)

at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)

at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)

at javax.faces.component.UICommand.broadcast(UICommand.java:383)

at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)

at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)

at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:268)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)

at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261)

at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212)

at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:361)

at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)

at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

Jul 26, 2007 1:10:52 PM com.sun.ejb.containers.BaseContainer postInvoke

INFO: EJB5018: An exception was thrown during an ejb invocation on [CIMailerBean]

Jul 26, 2007 1:10:52 PM com.sun.ejb.containers.BaseContainer postInvoke

INFO:

amattasa at 2007-7-29 18:28:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

If the constructor is implemented, it must be public. As I mentioned before, it's better to just not use

the constructor at all. In that case, the default public no-arg one will be generated automatically per

the Java language rules.

You can put your initilization code in a PostConstruct method as follows :

@javax.annotation.PostConstruct

private void init() {

...

}

ksaksa at 2007-7-29 18:28:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Will the post construct be called after every constructor then even if args are passed?

amattasa at 2007-7-29 18:28:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

There are no arguments for Java constructors in EJB.The constructor must always be 0-arg.

The constructor is not part of the programming model so it should basically be ignored.

The PostConstruct method will be called once per bean instance, after any injection has been

performed.There isn't any way to pass args to a PostConstruct method. Passing client-specific

data at initialization time doesn't make sense for a Stateless Session Bean, since there is no guarantee

as to which bean instance will be used for a given invocation.Passing client-specific data at

initialization time does make sense for Stateful Session Beans.In EJB 3.0, the way to do that is simply

to define a business method that takes the initialization data and have the client call it as the first

invocation on the bean.

--ken

ksaksa at 2007-7-29 18:28:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...