Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

john d

Greenhorn
+ Follow
since Jul 11, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by john d

I'm writing this RMI program(s) and successfully started RMIRegistry and Server, when I try to start the Client (on the same machine as Server) I get this null pointer exception on a remote method call. getSegment is a method within one of the Impl's that are being called remotely from the client.
I've a non-RMI version of the program(s) and it works fine. What could cause this exception? method not being reference correctly?
I've also included the codes for server, client and Impl at the bottom of this message!
thank you in advacned for any tips or ideas?
C:\java\projects\seg_api_rmi>java -cp c:\java\projects\seg_api_rmi -Djava.rmi.server.codebase=file:\c:\java\projects\seg_api_rmi\ -Djava.security.policy=file:\c:\java\projects\seg_api_rmi\wideopen.policy DemoSegmentClient 127.0.0.1
Exception in thread "main" java.lang.NullPointerException
at DemoSegmentImpl.getSegment(DemoSegmentImpl.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
60)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:701)
at java.lang.Thread.run(Thread.java:536)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at DemoSegmentImpl_Stub.getSegment(Unknown Source)
at DemoSegmentClient.<init>(DemoSegmentClient.java:29)
at DemoSegmentClient.main(DemoSegmentClient.java:47)

Client: DemoSegmentClient.java
import java.rmi.*;
import java.net.MalformedURLException;
import java.util.Locale;
import java.text.NumberFormat;
public class DemoSegmentClient {
private DemoSegment ds;
public DemoSegmentClient() {
int y = 0;
int hseKey = 0;
long start = 0, end = 0;
try {
//bind server object to object in client
ds = (DemoSegment)Naming.lookup("rmi://127.0.0.1:1099/DemoSegment");
// set start time
start = System.currentTimeMillis();
y = ds.getSegment(Integer.toString(hseKey));
System.out.println("Value returned is " + y);
// set the end time
end = System.currentTimeMillis();
System.out.println("The elpased time : "+(end - start));
}
catch (MalformedURLException malformedException) {
System.err.println("Bad URL: " + malformedException);
}
catch (NotBoundException notBoundException) {
System.err.println("Not Bound: " + notBoundException);
}
catch (RemoteException remoteException) {
System.err.println("Remote Exception: " + remoteException);
}
}
public static void main (String[] argv) {
new DemoSegmentClient();
}
}
Server: DemoSegmentServer
import java.io.IOException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.net.MalformedURLException;
public class DemoSegmentServer {
// public No-argument constructor
public DemoSegmentServer() {
}
public static void main(String args[]) {
new DemoSegmentServer();
DemoSegment bm = null;
try {
// Create a BankManager object
bm = new DemoSegmentImpl();
// Export it to RMI
UnicastRemoteObject.exportObject( bm );
}
catch (RemoteException remoteException) {
System.err.println("Failure during object export to RMI: " + remoteException);
}
// Register an external name for the service
try {
Naming.rebind("//localhost/DemoSegment", bm);
}
catch (RemoteException remoteException) {
System.err.println("Failure during Name registration: " + remoteException);
}
catch (MalformedURLException malformedException) {
System.err.println("Failure during Name registration: " + malformedException);
}
System.out.println("Server started.");
System.out.println("Enter <CR> to end.");
try {
int i = System.in.read();
}
catch (IOException ioException) {
}
System.exit(0);
}
}

