Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jndi.properties 1

Status
Not open for further replies.

Themuppeteer

Programmer
Apr 4, 2001
449
BE
Hello guys,

Could anyone who has an application connecting to an application server over the internet please post his jndi.properties file here (or the code for his getInitialContext()) ? I think I have something missing but I can't figure out what. (keep getting remoteexceptions on client side)

I only yesterday found out (after a week of searching) that stuff like this :
-Djava.naming.provider.url=jnp://myip:1099
-Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

should be included in your command line,your code or your jndi.properties file. But I still think I'm missing stuff.
Are there any more properties I should set ?

Thnx!



Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

"Those who say they understand chess, understand nothing"

-- Robert HUBNER
 
jndi.properties is different for applications dependining on your J2EE vendor, the type of application that is serviced etc etc.

As a hint though, here is a file that is used for looking up JBoss encapsualted EJBs :

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:eek:rg.jnp.interfaces
java.naming.provider.url=servername
 
Hello sedj,
thanks for your answer (again :))
Well, I use jboss and I copied the file from my
%jboss%\server\default\conf,
and that file had :

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:eek:rg.jnp.interfaces

in it already,
then I booted my jar using the option:
-Djava.naming.provider.url=jnp://xxx.xxx.xxx.xxx:1099

,the lookups of the home interfaces seemed to work (the part with the portableRemoteObject.narrow thing), but when I call the 'create' function on my home interface, I get an exception. The printstacktrace funciton shows me a connection exception with 'connection timeout' (in my dos box that is). My client application self shws a messagebox with exception.getMessage() in it, and that says 'connection refused'. Strange that the stacktrace isn't equal to the getMessage...
Do you think puting the java.naming.provider.url=jnp://xxx.xxx.xxx.xxx:1099
in the jndi.properties file could solve my problem ? or does it lie somewhere else ?



Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

"Those who say they understand chess, understand nothing"

-- Robert HUBNER
 
I think

java.naming.provider.url=servername

should be enough without specify ports, or protocaols because the factory classes will know which port the jnp server is running on. Add it to jndi.properties, and make sure you add the jndi.properties file to your CLASSPATH.

Now, sometimes I used to have problems with the VM picking up my jndi.properties file from the command line using the "java bla" method, but found if I ran it through Ant, it was OK, so below is an example Ant build script incase it doesn't work :

Code:
<?xml version="1.0"?>

<!-- ======================================================================= -->
<!-- JBoss build file                                                       -->
<!-- ======================================================================= -->

<project name="JBoss" default="ejbjar" basedir=".">

  <property environment="env"/>
  <property name="src.dir" value="${basedir}/src/main"/>
  <property name="src.resources" value="${basedir}/src/resources"/>
  <property name="jboss.home" value="${env.JBOSS_HOME}"/>
  <property name="build.dir" value="${basedir}/build"/>
  <property name="build.classes.dir" value="${build.dir}/classes"/>

  <!-- Build classpath -->
  <path id="classpath">
        <fileset dir="${jboss.home}/client">
            <include name="**/*.jar"/>
        </fileset>
	<pathelement location="${build.classes.dir}"/>
	<!-- So that we can get jndi.properties for InitialContext -->
	<pathelement location="${basedir}/jndi"/>
  </path>

  <property name="build.classpath" refid="classpath"/>

  <!-- =================================================================== -->
  <!-- Prepares the build directory                                        -->
  <!-- =================================================================== -->
  <target name="prepare" >
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes.dir}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source code                                            -->
  <!-- =================================================================== -->
  <target name="compile" depends="prepare">
    <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           debug="on"
           deprecation="on"
           optimize="off"
           includes="**">
            <classpath refid="classpath"/>
    </javac>
  </target>

  <target name="ejbjar" depends="compile">
    <jar jarfile="build/titan.jar">
      <fileset dir="${build.classes.dir}">
      	  <include name="com/titan/cabin/*.class"/>
      </fileset>
      <fileset dir="${src.resources}/">
         <!-- <include name="**/*.xml"/> -->
         <include name="ejb-jar.xml"/>
      </fileset>
     </jar>
     <copy file="build/titan.jar" todir="${jboss.home}/server/default/deploy"/>
  </target>

  <target name="run.client_41a" depends="ejbjar">
    <java classname="com.titan.clients.Client_1" fork="yes" dir=".">
      <classpath refid="classpath"/>
    </java>
  </target>

  <target name="run.client_41b" depends="ejbjar">
    <java classname="com.titan.clients.Client_2" fork="yes" dir=".">
      <classpath refid="classpath"/>
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Cleans up generated stuff                                           -->
  <!-- =================================================================== -->
  <target name="clean.db">
    <delete dir="${jboss.home}/server/default/data/hypersonic"/>
  </target>

  <target name="clean">
    <delete dir="${build.dir}"/>
    <delete file="${jboss.home}/server/default/deploy/titan.jar"/>
  </target>


