Higor Zardo

Ranch Hand
+ Follow
since Feb 16, 2008
Merit badge: grant badges
For More
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 Higor Zardo

me toooooooooooooooooooooooooooooooooo
13 years ago
Ok, thank you.

Higor
Someone know how to setting jndi properties inside Eclipse?

With Glassfish and Eclipse we need just to add appserver-rt.jar to our Build Path. This JAR is from the Glassfish 2 library directory and contains a customized jndi.properties file that will allow us to connect directly to the Glassfish 2 JNDI context automatically. But, and with JBOSS?

Thank you if someone can help me.
Higor.
And for JBOSS, someone know how to setting jndi properties inside Eclipse?

Thank youu,
Higor
What did you do to setting jndi properties inside Eclipse?
Please, if you can help me I thank you.

Thank you,
Higor
Congratulations!!!

Mikalai is the best /o/
13 years ago
is SCBCD exam questions about concepts more than implementation?
13 years ago
Hello ranchers,
I'm trying to execute this code below in Eclipse 3.4.1 + Jboss 5.0 but problems heppes.

I have this simple code:

My Bean...

package test;

import javax.ejb.Stateless;

/**
* Session Bean implementation class StatelessCalculator
*/
@Stateless
public class StatelessCalculator implements StatelessCalculatorLocal {

/**
* Default constructor.
*/
public StatelessCalculator() {
// TODO Auto-generated constructor stub
}

public double add(double a, double b)
{
return a + b;
}


}



My Remote...


package test;
import javax.ejb.Remote;

@Remote
public interface StatelessCalculatorLocal {
public double add(double a, double b);
}



My simple Client...

package test;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class ClientCalc {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println("test");
try {
Context jndiContext = new InitialContext();
Object ref = jndiContext.lookup("StatelessCalculator");
StatelessCalculatorLocal calc = (StatelessCalculatorLocal) PortableRemoteObject.narrow(ref, StatelessCalculatorLocal.class);
System.out.println("4 + 3 = " + calc.add(4, 3));
}
catch (NamingException ne) {
ne.printStackTrace();
}

}

}



And when execute the client like Java Application I have it:

test
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at test.ClientCalc.main(ClientCalc.java:20)



Thank youuu,
Higor
13 years ago
Hello friends Christophe Verré and Nitin!!!
Thank you for help me.

Well, I tried without parameter:

