This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Error In EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Error In EJB" Watch "Error In EJB" New topic
Author

Error In EJB

dhinakar Meenakshi Sundaram
Greenhorn

Joined: Mar 22, 2004
Posts: 3
Hi,
I am getting an Error while running an EJB client.
I am using an Container bean(StateLess)
This is the code i am using
--->
import java.awt.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.naming.Context;
import javax.naming.*;
import javax.ejb.*;
import java.rmi.*;
import javax.rmi.*;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
public class myClient extends JFrame
{
public static int w=500;
public static int h=95;
public static String str = "Polaris Welcomes You";
public static String value1, value2;
Container cnr;

JLabel lblNumber1, lblNumber2, lblResult;
JTextField txtNumber1, txtNumber2;
JButton butAdd;
public myClient()
{
super(str);
cnr = getContentPane();
cnr.setLayout(new GridLayout(3, 3, 2, 2));
lblNumber1 = new JLabel("Number 1:");
lblNumber2 = new JLabel("Number 2:");
lblResult = new JLabel("Result");
txtNumber1 = new JTextField(10);
txtNumber2 = new JTextField(10);
butAdd = new JButton("Add");
cnr.add(lblNumber1);
cnr.add(txtNumber1);
cnr.add(lblNumber2);
cnr.add(txtNumber2);
cnr.add(lblResult);
cnr.add(butAdd);
butAdd.addActionListener(new addEvent());
setSize(w, h);
show();
}

public static void main(String args[])
{
new myClient();
}

public class addEvent implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
int num1 = Integer.parseInt(txtNumber1.getText());
int num2 = Integer.parseInt(txtNumber2.getText());
try
{
Hashtable env = new Hashtable();
System.out.println("Hashtable env = new Hashtable()");
//env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
System.out.println("env.put(Context.INITIAL_CONTEXT_FACTORY, com.sun.jndi.cosnaming.CNCtxFactory)");
env.put(Context.PROVIDER_URL, "http://localhost:8080");
System.out.println("env.put(Context.PROVIDER_URL, http://localhost:8080)");
Context iContext = new InitialContext(env);
//Context iContext = new InitialContext();
System.out.println("Setting Initial Context(env)");
//Object obj = iContext.lookup("java:comp/env/ejb/myEJBClass");
//System.out.println("lookup(myEJBClass)");
Context myEnv = (Context)iContext.lookup("java:comp/env");
System.out.println("(Context)iContext.lookup(java:comp/env)");
Object obj = myEnv.lookup("ejb/myEJBClass");
System.out.println("myEnv.lookup(ejb/myEJBClass)");
myHome home = (myHome)PortableRemoteObject.narrow(obj, myHome.class);
System.out.println("(myHome)PortableRemoteObject.narrow(obj, myHome.class)");
myRemote remote = home.create();
System.out.println("home.create()");
int res = remote.myMethod(num1, num2);
System.out.println("remote.myMethod(num1, num2)");
lblResult.setText("Result Is: " + Integer.toString(res));
System.out.println("lblResult.setText(Result Is: + Integer.toString(res))");
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}
}
}
<--
Error Contents:
-->
javax.naming.ConfigurationException: http://localhost:8080 does not contain an IOR
javax.naming.ConfigurationException: http://localhost:8080 does not contain an IOR
at com.sun.jndi.cosnaming.CNCtx.getStringifiedIor(CNCtx.java:421)
at com.sun.jndi.cosnaming.CNCtx.initOrbAndRootContext(CNCtx.java:198)
at com.sun.jndi.cosnaming.CNCtx.<init>(CNCtx.java:69)
at com.sun.jndi.cosnaming.CNCtxFactory.getInitialContext(CNCtxFactory.java:32)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at myClient$addEvent.actionPerformed(myClient.java:69)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5134)
at java.awt.Component.processEvent(Component.java:4931)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1590)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
<--
Please help me to solve the problem...
Regards,
Dhinakar. M


dhinakar
Ramakrishna Allam
Ranch Hand

