Ravindra Balija wrote:
>
> Dear ALL,
> Does anybody in the list have any experiences with NAS 4.0
> implementation EJB Support and JSP support? We are going into the
> coding phase soon. I would like to know are there any pitfalls which
> we need to take care of. Please let us know so that we could avoid
> making the same mistakes.
>
> Thanks with regards,
> Ravindra
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
The main gotcha for NAS 4.0 is that it uses JSP 0.98 spec not 1.0! so be
careful on the <BEAN> tags and you can't use <jsp: ....> tags
On deployment you can The NAS Deployment Manager (nasdm) can not deploy
more than one .jar file at a time even though it thinks it can. So do
them one at a time.
NAS uses netscapes NTV descriptors not XML I have left an example that I
got from a Sun course below
DO NOT start more than ONE Netscape Application Server Administrator
(NASA ,<Install-dir>/server4/nas/bin/ksvradmin ) on a NAS Cluster or bad
things will happen. (The LDAP registry gets out of sync or hosed!)
There are a few Bugs with NAS administration, one of the most annoying
is that
<install-path>/server4/nas/bin/KIVAes.sh stop
does not work if the environment variable LOGNAME is not set. It must
also be root ie you must run it
as root. This sometimes happens if your Sun refuses to read the
/.profile file (check /.dtprofile and make sure DTSOURCEPROFILE is set
properly for your machine)
One more thing ... strictly speaking it's not a gotcha but the name you
want to use to refer to your servlets (ie the mapping between the class
name and the URL name) is the "Name" value (ie the first value) in the
.ntv file that is reference by the appInfo.ntv the class is the value
(third entry in ntv) of the ServletClassPath which is itself a Value of
the ServletRunnerInfo see below int he source code
Hope this helps
Karl
CustomerQuery.java
import java.io.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.rmi.*;
import ejb.entityexample.*;
public class CustomerQuery extends HttpServlet
{
public String getServletInfo()
{
return "By: Joel Parker, Netscape Communications";
}
public void service(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType("text/html");
String JNDI_NAME = "EntityExample/EntityHome";
javax.naming.Context initContext;
java.util.Hashtable env = new java.util.Hashtable(1);
EntityHome home;
EntityRemote remote;
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.kivasoft.eb.jndi.GDSInitContextFactory");
try
{
initContext = new
javax.naming.InitialContext(env);
System.out.println("Got the InitialContext");
}
catch (Exception e)
{
throw new
RemoteException("JNDI_INIT_CONTEXT_FAILED");
}
if (initContext == null)
{
throw new
RemoteException("JNDI_INIT_CONTEXT_FAILED");
}
try
{
/** Call JNDI to lookup the home interface **/
home = (EntityHome) initContext.lookup(JNDI_NAME);
System.out.println("Found the JNDI_NAME using
JNDI");
}
catch(javax.naming.NameNotFoundException e)
{
throw new RemoteException("JNDI_LOOKUP_FAILED");
}
catch(javax.naming.NamingException e)
{
throw new RemoteException("JNDI_LOOKUP_FAILED");
}
catch (java.lang.ClassCastException e)
{
throw new RemoteException("JNDI_LOOKUP_FAILED");
}
try
{
remote = home. findByPrimaryKey
("[EMAIL PROTECTED]"); // use your primary key
}
catch(javax.ejb.FinderException e)
{
throw new
RemoteException("EJB_BEAN_findByPrimaryKey_FAILED");
}
catch(java.rmi.RemoteException e)
{
throw new
RemoteException("EJB_BEAN_findByPrimaryKey_FAILED");
}
String UserName = remote.getUserName();
String Email = remote.getEmail();
String address = remote.getAddress();
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("ejb/DisplayCustomer.jsp");
req.setAttribute("username", UserName);
req.setAttribute("email",Email);
req.setAttribute("address",address);
dispatcher.include(req, resp);
}
}
appInfo.ntv
NTV-ASCII
{
"ServletFiles" StrArr ["Customer"],
"AppName" Str "Ejb",
}
Customer.ntv
NTV-ASCII {
"Customer" NTV {
"ServletRegistryInfo" NTV {
"enable" Str "y",
"encrypt" Str "n",
"group" StrArr ["Ejb"],
"guid" Str
"{C14C59B0-1EB9-11D3-BC9D-00104BEC5BF6}",
},
"ServletRunnerInfo" NTV {
"ServletClassPath" Str "Ejb.CustomerQuery",
},
"ServletData" NTV {
"CreateDate" Str "04291999",
"Description" Str "HelloWorld servlet",
},
},
}
EJB Source
EntityRemote.java (Remote Interface)
package ejb.entityexample;
import java.rmi.RemoteException;
import java.rmi.Remote;
import javax.ejb.*;
public interface EntityRemote extends EJBObject, Remote {
public String getUserName() throws RemoteException;
public String getEmail() throws RemoteException;
public String getAddress() throws RemoteException;
}
EntityHome.java (Home Interface)
package ejb.entityexample;
import javax.ejb.*;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.*;
public interface EntityHome extends EJBHome {
public EntityRemote findByPrimaryKey (String key) throws
FinderException, RemoteException;
}
EntityImpl.java (Implementation)
package ejb.entityexample;
import javax.ejb.*;
import java.io.*;
import java.io.Serializable;
import java.util.*;
import java.rmi.*;
import java.sql.*;
import javax.naming.*;
import com.netscape.server.jdbc.DataSource;
public class EntityImpl implements javax.ejb.EntityBean
{
private transient javax.ejb.EntityContext m_ctx =null;
private String UserName;
private String Email;
private String address;
public void setEntityContext(javax.ejb.EntityContext ctx)
{
m_ctx =ctx;
}
public void unsetEntityContext()
{
m_ctx = null;
}
public String ejbFindByPrimaryKey(String key)
throws RemoteException, FinderException
{
return key;
}
public void ejbRemove() throws RemoteException,
RemoteException { }
public void ejbActivate() throws RemoteException { }
public void ejbPassivate() throws RemoteException { }
public void ejbLoad() throws RemoteException
{
String customerID;
java.sql.Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds =
(DataSource)ctx.lookup("jdbc/JdbcHelloWorldAppGlobal");
conn = ds.getConnection();
stmt = conn.createStatement();
customerID = (String) m_ctx.getPrimaryKey();
String query = "select username, email, address from
Customer where userid ='" + customerID
+ "'";
System.out.println("Executing query : "+query);
rs = stmt.executeQuery(query);
if ((rs !=null) && rs.next()) {
UserName = rs.getString("username");
Email = rs.getString("email");
address = rs.getString("address");
}
else
{
throw new RemoteException(
"EntityBean.ejbLoad: Unable to load record with
customerID ="
+customerID);
}
}
catch(javax.naming.NamingException n)
{
n.printStackTrace();
throw new java.rmi.RemoteException("Lookup Failed");
}
catch (java.sql.SQLException e) {
e.printStackTrace();
throw new java.rmi.RemoteException(" SQL exception", e);
}
finally {
try {
rs.close();
stmt.close();
conn.close();
}
catch ( SQLException e ) {
e.printStackTrace();
throw new RemoteException ("SQL exception", e);
}
}
}
public void ejbStore() throws RemoteException { }
public EntityImpl () { }
public String getUserName() throws RemoteException
{
return UserName;
}
public String getEmail() throws RemoteException
{
return Email;
}
public String getAddress() throws RemoteException
{
return address;
}
}
bean.properties
#tBean properties
# BeanType
#
# Specify one of session or entity as well as the relevant
# properties below. Properties in this file for the "other" type
# of bean will be ignored.
#
# { SESSION, ENTITY }
BeanType=ENTITY
# GUID (type:STRING)
#
GUID={9BACF990-1EAE-11D3-BC9D-00104BEC5BF6}
#######################################################################
# DeploymentDescriptors
#
# VersionNumber (type:DWORD)
VersionNumber=1
# BeanHomeName
#
# This is the name used to register the bean in JNDI. The name is
# always relative; the JNDI root prefix is specified elsewhere.
#
BeanHomeName=EntityExample/EntityHome
# EnterpriseBeanClassName
# HomeInterfaceClassName
# RemoteInterfaceClassName
#
# In order to boostrap from this file, the user must specify these 3
# mandatory classfiles. Use the java class name format, i.e
# "hello.HelloImpl"
#
EnterpriseBeanClassName=ejb.entityexample.EntityImpl
HomeInterfaceClassName=ejb.entityexample.EntityHome
RemoteInterfaceClassName=ejb.entityexample.EntityRemote
PrimaryKeyClassName=java.lang.String
# for entity beans, mandatory property
IsReentrant=true
#######################################################################
# ControlDescriptor
#
# The MethodName must always be specified, and should be the
# special string "DEFAULT" to indicate that the control
# descriptor changes apply to all methods.
#
# Multiple control descriptors can be specified by
# increasing the index, i.e. ControlDescriptor.1.MethodName=foobar
# Indicies cannot be skipped.
#
ControlDescriptor.0.MethodName=DEFAULT
# IsolationLevel
#
# { TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED,
# TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE }
#
ControlDescriptor.0.IsolationLevel=TRANSACTION_SERIALIZABLE
# RunAsMode
#
# { CLIENT_IDENTITY, SPECIFIED_IDENTITY, SYSTEM_IDENTITY }
#
ControlDescriptor.0.RunAsMode=CLIENT_IDENTITY
# TransactionAttribute
#
# { TX_BEAN_MANAGED, TX_MANDATORY, TX_NOT_SUPPORTED, TX_REQUIRED,
# TX_REQUIRES_NEW, TX_SUPPORTS }
#
ControlDescriptor.0.TransactionAttribute=TX_REQUIRED
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".