Impl: DemoSegmentImpl.java
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.pool.*;
import oracle.jdbc.OracleConnection;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class DemoSegmentImpl implements DemoSegment {
private OracleConnectionPoolDataSource myDataSource = null; // Connection Pool Data Source
private OraclePooledConnection myPooledConnection = null; // Pooled Connection
private SegmentBeanImpl segBean = null;
private int segScheme = 1;
// Default constructor
//
public void DemoSegment() throws java.rmi.RemoteException {
// Defualt connection here
//
try {
// Create Oracle DataSource Instance
myDataSource = new OracleConnectionPoolDataSource();
// Set connection parameters
<connection parameters ...>
// Get Pooled Connection
myPooledConnection = (OraclePooledConnection)myDataSource.getPooledConnection();
// Enable Explicit Caching on Pooled Connection
myPooledConnection.setStatementCacheSize(5);
myPooledConnection.setImplicitCachingEnabled(true);
}
catch(SQLException e) {
System.out.println("Error Logging in to Oracle: " + e.getMessage());
System.exit(1);
//throw new Exception("Error Logging in to Oracle: " + e.getMessage());
}
// Set the default seg scheme
//
segScheme = 1;
// Create the segment bean
//
segBean = new SegmentBeanImpl();
segBean.setPooledConnection(myPooledConnection);
UnicastRemoteObject.exportObject(segBean);
}
// Other constructor
//
public void DemoSegment(String jdbcDriver,
String dbUserName,
String dbPassword,
int segmentationScheme) throws java.rmi.RemoteException {
try {
// Create Oracle DataSource Instance
myDataSource = new OracleConnectionPoolDataSource();
// Set connection parameters
<connection parameters ...>
// Get Pooled Connection
myPooledConnection = (OraclePooledConnection)myDataSource.getPooledConnection();
// Enable Explicit Caching on Pooled Connection
myPooledConnection.setStatementCacheSize(5);
myPooledConnection.setExplicitCachingEnabled(true);
}
catch(SQLException e) {
System.out.println("Error Logging in to Oracle: " + e.getMessage());
System.exit(1);
//throw new Exception("Error Logging in to Oracle: " + e.getMessage());
}
// Create the segment bean
//
segBean = new SegmentBeanImpl();
segBean.setPooledConnection(myPooledConnection);
UnicastRemoteObject.exportObject(segBean);
}

// Explicit cleanup method
//
public void cleanupDemoSegment() throws java.rmi.RemoteException {
// Release Oracle resouces
//
try {
myPooledConnection.close();
}
catch (SQLException e) {} // ignore
}

public int getSegment(String houseKey) throws java.rmi.RemoteException {
return( segBean.getSegmentBean(houseKey, segScheme));
}
}
Impl: SegmentBeanImpl.java
import java.io.*;
import java.sql.*;
import javax.sql.*;
import oracle.jdbc.pool.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.OracleConnection;
import java.rmi.RemoteException;
/**
* Segment access bean
*/
public class SegmentBeanImpl implements Serializable, SegmentBean {
private OraclePooledConnection pooledconnection;
private static String segmentSelect = "<SELECT SOMETHING HERE!>";

/**
* Sets the dataSource property value.
*/
public void setPooledConnection(OraclePooledConnection pooledconnection) {
this.pooledconnection = pooledconnection;
}
/**
* Returns a segment for the input house and segment scheme.
* ?? What to return if no corresponding record found??
*/
public int getSegmentBean(String houseKey, int segScheme)
{
// Physical connection
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int seg = -1;
// Get segment for this house
//
try {
// Get Physical Connection from OraclePooledConnection passed in from DemoSegment
conn = (this.pooledconnection).getConnection();
pstmt = conn.prepareStatement(segmentSelect);
pstmt.setString(1, houseKey);
pstmt.setInt(2, segScheme);
rs = pstmt.executeQuery();
if ( rs.next() ) { // fetch first/only row
seg = rs.getInt(1);
} else {
System.out.println("No Rows for housekey " + houseKey + " ,segScheme " + segScheme);
}
}
catch (SQLException se) {
System.out.println("SegmentBeanImpl.getSegment: SQLExecption occurred: " + se.getMessage());
}
finally {
try {
if (conn != null) {conn.close();}
if (rs != null) {rs.close();}
if (pstmt != null) {pstmt.close();
}
} catch (SQLException se) {} //ignore
}
return seg;
}
}
18 years ago
I'm writing this RMI program(s) and successfully started RMIRegistry and Server, when I try to start the Client (on the same machine as Server) I get this null pointer exception on a remote method call. getSegment is a method within one of the Impl's that are being called remotely from the client.
I've a non-RMI version of the program(s) and it works fine. What could cause this exception? method not being reference correctly?
I've also included the codes for server, client and Impl at the bottom of this message!
thank you in advacned for any tips or ideas?
C:\java\projects\seg_api_rmi>java -cp c:\java\projects\seg_api_rmi -Djava.rmi.server.codebase=file:\c:\java\projects\seg_api_rmi\ -Djava.security.policy=file:\c:\java\projects\seg_api_rmi\wideopen.policy DemoSegmentClient 127.0.0.1
Exception in thread "main" java.lang.NullPointerException
at DemoSegmentImpl.getSegment(DemoSegmentImpl.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
60)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:701)
at java.lang.Thread.run(Thread.java:536)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at DemoSegmentImpl_Stub.getSegment(Unknown Source)
at DemoSegmentClient.<init>(DemoSegmentClient.java:29)
at DemoSegmentClient.main(DemoSegmentClient.java:47)

