users@glassfish.java.net

Re: EJB Cannot Be Found

From: <glassfish_at_javadesktop.org>
Date: Wed, 20 Jun 2007 09:04:10 PDT

I made these changes, and still seem to have problems. The app does deploy now, however when I access the page that uses the EJB I get this.


-------------------
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.stryker.cmf.newuser.JSFUser/newuser_at_jndi: com.stryker.cmf.users.UserAccountBean_at_null@com.stryker.cmf.users.UserAccountBean_at_Session@null into class com.stryker.cmf.newuser.JSFUser
root cause

javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.stryker.cmf.newuser.JSFUser/newuser_at_jndi: com.stryker.cmf.users.UserAccountBean_at_null@com.stryker.cmf.users.UserAccountBean_at_Session@null into class com.stryker.cmf.newuser.JSFUser
root cause

com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.stryker.cmf.newuser.JSFUser/newuser_at_jndi: com.stryker.cmf.users.UserAccountBean_at_null@com.stryker.cmf.users.UserAccountBean_at_Session@null into class com.stryker.cmf.newuser.JSFUser
root cause

javax.naming.NameNotFoundException: com.stryker.cmf.users.UserAccountBean#com.stryker.cmf.users.UserAccountBean not found
note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.

----------------------
Interface
----------------------
package com.stryker.cmf.users;

import javax.ejb.Local;

@Local
public interface UserAccount {
        public void adduser(String username, String password);
}


----------------------
Enterprise Bean
----------------------
package com.stryker.cmf.users;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.ejb.Stateless;
/**
 *
 * @author tony.mattas
 *
 */
@Stateless
public class UserAccountBean implements UserAccount {
        private Users iusername;
        private UsersFacade userfacade;
        private Groups igroupname;
        private GroupsFacade groupsfacade;
/**
 * Constructor to load an exisiting user.
 * @param username
 */
        public void adduser(String username, String password) {
                //TODO - Exception user exists
                iusername.setUsername(username);
                iusername.setPassword(hash(password));
                userfacade.save(iusername);
        }
        /**
         * Generates a MD5 Hash
         * @param password Plain text password
         * @return Hashed Password
         */
        private String hash(String password) {
                String hashed = null;
                BigInteger hash;
                try {
                        MessageDigest md5 = MessageDigest.getInstance("MD5");
                        md5.update(password.getBytes());
                        hash = new BigInteger(1, md5.digest());
                        hashed = hash.toString(16);
                } catch (NoSuchAlgorithmException e) {
                        e.printStackTrace();
                }
                return hashed;
        }
/**
 * Adds a group to the current user.
 * @param group
 */
        public void addgroup(String group) {
                Groups newGroup = new Groups(null ,iusername, group);
                groupsfacade.save(newGroup);
        }
}



---------------------
Managed Bean
--------------------
package com.stryker.cmf.newuser;

import javax.ejb.EJB;

import com.stryker.cmf.users.UserAccountBean;

public class JSFUser {
        String username = null;
        String password = null;
        @EJB
        public UserAccountBean newuser;
        public String add() {
                newuser.adduser(username, password);
                return "success";
        }
        public String getPassword() {
                return password;
        }
        public void setPassword(String password) {
                this.password = password;
        }
        public String getUsername() {
                return username;
        }
        public void setUsername(String username) {
                this.username = username;
        }
}
[Message sent by forum member 'amattas' (amattas)]

http://forums.java.net/jive/thread.jspa?messageID=223102