Problem returning a string from a stateless session bean
tomjmalone Oct 28, 2004 5:38 AMI have set up a stateless session bean, with should do login. I am new to ejbs,so i set it up to just reurn the username, the ejb is below.
/**
*
* File: LoginHome
*
* Use: The login EJB
*
* Author: Thomas James Malone
* Email: tom.malone@fastest.org.uk
* Copyright: (c) Thomas James Malone
*
*/
// Declare the package
package co.uk.fastest.foi.ejb.session.Login;
// Declare the java imports
// Declare the extention java imports
import javax.ejb.*;
import javax.naming.*;
// Declare the interface
public class LoginEJB implements SessionBean { // start of the SessionEJB class
// Fields
private SessionContext ctx;
private Context enviroment;
// Constructor
public LoginEJB ( ) { // start of the constructor
} // End of the consrutor
// Methods
public void ejbCreate ( ) throws CreateException { // start of the CreateException
try { // start of the try statement
InitialContext ic = new InitialContext ( );
enviroment = ( Context ) ic.lookup( "java:comp/env" );
} // end of the try statement
catch ( NamingException ne ) { // start of the catch statement
throw new CreateException ( " Could not look up the context ");
} // end of the catch statement
} // End of the ejbCreate
public void ejbActivate( ) { }
public void ejbPassivate ( ) { }
public void ejbRemove ( ) { }
public void setSessionContext ( SessionContext c ) { // start of the setSessionContext method
ctx=c;
} // End of the setSessionContext method
public String validateUser ( String username, String password ) throws InvalidLoginException { // start of the validateUser method
/*String outcome;
outcome = "username";*/
return username;
} // end of the validateUser method
} // end of the SessionEJB class
the ejb-jar.xml i use is here
<ejb-name>LoginEJB</ejb-name>
co.uk.fastest.foi.ejb.session.Login.LoginHome
co.uk.fastest.foi.ejb.session.Login.Login
<ejb-class>co.uk.fastest.foi.ejb.session.Login.LoginEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
And the jboss.xml file
<ejb-name>LoginEJB</ejb-name>
<jndi-name>foi/Login</jndi-name>
And when the following code is called:
try { // start of the try statement
Object object = initialContext.lookup("foi/login");
loginHome = ( LoginHome ) PortableRemoteObject.narrow(object, LoginHome.class);
login = ( Login ) loginHome.create();
status = login.validateUser(username, password);
} // end of the try statement
catch ( Exception e ) { // start of the catch statement
status = e.getMessage();
} // end of the catch exception
Status is a String and it should be the username, but it just comes back as null, any help would be greatly received.
Sorry for such an irratating question but i'm really stuck
Tom