Client: DemoSegmentClient.java
import java.rmi.*;
import java.net.MalformedURLException;
import java.util.Locale;
import java.text.NumberFormat;
public class DemoSegmentClient {
private DemoSegment ds;
public DemoSegmentClient() {
int y = 0;
int hseKey = 0;
long start = 0, end = 0;
try {
//bind server object to object in client
ds = (DemoSegment)Naming.lookup("rmi://127.0.0.1:1099/DemoSegment");
// set start time
start = System.currentTimeMillis();
y = ds.getSegment(Integer.toString(hseKey));
System.out.println("Value returned is " + y);
// set the end time
end = System.currentTimeMillis();
System.out.println("The elpased time : "+(end - start));
}
catch (MalformedURLException malformedException) {
System.err.println("Bad URL: " + malformedException);
}
catch (NotBoundException notBoundException) {
System.err.println("Not Bound: " + notBoundException);
}
catch (RemoteException remoteException) {
System.err.println("Remote Exception: " + remoteException);
}
}
public static void main (String[] argv) {
new DemoSegmentClient();
}
}
Server: DemoSegmentServer
import java.io.IOException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.net.MalformedURLException;
public class DemoSegmentServer {
// public No-argument constructor
public DemoSegmentServer() {
}
public static void main(String args[]) {
new DemoSegmentServer();
DemoSegment bm = null;
try {
// Create a BankManager object
bm = new DemoSegmentImpl();
// Export it to RMI
UnicastRemoteObject.exportObject( bm );
}
catch (RemoteException remoteException) {
System.err.println("Failure during object export to RMI: " + remoteException);
}
// Register an external name for the service
try {
Naming.rebind("//localhost/DemoSegment", bm);
}
catch (RemoteException remoteException) {
System.err.println("Failure during Name registration: " + remoteException);
}
catch (MalformedURLException malformedException) {
System.err.println("Failure during Name registration: " + malformedException);
}
System.out.println("Server started.");
System.out.println("Enter <CR> to end.");
try {
int i = System.in.read();
}
catch (IOException ioException) {
}
System.exit(0);
}
}

