| |
Sistemi distribuiti: design
-
Forum del Corso
Messaggi del Thread
|
| Autore |
Messaggio |
gianni.costanzi
|
Thread
Postato:
14 gennaio 2005
Titolo:
jndi.properties, where should I put it?
|
|
|
Looking at the "Cabin" example, I saw in the build.xml that the directory that contains the jndi.properties file is added to the classpath in the following way:
<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>
In this way, when we execute 'ant run.client' the client finds the jndi.properties in the classpath:
<target name="run.client" depends="ejbjar"> <java classname="com.titan.clients.Client_1" fork="yes" dir="."> <classpath refid="classpath"/> <arg value="${arg1}"/> <arg value="${arg2}"/> </java> </target>
Now, I'd like to know where to put the jndi.properties in the following cases:
1) I create a web-application and I want to do a lookup inside a servlet
2) I do a lookup inside a session bean (I saw that in the titan.jar generated from the build.xml there is no jndi.properties file, and I do not understand why)
Bye, Gianni
PS: can you tell me again some tools to create UML diagrams (I've forgot the names you told me...)
|
|
|
afogarolli
|
Postato:
14 gennaio 2005
Titolo:
Re: jndi.properties, where should I put it?
|
|
|
Hi! If you have a standalone client as in Cabin example you have two ways in order to get jndi properties, the first method is to put the jndi.propertis file where you have the compiled classes, the second method is to write in the client code the jndi properties. If I remember right, in the Cabin example both methods are used, but you just need to follow one way. For the web client the rules are differents, you don't need to tell the program where to fatch the jndi services, because you are deploying the application in a container that is already aware of the jndi service (where to find the service port ecc..). Getting back to your questions... 1) if you have a web application and you want to lookup a jndi resource from a servlet you just need to put a reference in the web.xml. Es. If you want to lookup a sessionBean you have to code in web.xml something like this: <ejb-ref> <description /> <ejb-ref-name>ejb/LoginManagerBean</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>com.angela.tesi.ejb.LoginManagerHome</home> <remote>com.angela.tesi.ejb.LoginManager</remote> </ejb-ref>
2) if you have to perform a lookup to another jndi resource from a session bean you have to put a reference in the ejb-jar.xml file. Es. if you want to call an entity from a session bean you have to code in the ejb-jar.xml something like this: <session> <description>No Description</description> <display-name>LoginManager</display-name> <ejb-name>LoginManager</ejb-name> <home>com.angela.tesi.ejb.LoginManagerHome</home> <remote>com.angela.tesi.ejb.LoginManager</remote> <local-home>com.angela.tesi.ejb.LoginManagerLocalHome</local-home> <local>com.angela.tesi.ejb.LoginManagerLocal</local> <ejb-class>com.angela.tesi.ejb.LoginManagerBean</ejb-class> <session-type>Stateful</session-type> <transaction-type>Container</transaction-type> <ejb-ref> <description /> <ejb-ref-name>ejb/LoginBean</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>com.angela.tesi.ejb.LoginHome</home> <remote>com.angela.tesi.ejb.Login</remote> </ejb-ref> <ejb-ref> <description /> <ejb-ref-name>ejb/UserBean</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>com.angela.tesi.ejb.UserHome</home> <remote>com.angela.tesi.ejb.User</remote> </ejb-ref> </session>
********************************************************* In reply to your first and second question you need an ejb-ref that has the same syntax in the web.xml and in ejb-jar.xml that address the container to the right object in the jndi directory.
Some names of UML tools you can try are: ArgoUML opensource Together commercial Rational Rose commercial ...other tools
|
|
|
gianni.costanzi
|
Postato:
16 gennaio 2005
Titolo:
Re: jndi.properties, where should I put it?
|
|
|
Thank you for the answer.. I made a simple servlet and I tried to access a bean with a remote lookup and it worked fine without anything in the web.xml
You said that the jndi.properties file is not necessary, but in that file we specify also the url of the server (i.e. jboss) that runs the EJB Application with
java.naming.provider.url=jnp://localhost:1099
and this row can not be guessed by the Web Application.. So if the web application runs on a different machine we must tell it where the EJB Application is running and this is why I thought the jndi.properties file was necessary..
|
|
|
afogarolli
|
Postato:
17 gennaio 2005
Titolo:
Re: jndi.properties, where should I put it?
|
|
|
...mmm maybe if you have deployed your web application in jboss...the container colud guess the reference without putting anything in the web.xml...but the standard way is putting the ejb-ref in web.xml.(Have you deployed everything in a ear?) Theorically you are right when you have said that we need a way to tell the web app where to find the ejb part when the web server is not on the same machine of the app server. I've never really dug this problem but I remember some chapters of the jboss admin guide about configuring tomcat connector to connect an external tomcat and jboss. There are just one case when you could reach the jndi server without knowing the srv ip; it's the case of a cluster configuration where you have to use a more sofisticated jndi service called HA-JNDI that allow auto-discovery using a multicast group address 230.0.0.4:1102. Hope it helps...
|
|
|
gianni.costanzi
|
Postato:
17 gennaio 2005
Titolo:
Re: jndi.properties, where should I put it?
|
|
|
I do not really understand why it is necessary to specify things like ejb-ref, ecc in the web.xml.. If you suppose that web-app and ejb-app run on the same machine we can say that jndi.properties is not necessary (the container can guess the right thing without specifying them), and the problem is solved, without specifying other things in the web.xml.. Why should I specify the ejb-ref in the web.xml? The web application can do a lookup and the ejb-container (the directory service) will receive the request for an home interface; then it can lookup in ITS xml configuration files to bind the request to the correct bean.. What I want to say is that it has no sense to put in the Web application (in the web.xml) something that is related to the beans of the ejb container (why should I tell to the web application that with a particular name I refer to a particular home interface? The ejb container knows all the bindings between names and objects)..
I hope to have been quite clear, because it is not simple to explain..
|
|
|
afogarolli
|
Postato:
17 gennaio 2005
Titolo:
Re: jndi.properties, where should I put it?
|
|
|
I agree with you. The jndi resource sholud map to the right bean via EJB descriptors...I can not give you an answer... J2EE 1.3 specification says (page 57):
-------------------------------------------------------------------------------- The Application Component Provider must declare all the EJB references using the ejb-ref elements of the deployment descriptor. This allows the consumer of the application component's jar file (the Application Assembler or Deployer) to discover all the EJB references used by the application component. --------------------------------------------------------------------------------
It means that each time a web application needs to reference a bean, the bean has to be declared in the web application's deployment descriptor ( /WEB-INF/web.xml file). The element which does so is ejb-ref. Although most containers don't enforce that approach, it's always better to describe dependencies in a standard, J2EE-compliant way, in the deployment descriptor of the corresponding components. Tomcat won't refuse to activate the components even if they reference EJBs with no declaration in the deployment descriptors.
Web.xml Reference Enterprise JavaBean (EJB) resource, ejb-ref Element.: <description> ...text... (Optional) </description> <ejb-ref-name> name (Required) </ejb-ref-name> <ejb-ref-type> Java type (Required) </ejb-ref-type> <home> mycom.ejb.AccountHome (Required) </home> <remote> mycom.ejb.Account (Required) </remote>
<ejb-link> ejb.name (Optional) </ejb-link>
<run-as> security role (Optional) </run-as> </ejb-ref> (Required)
To reference an EJB for use in a Web Application: Enter the EJB reference name you use to look up the EJB in your code, the Java class name, and the class name of the home and remote interfaces of the EJB in the <ejb-ref> element of the Web Application deployment descriptor.
To learn more about ejb Reference check out the JBoss manual ...but I think that also the linked page will not expained why we have to duplicate the inforamtion about the interfaces.
Bye
|
|
|
gianni.costanzi
|
Postato:
17 gennaio 2005
Titolo:
Re: jndi.properties, where should I put it?
|
|
|
Ok, things are getting more and more confused A last (in this thread) question.. If all the stuff works well without specifying nothing in the web.xml, can we avoid writing ejb-refs in the web.xml? It's because we have never talked about putting this ejb-related stuff in the web.xml during the lessons and I'd like to avoid possible complications..
Thank you
|
|
|
afogarolli
|
Postato:
18 gennaio 2005
Titolo:
Re: jndi.properties, where should I put it?
|
|
|
You should use ejb-ref as the specification tells. I 've wanted to introduce you the web.xml in the laboratory session and for this purpose I had asked you to do the exercise for arising doubts and questions. (With this kind of exercise you could face in advance all the problematic steps that you will encounter in your final project). If we have the chance we can discuss the exercise in the next lecture. CU.
|
|
|
|
|