Solved

problems with testing an ejb apps in eclipse ide?

Posted on 2004-04-19
10
2,181 Views
Last Modified: 2013-11-24
Hi! I tried to do a simple application in ejb.Its a stateless session bean that just print a hello message.
Im using the sun one application server and i deployed my ejb apps using the deploytool.Im using the
eclipse ide.

I write a test application:

                  Context initContext = new javax.naming.InitialContext();
                  String JNDIName = "java:comp/env/ejb/HelloBean";
                  System.out.println("looking");
                  Object objref = initContext.lookup(JNDIName);
                  HelloHome helloHome = (HelloHome)PortableRemoteObject.narrow(objref,
                                                                  HelloHome.class);
                  System.out.println("looked");
                  Hello hello = helloHome.create();
                  System.out.println("message   " + hello.getMessage());


and when i run it i got an error:

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



sun-ejb.jar.xml
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 EJB 2.1//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-ejb-jar_2_1-0.dtd">
<sun-ejb-jar>
  <enterprise-beans>
    <unique-id>1300025963</unique-id>
    <ejb>
      <ejb-name>HelloBean</ejb-name>
      <jndi-name>HelloBean</jndi-name>
      <pass-by-reference>false</pass-by-reference>
      <is-read-only-bean>false</is-read-only-bean>
      <refresh-period-in-seconds>-1</refresh-period-in-seconds>
      <cmt-timeout-in-seconds>0</cmt-timeout-in-seconds>
      <gen-classes>
        <remote-impl>simple.HelloBean_EJBObjectImpl</remote-impl>
        <remote-home-impl>simple.HelloBean_RemoteHomeImpl</remote-home-impl>
      </gen-classes>
      <session>
        <quick-checkpoint>true</quick-checkpoint>
      </session>
    </ejb>
  </enterprise-beans>
</sun-ejb-jar>


ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
  <display-name>Ejb1</display-name>
  <enterprise-beans>
    <session>
      <ejb-name>HelloBean</ejb-name>
      <home>simple.HelloHome</home>
      <remote>simple.Hello</remote>
      <ejb-class>simple.HelloBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>
      <security-identity>
        <use-caller-identity/>
      </security-identity>
    </session>
  </enterprise-beans>
</ejb-jar>

Any help? thanks.


raymond

0
Comment
Question by:rdy1437
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 1

Expert Comment

by:manifoldronin
ID: 10865771
Every J2EE compliant app server has a pair of vendor specific values for the two standard properties required for creating a JNDI initial context.  IIRC, for Sun ONE, it's like this:

Properties env = new Properties();
env.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
env.put("java.naming.provider.url", "iiop://<your-server-name>:<port>");
InitialContext jndi = new InitialContext(env);
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10866047
Yup, it would be better to use the provided constants, like:

env.put ( javax.naming.Context.PROVIDER_URL, "com.sun.jndi.cosnaming.CNCtxFactory" ) ;
env.put ( javax.naming.Context.INITIAL_CONTEXT_FACTORY, "iiop://server-name:port>" ) ;

- it would be even better to store the Provider-URL in a properties-file and read from there because if you deploy on something else (like Websphere), then the name will change.
0
 

Author Comment

by:rdy1437
ID: 10866207
Hi!

I tried to use this :

   Properties env = new Properties();
   env.put ( javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory") ;
   env.put ( javax.naming.Context.PROVIDER_URL, "iiop://localhost:9090") ;
   InitialContext initContext = new InitialContext(env);


but i got this error:


javax.naming.CommunicationException: Cannot connect to ORB [Root exception is org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 208 completed: Maybe]
      at com.sun.jndi.cosnaming.CNCtx.setOrbAndRootContext(Unknown Source)
      at com.sun.jndi.cosnaming.CNCtx.initUsingIiopUrl(Unknown Source)
      at com.sun.jndi.cosnaming.CNCtx.initUsingUrl(Unknown Source)
      at com.sun.jndi.cosnaming.CNCtx.initOrbAndRootContext(Unknown Source)
      at com.sun.jndi.cosnaming.CNCtx.<init>(Unknown Source)
      at com.sun.jndi.cosnaming.CNCtxFactory.getInitialContext(Unknown Source)
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.<init>(Unknown Source)

my sun one server is running, access it thru http://localhost:9090

      
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 30

Expert Comment

by:Mayank S
ID: 10867357
Try: env.put ( javax.naming.Context.PROVIDER_URL, "http://localhost:9090") ;
0
 
LVL 1

Expert Comment

by:manifoldronin
ID: 10870190
Hmm I don't think it's the same URL.  It's definitely "iiop://localhost:" + port.  I'm not very sure about which version of the Sun ONE you are running, so I don't know the port number.  Give 3700 a try because IIRC that's the default.
0
 

Author Comment

by:rdy1437
ID: 10875326
manifoldronin,
im using the one bundle with the j2ee1.4 installer
0
 

Author Comment

by:rdy1437
ID: 10875382
i  tried
 env.put ( javax.naming.Context.PROVIDER_URL, "iiop://localhost:3700") ;

but got the following exception:

javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10876520
Yeah, it should be "iiop://". I have never used "http:" - suggested that just in case.... because "iiop" did not seem to work. Are you sure your class-path is properly set? I mean - if you're using your own IDE, it would generally use its own classpath and not the system classpath.
0
 
LVL 1

Accepted Solution

by:
manifoldronin earned 150 total points
ID: 10878591
I think you have got the right URL.  Ironically, though, telling from the new exception you got and this link below, to get an InitialContext through IIOP, you probably have to do it in a different way.  8-)

http://forum.java.sun.com/thread.jsp?forum=51&thread=497115&tstart=0&trange=15
(The last post gives an answer)
0
 

Author Comment

by:rdy1437
ID: 10896920
Thanks manifoldronin!

I used the following code and it works.


Properties env = System.getProperties();
env.setProperty( javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory") ;
env.setProperty( javax.naming.Context.PROVIDER_URL, "iiop://purple:3700") ;*/

InitialContext context = new InitialContext();  
Object objref = context.lookup("HelloBean");
System.out.println("Looking               - " + context.getEnvironment());
System.out.println("Looking               - " + objref );
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Soundcloud.com 4 108
JAVA API design with micro service cloud in mind 1 106
maven disable workspace resolution 1 70
Is Applet the way to go for my drag and drop system? 8 49
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question