Impl: DemoSegmentImpl.java
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.pool.*;
import oracle.jdbc.OracleConnection;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class DemoSegmentImpl implements DemoSegment {
private OracleConnectionPoolDataSource myDataSource = null; // Connection Pool Data Source
private OraclePooledConnection myPooledConnection = null; // Pooled Connection
private SegmentBeanImpl segBean = null;
private int segScheme = 1;
// Default constructor
//
public void DemoSegment() throws java.rmi.RemoteException {
// Defualt connection here
//
try {
// Create Oracle DataSource Instance
myDataSource = new OracleConnectionPoolDataSource();
// Set connection parameters
<connection parameters ...>
// Get Pooled Connection
myPooledConnection = (OraclePooledConnection)myDataSource.getPooledConnection();
// Enable Explicit Caching on Pooled Connection
myPooledConnection.setStatementCacheSize(5);
myPooledConnection.setImplicitCachingEnabled(true);
}
catch(SQLException e) {
System.out.println("Error Logging in to Oracle: " + e.getMessage());
System.exit(1);
//throw new Exception("Error Logging in to Oracle: " + e.getMessage());
}
// Set the default seg scheme
//
segScheme = 1;
// Create the segment bean
//
segBean = new SegmentBeanImpl();
segBean.setPooledConnection(myPooledConnection);
UnicastRemoteObject.exportObject(segBean);
}
// Other constructor
//
public void DemoSegment(String jdbcDriver,
String dbUserName,
String dbPassword,
int segmentationScheme) throws java.rmi.RemoteException {
try {
// Create Oracle DataSource Instance
myDataSource = new OracleConnectionPoolDataSource();
// Set connection parameters
<connection parameters ...>
// Get Pooled Connection
myPooledConnection = (OraclePooledConnection)myDataSource.getPooledConnection();
// Enable Explicit Caching on Pooled Connection
myPooledConnection.setStatementCacheSize(5);
myPooledConnection.setExplicitCachingEnabled(true);
}
catch(SQLException e) {
System.out.println("Error Logging in to Oracle: " + e.getMessage());
System.exit(1);
//throw new Exception("Error Logging in to Oracle: " + e.getMessage());
}
// Create the segment bean
//
segBean = new SegmentBeanImpl();
segBean.setPooledConnection(myPooledConnection);
UnicastRemoteObject.exportObject(segBean);
}

// Explicit cleanup method
//
public void cleanupDemoSegment() throws java.rmi.RemoteException {
// Release Oracle resouces
//
try {
myPooledConnection.close();
}
catch (SQLException e) {} // ignore
}

public int getSegment(String houseKey) throws java.rmi.RemoteException {
return( segBean.getSegmentBean(houseKey, segScheme));
}
}
Impl: SegmentBeanImpl.java
import java.io.*;
import java.sql.*;
import javax.sql.*;
import oracle.jdbc.pool.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.OracleConnection;
import java.rmi.RemoteException;
/**
* Segment access bean
*/
public class SegmentBeanImpl implements Serializable, SegmentBean {
private OraclePooledConnection pooledconnection;
private static String segmentSelect = "<SELECT SOMETHING HERE!>";

/**
* Sets the dataSource property value.
*/
public void setPooledConnection(OraclePooledConnection pooledconnection) {
this.pooledconnection = pooledconnection;
}
/**
* Returns a segment for the input house and segment scheme.
* ?? What to return if no corresponding record found??
*/
public int getSegmentBean(String houseKey, int segScheme)
{
// Physical connection
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int seg = -1;
// Get segment for this house
//
try {
// Get Physical Connection from OraclePooledConnection passed in from DemoSegment
conn = (this.pooledconnection).getConnection();
pstmt = conn.prepareStatement(segmentSelect);
pstmt.setString(1, houseKey);
pstmt.setInt(2, segScheme);
rs = pstmt.executeQuery();
if ( rs.next() ) { // fetch first/only row
seg = rs.getInt(1);
} else {
System.out.println("No Rows for housekey " + houseKey + " ,segScheme " + segScheme);
}
}
catch (SQLException se) {
System.out.println("SegmentBeanImpl.getSegment: SQLExecption occurred: " + se.getMessage());
}
finally {
try {
if (conn != null) {conn.close();}
if (rs != null) {rs.close();}
if (pstmt != null) {pstmt.close();
}
} catch (SQLException se) {} //ignore
}
return seg;
}
}
18 years ago
you need to put "permission" in front of the call like this!
grant {
// Allow everything for now
permission java.security.AllPermission;
};
hope it helps
18 years ago
its most likely will be over the internet. I'm reading on web services, it sounds like web services is a combination of JMS, EJB, Servlet, and all the other XML APIs. I got the Java Web Services Tutorial and exmaples, from it I've noticed that all the client calls are through JSP / servlet. Is it possible to have clients calling a client class locally and it would look up the registry to get to the server for request ? any other useful tutorials out there on the web?
thanks
18 years ago
I've downloaded the latest version of Oracle JDBC Driver v9.2 and tried the new statement caching feature and see how it works within connection pooling. I wrote this class that basically would get a connection from pool and loop throught a query 10 times (without statement caching) and return the elapsed time, then the do the same with statement caching.
How I have been keep getting ;
C:\java\projects\ora_pool_stmt_cache>java stmt_cache_conn_pool
Elapsed Time without Statement Caching :150
Error connecting to database :java.sql.SQLException: Statement Caching cannot be enabled for this logical connection.
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.pool.*;
import oracle.jdbc.OracleConnection;
public class stmt_cache_conn_pool {
public static void main(String[] args) {
OracleConnectionCacheImpl myConnectionPool=null;
OracleConnectionPoolDataSource myDataSource=null;
Connection ora_conn = null;
Connection sc_imp_ora_conn = null;
PreparedStatement ora_stmt = null;
ResultSet ora_rs = null;
String SQL_stmt = "select * from table1";
long start = 0, end = 0;
int x = 0;
try {
//Create oracle datasource instance
myDataSource = new OracleConnectionPoolDataSource();
// Set connection parameters
myDataSource.setDriverType("thin");
myDataSource.setNetworkProtocol("tcp");
myDataSource.setServerName("myServer");
myDataSource.setDatabaseName("myDB");
myDataSource.setPortNumber(1521);
myDataSource.setUser("user");
myDataSource.setPassword("password");
//Create & configure pool
myConnectionPool = new OracleConnectionCacheImpl(myDataSource);
myConnectionPool.setMaxLimit(10);
myConnectionPool.setMinLimit(3);
myConnectionPool.setCacheScheme(OracleConnectionCacheImpl.FIXED_RETURN_NULL_SCHEME);
ora_conn = myConnectionPool.getConnection();
// Prepare, Execute Query without Statement Caching
// Set Start Time
start = System.currentTimeMillis();
// Loop, prepare and execute the query 10 times
for (int i = 0;i < 10;i++) {
ora_stmt = ora_conn.prepareStatement(SQL_stmt);
ora_rs = ora_stmt.executeQuery();
ora_rs.close();
ora_stmt.close();
}
// Set End Time
end = System.currentTimeMillis();
// Display the duration
System.out.println("Elapsed Time without Statement Caching :"+((int) (end-start)));
// close connection for non-statement caching
ora_conn.close();

sc_imp_ora_conn = (OracleConnection)myConnectionPool.getConnection();
// Prepare, Execute Query with Implicit Statement Caching
// Set Start Time
// Set the Statement cache size to 5
((OracleConnection) sc_imp_ora_conn).setStatementCacheSize(5);
// Enable Implicit caching
((OracleConnection) sc_imp_ora_conn).setImplicitCachingEnabled(true);
start = System.currentTimeMillis();
// Loop, prepare and execute the query 10 times
for (int i = 0;i < 10;i++) {
ora_stmt = (OraclePreparedStatement) sc_imp_ora_conn.prepareStatement(SQL_stmt);
ora_rs = ora_stmt.executeQuery();
ora_rs.close();
ora_stmt.close();
}
// Set End Time
end = System.currentTimeMillis();
// Display the duration
System.out.println("Elapsed Time with Implicit Statement Caching:"+((int) (end-start)));
sc_imp_ora_conn.close();
}
catch (Exception ex) {
System.out.println("Error connecting to database :"+ex);
}
// close physical database (pooled) connections
try {
if (myConnectionPool != null) myConnectionPool.close();
} catch (SQLException SQLEx) {
System.out.println("Error disconnecting to database :"+SQLEx);
}
}
}
I've done some applet, servlet and JSP work. Now I want to write a program (or service if you will) that sits on top of a database. This program will receive request with parameter to look up the database (as it executes a SQL stmt) and then return the query result back to the requester.
This does not need a presentation layer, so no need for servlet or JSP(it would add overheads for the app server and alike).
I started look into RMI, JINI and even EJB. But they seems to have their overheads as well. All I need is a program that runs like service (never ends) and able to execute from remote calling froma client or some sort.
I know this is very vague, but I'm in the very early design stage!
18 years ago
I'm running JBoss 3.0.1 with Tomcat 4.0.4 bundle. I have successfully deployed a EJB to Jboss and created 2 clients (java & JSP client).
For some reasons, I'm able to run the java client but when I try the JSP client (served by Tomcat) I get this error message
javax.servlet.ServletException: Name greetings is not bound in this Context
Below is the code for the 2 clients & web.xml
<----------- jsp client -------------->
<%@ page import="javax.naming.*,
java.util.*,
java.util.Hashtable,
javax.rmi.PortableRemoteObject,
com.stardeveloper.ejb.session.*"%>
<%
long t1 = System.currentTimeMillis();
InitialContext ctx = new InitialContext();
Object ref = ctx.lookup("ejb/First");
FirstHome home = (FirstHome) PortableRemoteObject.narrow (ref, FirstHome.class);
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
%>
<html>
<head>
<style>p { font-family:Verdana;font-size:12px; }</style>
</head>
<body>
<p>Message received from bean = "<%= time %>".<br>Time taken :
<%= (t2 - t1) %> ms.</p>
</body>
</html>