</project>

I would also recommend purchasing "Enterprise JavaBeans" by Richard Monson-Haefal
and also the JBoss e-book for deveopers :

and some examples for JBoss 3 :

 
ok, thanks for the links. They look very useful.

Is the default place to put jndi.properties file in your jar under the directory jndi (like they do in the examples)?
Because when I tried it at home,I've put the file in the root dir of the jar and also outside the jar in the same directory. Or doesn't it matter as long that it is in your classpath (so inside the jar should do).
I do have noticed that (as usual) all the examples given in
JBoss 3.2 Workbook are made for localhost...and of course my program works just fine localhost its once you put the internet in between it goes wrong.
How can you check if he has found the jndi.properties file ?


Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

&quot;Those who say they understand chess, understand nothing&quot;

-- Robert HUBNER
 
The jndi.properties file should be referenced on your CLASSPATH - however you achive that is down to the programmer.

Your "'connection refused'" error sounds like either your server is not listening on the specified port, or is not configured to accept incoming connections from foreign clients.

Try the "netstat" command from the command line to check what ports are doing what.
 
I already tried a telnet to that port, and I got some sort of binary dump back with some ascii characters in there,and then the connection was closed..so I guess something is running there.

Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

&quot;Those who say they understand chess, understand nothing&quot;

-- Robert HUBNER
 
If I put jndi.properties in my sdk directory, its in my classpath. But I'm not sure if JBuilderX will take it along in the jar. I'm goanna have to test that.

Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

&quot;Those who say they understand chess, understand nothing&quot;

-- Robert HUBNER
 
Actually,what I do in my code is this:

Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:eek:rg.jnp.interfaces");
environment.put(Context.PROVIDER_URL,"jnp://"+ip);
environment.put(Context.SECURITY_PRINCIPAL, "guest");
environment.put(Context.SECURITY_CREDENTIALS, "guest");


so that should also be enough shouldn't it ?
Guess the jndi.properties file has nothing to do with my problem.


Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

&quot;Those who say they understand chess, understand nothing&quot;

-- Robert HUBNER
 
<quote>"I think
java.naming.provider.url=servername
should be enough without specify ports, or protocaols because the factory classes will know which port the jnp server is running on." </quote>


I've just noticed, that if I don't put my port number after the ip,it doesn't work anymore on localhost either.



Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

&quot;Those who say they understand chess, understand nothing&quot;

-- Robert HUBNER
 
Are your java.policy permissions correct (in jre\lib\security)

Check that the SocketPermission is like this fro the default domains :

permission java.net.SocketPermission "localhost:1024-", "listen,connect,accept,resolve";

And as an extra step, grant the specific codeBase :

grant codeBase "file:C:/java/ejb/code/*" {
permission java.security.AllPermission;
};
 
Hello sedj,

thanks for your reply,
I've seen that in my java.policy file,the permission was only set on listen. So I've changed that. Also I've noticed that zonealarm is a real pain since it blocks my application server.
I've got it working on a hub with my pc on one side,and a laptop on the other side (which I could use for the weekend from my boss). I've noticed that the java.policy file on client side only need the 'listen' in its permissions which is good, because otherwise the installation procedure for people who want to use the client would become to complicated.

About the java.policy file, I already had a rmi.policy file in the same directory of my jar which I inlcuded with a -D in my java -jar line. It had only a grant allpermissions
block (similar to what you put above) in it. Does this override the defaults in the java.policy file ?

I'm going to try it over the internet as soon as possible now. But since it works over a hub, I can't see why I should not work over the internet. (Perhaps my timeout is to low ?)

I'll come back to tell you wether or not it worked.

Thanks again, this is by far the most useful help I've got on my problem.


Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

&quot;Those who say they understand chess, understand nothing&quot;

-- Robert HUBNER
 
Doh ! Firewall. Of course. I bet that was the problem all along - hence the orignal "connection refused" problem ... should have spotted that earlier.

Best wishes.
 
Hello sedj,

Unfortunately the problem is not solved yet.
Even if the firewall is turned of. I still get connection refused error and then the client gets a time-out.
What happens I think is that the jndi lookup on port 9099 works, but the create failes. I think connection on a different port is made then (?) and that port is not accesible for some reason.
I friend of mine told me that once you've run the windows firewall,it will do translation of addresses using NAT for the rest of his days, even if you turn the firewall off lateron. I don't know if thats the same for zonealarm nor what I have to do to make it work.
In any case, its configuration of jboss or windows xp, but the program works fine I think.



Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

&quot;Those who say they understand chess, understand nothing&quot;

-- Robert HUBNER
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top