• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JNDI Lookup

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am facing problem to lookup a Stateless Session Bean having Local Interface From a CMP EntityBean i am Using WASD50.
===Here is the code====
This is UUID Bean Which Just generates UUID
package com.wesra.uuid;
import java.net.InetAddress;
import java.security.SecureRandom;
import com.wesra.ejb.exception.*;
/**
* Bean implementation class for Enterprise Bean: UUID
*/
public class UUIDBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;
//Non reapting random seed
SecureRandom seeder;
//cached value for mid part of string
private String midValue;

/**
* getSessionContext
*/
public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* setSessionContext
*/
public void setSessionContext(javax.ejb.SessionContext ctx) {
mySessionCtx = ctx;
}
/**
* ejbCreate
*/
public void ejbCreate() throws javax.ejb.CreateException {
try {
StringBuffer stringbuffer = new StringBuffer();
seeder = new SecureRandom();
//Get the internet address
InetAddress inet = InetAddress.getLocalHost();
byte[] bytes = inet.getAddress();
String hexInetAddress = hexFormat(getInt(bytes),8);
//get the hex code for this object.
String thisHashCode = hexFormat(System.identityHashCode(this),8);

stringbuffer.append("-");
stringbuffer.append(hexInetAddress.substring(0, 4));
stringbuffer.append("-");
stringbuffer.append(hexInetAddress.substring(4));
stringbuffer.append("-");
stringbuffer.append(thisHashCode.substring(0, 4));
stringbuffer.append("-");
stringbuffer.append(thisHashCode.substring(4));
midValue = stringbuffer.toString();

}catch(Exception e) {
throw new UUIDCreateException("Fail to genereate UUID:"+e);
}
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}

//Developer Defined Methods
/**
* Implementation of method declared in Local
* interface
*/
public String getUUID() {
return getVal(midValue);
}

/**
* This is utility method for converting bytes into integer.
*/
private int getInt(byte abyte0[])
{
int i = 0;
int j = 24;
for(int k = 0; j >= 0; k++)
{
int l = abyte0[k] & 0xff;
i += l << j;
j -= 8;
}
return i;
}
/**
* This is utility method to convert integer primitive to hex format
*/
private String hexFormat(int i, int j)
{
String s = Integer.toHexString(i);
return padHex(s, j) + s;
}
/**
* This is utility method used for converting to hex format
*/
private String padHex(String s, int i)
{
StringBuffer stringbuffer = new StringBuffer();
if(s.length() < i)
{
for(int j = 0; j < i - s.length(); j++)
stringbuffer.append("0");
}
return stringbuffer.toString();
}
/**
* This is utility method for converting string to hex format.
*/
private String getVal(String s) {
long l = System.currentTimeMillis();
int i = (int)l & 0xffffffff;
int j = seeder.nextInt();
return hexFormat(i, 8) + s + hexFormat(j, 8);
}
}
=======End of UUIDBean Code=====
====This is the EntityBean Which lookup UUID bean to get UUID=========
package com.wesra.nmat;
import java.sql.Timestamp;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.wesra.uuid.UUIDLocal;
import com.wesra.uuid.UUIDLocalHome;
/**
* Bean implementation class for Enterprise Bean: SysAdmin
*/
public abstract class SysAdminBean implements javax.ejb.EntityBean {
private javax.ejb.EntityContext myEntityCtx;
/**
* setEntityContext
*/
public void setEntityContext(javax.ejb.EntityContext ctx) {
myEntityCtx = ctx;
}
/**
* getEntityContext
*/
public javax.ejb.EntityContext getEntityContext() {
return myEntityCtx;
}
/**
* unsetEntityContext
*/
public void unsetEntityContext() {
myEntityCtx = null;
}
/**
* ejbCreate
*/
public java.lang.String ejbCreate(String loginID,String password,
String fName,String lName,String email,
String createdBy)
throws javax.ejb.CreateException {
//1. Generate UUID for administrator registration
/*Propertiesprop = new Properties();
prop.put(javax.naming.Context.PROVIDER_URL, "iiop:///");
prop.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");*/
try {
//Context jndiContext = new InitialContext(prop);
InitialContext context = new InitialContext();
UUIDLocalHome uuidHome = (UUIDLocalHome)context.lookup("java:comp/env/ejb/UUIDLocalHome");
//UUIDLocalHome uuidHome = (UUIDLocalHome)jndiContext.lookup("UUIDLocalHome");
System.out.println("JNDI For UUID Done:"+uuidHome);
UUIDLocal uuidLocal = uuidHome.create();
System.out.println("UUID Local Created.");
String PK = uuidLocal.getUUID();
System.out.println("Finally got the PK:"+PK);
setPK(PK);
setLoginID(loginID);
setPassword(password);
setFName(fName);
setLName(lName);
setEmail(email);
if(createdBy == null)
createdBy = "SYSTEM";
setCreatedBy(createdBy);
//Putting Time Stamp
Timestamp lin = new Timestamp(System.currentTimeMillis());
setLoggedInTime(lin);
setLogoutTime(lin);
return null;
} catch (NamingException e) {
throw new CreateException("Initial Context Fail While looking for UUID "+e);
}
}
/**
* ejbPostCreate
*/
public void ejbPostCreate(String loginID,String password,
String fName,String lName,String email,
String createdBy)
throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbLoad
*/
public void ejbLoad() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() throws javax.ejb.RemoveException {
}
/**
* ejbStore
*/
public void ejbStore() {
}
/**
* Get accessor for persistent attribute: PK
*/
public abstract java.lang.String getPK();
/**
* Set accessor for persistent attribute: PK
*/
public abstract void setPK(java.lang.String newPK);
/**
* Get accessor for persistent attribute: loginID
*/
public abstract java.lang.String getLoginID();
/**
* Set accessor for persistent attribute: loginID
*/
public abstract void setLoginID(java.lang.String newLoginID);
/**
* Get accessor for persistent attribute: password
*/
public abstract java.lang.String getPassword();
/**
* Set accessor for persistent attribute: password
*/
public abstract void setPassword(java.lang.String newPassword);
/**
* Get accessor for persistent attribute: fName
*/
public abstract java.lang.String getFName();
/**
* Set accessor for persistent attribute: fName
*/
public abstract void setFName(java.lang.String newFName);
/**
* Get accessor for persistent attribute: lName
*/
public abstract java.lang.String getLName();
/**
* Set accessor for persistent attribute: lName
*/
public abstract void setLName(java.lang.String newLName);
/**
* Get accessor for persistent attribute: email
*/
public abstract java.lang.String getEmail();
/**
* Set accessor for persistent attribute: email
*/
public abstract void setEmail(java.lang.String newEmail);
/**
* Get accessor for persistent attribute: createdBy
*/
public abstract java.lang.String getCreatedBy();
/**
* Set accessor for persistent attribute: createdBy
*/
public abstract void setCreatedBy(java.lang.String newCreatedBy);
/**
* Get accessor for persistent attribute: loggedInTime
*/
public abstract java.sql.Timestamp getLoggedInTime();
/**
* Set accessor for persistent attribute: loggedInTime
*/
public abstract void setLoggedInTime(java.sql.Timestamp newLoggedInTime);
/**
* Get accessor for persistent attribute: logoutTime
*/
public abstract java.sql.Timestamp getLogoutTime();
/**
* Set accessor for persistent attribute: logoutTime
*/
public abstract void setLogoutTime(java.sql.Timestamp newLogoutTime);
}
========================End of Entity Bean

Any Help in this is highly apperciated....
reply
    Bookmark Topic Watch Topic
  • New Topic