<----------- java client ------------->
import javax.naming.*;
import com.stardeveloper.ejb.session.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
import com.stardeveloper.ejb.session.*;
class firstEJBclient {
public static void main(String[] args) {
try {
long t1 = System.currentTimeMillis();
InitialContext ctx = new InitialContext();
System.out.println("Got CONTEXT");

Object ref = ctx.lookup("ejb/First");
System.out.println("Got REFERENCE");

FirstHome home = (FirstHome) PortableRemoteObject.narrow (ref, FirstHome.class);
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
System.out.println("Message received from bean = "+time+" Time taken : "+(t2 - t1)+" ms.");
}
catch (Exception e) {
System.out.println(e.toString());
}
}
}

<----------------- web.xml -------------------->
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<session-config>
<session-timeout>
1800
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
firstEJB2.jsp
</welcome-file>
</welcome-file-list>
<ejb-ref>
<description>A reference to an entity bean</description>
<ejb-ref-name>ejb/First</ejb-ref-name>
<ejb-ref-type>Stateless</ejb-ref-type>
<home>com.stardeveloper.ejb.session.FirstHome</home>
<remote>com.stardeveloper.ejb.session.First</remote>
</ejb-ref>
</web-app>
Why is it not bound?
18 years ago
I'm running JBoss 3.0.1 with Tomcat 4.0.4 bundle. I have successfully deployed a EJB to Jboss and created 2 clients (java & JSP client).
For some reasons, I'm able to run the java client but when I try the JSP client (served by Tomcat) I get this error message
javax.servlet.ServletException: Name greetings is not bound in this Context
Below is the code for the 2 clients & web.xml
<----------- jsp client -------------->
<%@ page import="javax.naming.*,
java.util.*,
java.util.Hashtable,
javax.rmi.PortableRemoteObject,
com.stardeveloper.ejb.session.*"%>
<%
long t1 = System.currentTimeMillis();
InitialContext ctx = new InitialContext();
Object ref = ctx.lookup("ejb/First");
FirstHome home = (FirstHome) PortableRemoteObject.narrow (ref, FirstHome.class);
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
%>
<html>
<head>
<style>p { font-family:Verdana;font-size:12px; }</style>
</head>
<body>
<p>Message received from bean = "<%= time %>".<br>Time taken :
<%= (t2 - t1) %> ms.</p>
</body>
</html>