package exemplo.Stateless;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.*;
/**
*
* @author Higor
*/
public class HelloUserClient {
//@EJB
public static HelloUserBeanBean helloUser;

public static void main(String[] args) {

//helloUser.sayHello("Curious George");
System.out.println("Invoked EJB successfully .. see server console for output");

Hashtable ht=new Hashtable();
ht.put("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
ht.put("org.omg.CORBA.ORBInitialHost", "localhost");
ht.put("org.omg.CORBA.ORBInitialPort","3700");
//Context ctx=new InitialContext(ht);

try {
Context ctx=new InitialContext();
helloUser = (HelloUserBeanBean) ctx.lookup("HelloUserBeanBean");
helloUser.sayHello("Billy Bob");
System.out.println("testeeeeeeeeeee");
}
catch(Exception ex) {
ex.printStackTrace();
}

}
}



And I received some errors yet:

init:
deps-jar:
Compiling 1 source file to C:\Users\Higor\Documents\NetBeansProjects\EJBModule2\build\jar
Note: C:\Users\Higor\Documents\NetBeansProjects\EJBModule2\src\java\exemplo\Stateless\HelloUserClient.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
compile-single:
run-main:
Invoked EJB successfully .. see server console for output
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at exemplo.Stateless.HelloUserClient.main(HelloUserClient.java:32)
BUILD SUCCESSFULLY (tempo total: 0 segundos)



Thank youuu,
Higor
Hello Nitin,
how are you?
Well, I tested it but a have had more problems.

I did it:

package exemplo.Stateless;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.*;
/**
*
* @author Higor
*/
public class HelloUserClient {
//@EJB
public static HelloUserBeanBean helloUser;

public static void main(String[] args) {

//helloUser.sayHello("Curious George");
System.out.println("Invoked EJB successfully .. see server console for output");

Hashtable ht=new Hashtable();
ht.put("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
ht.put("org.omg.CORBA.ORBInitialHost", "localhost");
ht.put("org.omg.CORBA.ORBInitialPort","3700");
//Context ctx=new InitialContext(ht);

try {
//InitialContext ctx = new InitialContext();
Context ctx=new InitialContext(ht);
//HelloUserBeanBean bean = (HelloUserBeanBean) ctx.lookup("ejb/HelloUserBeanBeanJNDI");
helloUser = (HelloUserBeanBean) ctx.lookup("ejb/HelloUserBeanBeanJNDI");
helloUser.sayHello("Billy Bob");
//System.out.println(result);
System.out.println("testeeeeeeeeeee");
}
catch(Exception ex) {
ex.printStackTrace();
}

}
}


And I received it...


init:
deps-jar:
compile-single:
run-main:
Invoked EJB successfully .. see server console for output
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at exemplo.Stateless.HelloUserClient.main(HelloUserClient.java:32)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
... 4 more
BUILD SUCCESSFULLY (tempo total: 0 segundos)




It is very dificult to execute yet. If anyone can help me thank you.

Thank youuu,
Higor
Hello friends,
where do you put the code?
I put inside client. It's like:

package exemplo.Stateless;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
/**
*
* @author Higor
*/
public class HelloUserClient {
//@EJB
public static HelloUserBeanBean helloUser;

public static void main(String[] args) {

//helloUser.sayHello("Curious George");
System.out.println("Invoked EJB successfully .. see server console for output");
Properties props=new Properties();
props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");//ur server ip
props.setProperty("org.omg.CORBA.ORBInitialPort","3700"); //default is 3700

try {
InitialContext ctx = new InitialContext();
HelloUserBeanBean bean = (HelloUserBeanBean) ctx.lookup("ejb/HelloUserBeanBeanJNDI");
helloUser.sayHello("Billy Bob");
//System.out.println(result);
System.out.println("testeeeeeeeeeee");
}
catch(Exception ex) {
ex.printStackTrace();
}

}
}

The problem is that Properties dont exist and inside API Specification JEE it dont exist too.

Thank youuu,
Higor
Hello ranchers,
I have had problems with my code in Netbeans 6.5 with Glassfish.

I have the bean

package exemplo.Stateless;

import javax.ejb.Stateless;

/**
*
* @author Higor
*/
@Stateless
public class HelloUserBeanBean implements HelloUserBeanRemote {

public void sayHello(String name) {
System.out.println("Hello " + name + " welcome to EJB 3 In Action!");
}

}


I have the Remote....


package exemplo.Stateless;

import javax.ejb.Remote;

/**
*
* @author Higor
*/
@Remote
public interface HelloUserBeanRemote {
public void sayHello(String name);
}



And I have a test client that use JNDI...


public class HelloUserClient {
//@EJB
public static HelloUserBeanBean helloUser;

public static void main(String[] args) {

//helloUser.sayHello("Curious George");
System.out.println("Invoked EJB successfully .. see server console for output");

try {
InitialContext ctx = new InitialContext();
HelloUserBeanBean bean = (HelloUserBeanBean) ctx.lookup("ejb/HelloUserBeanBeanJNDI");
helloUser.sayHello("Billy Bob");
//System.out.println(result);
System.out.println("testeeeeeeeeeee");
}
catch(Exception ex) {
ex.printStackTrace();
}

}
}




Ok, but when I execute the client I have the follow errors.

Invoked EJB successfully .. see server console for output
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at exemplo.Stateless.HelloUserClient.main(HelloUserClient.java:25)
BUILD SUCCESSFULLY (tempo total: 0 segundos)


Seem JNDI problem.
Anyone can Help me please?

Thank youuu,
Higor
I would like to know it so!
How can I make a new EJB project in Eclipse or Netbeans and TEST if it's Ok.
Internet dont have nothing about it =/
It's terrible!!
Please, I'm trying to do a simple test EJB project in Netbeans 6.5 and Glassfish V2, but It is terrible.

Look... I just do It. First a created a project in New Project -> Java EE -> EJB Module. Ok!
In directory "Source Code Packeages" I created one package called "stateless" with yours two ejb. They are:

package stateless;

import javax.ejb.Stateless;

/**
*
* @author Higor
*/
@Stateless
public class TesteEJBBean implements TesteEJBRemote {

public String getMessage() {
return "Hello EJB World";
}

}


And the Remote:

package stateless;

import javax.ejb.Remote;

/**
*
* @author Higor
*/
@Remote
public interface TesteEJBRemote {

public java.lang.String getMessage();

}

In Enterprise Beans directory it have the same code of TesteEJBBean. I think Netbeans do it automaticaly, I dont remember if I put it there.

Ok,it's work!
But How can I try test it???

I tryed to put a simple java class in "Test Package" directory like it:

package Teste;
import javax.ejb.EJB;
import stateless.TesteEJBRemote;
/**
*
* @author Higor
*/
public class NewClass {
@EJB
private static TesteEJBRemote teste;

public static void main(String[] args) {
//System.out.println(teste.getMessage());
System.out.println("teste");
}
}

The compilation is Ok, but when I select it and select Execute option it have a error.

The compilation step I'm doing with all this classes is: Select the project and right mouse click and select BUILD.
Later I just select NewClass in Test Package directory and try Compile -> Execute.

Anyone can help me please??

Thank you a lot if you can help me!!!
Higor
Oreilly EJB book is not a simple book for begginers, believe it! ;/
It is hard, prefer other book IF you are really a beginer.