Joined: Mar 23, 2004
Posts: 34
I havent gone thru ur code fully . But , page 494 of the spec says that "An enterprise Bean must not use the AWT functionality to attempt to output information to a display, or to input information from a keyboard."
Edy Yu
Ranch Hand

Joined: Nov 21, 2000
Posts: 264
Your naming context provider's URL seems wrong. Double check the documentation.


<i><br />Sun Certified Programmer for Java 2 Platform (SCJP)<br />Sun Certified Developer for Java 2 Platform (SCJD)<br />Sun Certified Web Component Developer for Java2 Platform, Enterprise Edition (SCWCD)<br />Sun Certified Business Component Developer for Java2 Platform, Enterprise Edition (SCBCD)<br />Sun Certified Enterprise Architect for J2EE (SCEA)<br />IBM Certified Enterprise Developer, WebSphere Studio V5.0<br /></i>
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Originally posted by Ramakrishna Allam:
I havent gone thru ur code fully . But , page 494 of the spec says that "An enterprise Bean must not use the AWT functionality to attempt to output information to a display, or to input information from a keyboard."

Yes, you are right. But this is a just swing EJB client program, which is OK. The specs only forbids the use of IO/UI classes in the enterprise bean classes.
dhinakar Meenakshi Sundaram
Greenhorn

Joined: Mar 22, 2004
Posts: 3
F1 me... Radhakrishna / EDU / Kumar,
Thanks for the reply...
I have taken all the AWT related stuffs...
The errors are minimized but still i am getting the error.
Code-->
import javax.swing.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.*;
public class CalculatorClient extends JFrame
{
public CalculatorClient()
{
double dbl = 10.20;
try
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "http://localhost:8080");
Context ic = new InitialContext(env);
System.out.println("Executing...Context ic = new InitialContext()");
Object obj = ic.lookup("CalculatorJNDI");
System.out.println("Executing...Object obj = ic.lookup(CalculatorJNDI)");
CalculatorHome home = (CalculatorHome)PortableRemoteObject.narrow(obj, CalculatorHome.class);
System.out.println("Executing...CalculatorHome home = (CalculatorHome)PortableRemoteObject.narrow(obj, CalculatorHome.class)");
Calculator calc = home.create();
System.out.println("Executing...Calculator calc = home.create()");
double amt = calc.dollarToRs(dbl);
System.out.println("Executing...amt = calc.dollarToRs(dbl)");
System.out.println("Result(Rs.): " + String.valueOf(amt));
System.out.println("Executing...result.setText(Result(Rs.): + String.valueOf(amt))");
}
catch(Exception ex)
{
System.err.println("Executing...Caught an un UnExpected Exception !");
ex.printStackTrace();
}
}
public static void main(String args[])
{

new CalculatorClient();
}
}
Code<---
Error--->
Executing...Caught an un UnExpected Exception !
javax.naming.ConfigurationException: http://localhost:8080 does not contain an IOR
at com.sun.jndi.cosnaming.CNCtx.getStringifiedIor(CNCtx.java:421)
at com.sun.jndi.cosnaming.CNCtx.initOrbAndRootContextCNCtx.java:198)
at com.sun.jndi.cosnaming.CNCtx.<init>(CNCtx.java:69)
at com.sun.jndi.cosnaming.CNCtxFactory.getInitialContextCNCtxFactory.java:32)
at javax.naming.spi.NamingManager.getInitialContextNamingManager.java:6
62)
at javax.naming.InitialContext.getDefaultInitCtxInitialContext.java:243
)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at CalculatorClient.<init>(CalculatorClient.java:19)
at CalculatorClient.main(CalculatorClient.java:43)
Error<---
Help me
[ April 05, 2004: Message edited by: dhinakar Meenakshi Sundaram ]
[ April 05, 2004: Message edited by: dhinakar Meenakshi Sundaram ]
 
 
subject: Error In EJB
 
Similar Threads
calling a EJB from JSP in weblogic , please help me fast
Error in EJB
problem with client
Problem calling EJB deployed on websphere from Java Client
How to run a client...