<----------- java client ------------->
import javax.naming.*;
import com.stardeveloper.ejb.session.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
import com.stardeveloper.ejb.session.*;
class firstEJBclient {
public static void main(String[] args) {
try {
long t1 = System.currentTimeMillis();
InitialContext ctx = new InitialContext();
System.out.println("Got CONTEXT");

Object ref = ctx.lookup("ejb/First");
System.out.println("Got REFERENCE");

FirstHome home = (FirstHome) PortableRemoteObject.narrow (ref, FirstHome.class);
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
System.out.println("Message received from bean = "+time+" Time taken : "+(t2 - t1)+" ms.");
}
catch (Exception e) {
System.out.println(e.toString());
}
}
}

<----------------- web.xml -------------------->
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<session-config>
<session-timeout>
1800
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
firstEJB2.jsp
</welcome-file>
</welcome-file-list>
<ejb-ref>
<description>A reference to an entity bean</description>
<ejb-ref-name>ejb/First</ejb-ref-name>
<ejb-ref-type>Stateless</ejb-ref-type>
<home>com.stardeveloper.ejb.session.FirstHome</home>
<remote>com.stardeveloper.ejb.session.First</remote>
</ejb-ref>
</web-app>
Why is it not bound?
ku916
I'm running JBoss 3.0.1 with Tomcat 4.0.4 bundle. I have successfully deployed a EJB to Jboss and created 2 clients (java & JSP client).
For some reasons, I'm able to run the java client but when I try the JSP client (served by Tomcat) I get this error message
javax.servlet.ServletException: Name greetings is not bound in this Context
Below is the code for the 2 clients & web.xml
<----------- jsp client -------------->
<%@ page import="javax.naming.*,
java.util.*,
java.util.Hashtable,
javax.rmi.PortableRemoteObject,
com.stardeveloper.ejb.session.*"%>
<%
long t1 = System.currentTimeMillis();
InitialContext ctx = new InitialContext();
Object ref = ctx.lookup("ejb/First");
FirstHome home = (FirstHome) PortableRemoteObject.narrow (ref, FirstHome.class);
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
%>
<html>
<head>
<style>p { font-family:Verdana;font-size:12px; }</style>
</head>
<body>
<p>Message received from bean = "<%= time %>".<br>Time taken :
<%= (t2 - t1) %> ms.</p>
</body>
</html>

<----------- java client ------------->
import javax.naming.*;
import com.stardeveloper.ejb.session.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
import com.stardeveloper.ejb.session.*;
class firstEJBclient {
public static void main(String[] args) {
try {
long t1 = System.currentTimeMillis();
InitialContext ctx = new InitialContext();
System.out.println("Got CONTEXT");

Object ref = ctx.lookup("ejb/First");
System.out.println("Got REFERENCE");

FirstHome home = (FirstHome) PortableRemoteObject.narrow (ref, FirstHome.class);
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
System.out.println("Message received from bean = "+time+" Time taken : "+(t2 - t1)+" ms.");
}
catch (Exception e) {
System.out.println(e.toString());
}
}
}

<----------------- web.xml -------------------->
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<session-config>
<session-timeout>
1800
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
firstEJB2.jsp
</welcome-file>
</welcome-file-list>
<ejb-ref>
<description>A reference to an entity bean</description>
<ejb-ref-name>ejb/First</ejb-ref-name>
<ejb-ref-type>Stateless</ejb-ref-type>
<home>com.stardeveloper.ejb.session.FirstHome</home>
<remote>com.stardeveloper.ejb.session.First</remote>
</ejb-ref>
</web-app>
Why is it not bound?
18 years ago
JSP