Trouble with client app
ckrum May 7, 2002 5:46 PMHi there,
I'm trying to use JBoss under a product called Panther for a test environment and I'm having some problems. I'm using the example "Interest" bean that comes with JBoss and my client code is as follows:
InterestButton.java -
import com.prolifics.jni.*;
import GetInterest;
public class InterestButton
extends ButtonHandlerAdapter
{
public int buttonActivate(FieldInterface fi,int item)
{
String interestValue = GetInterest.getInterest();
// Get CFunctions and ScreenInterface from FieldInterface
CFunctionsInterface c = fi.getCFunctions();
c.sm_n_putfield("interestOut",interestValue);
c.sm_n_putfield("errorOut",interestValue);
return 0;
}
}
GetInterest.java -
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import org.jboss.docs.interest.Interest;
import org.jboss.docs.interest.InterestHome;
public class GetInterest
{
/** This method does all the work. It creates an
instance of the Interest EJB on
the EJB server, and calls its
`calculateCompoundInterest()' method, then prints
the result of the calculation.
*/
public static String getInterest()
{
// Enclosing the whole process in a single `try'
// block is not an ideal way
// to do exception handling, but I don't want to
// clutter the program up
// with catch blocks
try
{
// Get a naming context
InitialContext jndiContext = new InitialContext
(System.getProperties());
System.out.println("Got context");
// Get a reference to the Interest Bean
Object ref = jndiContext.lookup
("interest/Interest");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home
// interface
InterestHome home = (InterestHome)
PortableRemoteObject.narrow(ref,
InterestHome.class);
// Create an Interest object from the Home
// interface
Interest interest = home.create();
// call the calculateCompoundInterest() method
// to do the calculation
return String.valueOf
(interest.calculateCompoundInterest(1000,
0.10, 2));
}
catch(Exception e)
{
return e.toString();
}
}
}
Whenever I activate the button that InterestButton is attached to I get a ClassCastException at the line -
InterestHome home = (InterestHome)
PortableRemoteObject.narrow(ref, InterestHome.class);
Any idea why?