geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mattias Malmgren <matt...@freefarm.se>
Subject Re: Minimalistic example
Date Wed, 13 Sep 2006 17:01:47 GMT
Thanks for all help so far Lasantha!

However, I have not been able to get my test case work yet. More questions:

OK, I understand the concept of writing EJBs and then tell the EJB 
container about how to run the EJBs by providing that kind of information 
in XML-files specifying names, URL-access-paths and other stuff. In that 
way one single application can run in many different EJB containers (or 
applications servers) just by modifying the XML-files not the program code.

In your example here you have changed the servlet code to include imports 
of the home and remote interface:
import com.test.ejb.MyTest;
import com.test.ejb.MyTestHome;

They appears as part of the com.test.ejb package. Note, I never put my EJB 
nor the interfaces in a package. Is the package necessary?

You never wrote the content of the application.xml file. What should the 
contents of the
applications.xml file be?

What is correct, to have one web.xml or one geronimo-web.xml or both? 
What's the difference between web.xml and geronimo-web.xml? What is correct 
about application.xml and geronimo-application.xml

In the servlet I use
Object objref = initial.lookup("java:comp/env/ejb/MyTest");
I guess that "java:comp/env/ejb/MyTest" is some sort of URL that the 
container will use to return the right object (in this case an interface). 
Now, what are the rules of the lookup-string? In a normal web-url eg. 
http://www.freefarm.se/foo/bar/test.html the http:// part is the protocol, 
<http://www.freefarm.se/>www.freefarm.se is the domain, foo/bar corresponds 
to directories and test.html is the file to ret rive and show in the users 
browser. But what is "java:" in java:comp/env/ejb/MyTest?? What is 
env/ejb?? Is that supposed to correspond to something we have put in one of 
the different xml files? Or is it part of the package com.test.ejb ? MyTest 
is probably the name of the remote interface. But why the name of the 
remote interface, why not the name of the home interface? Or is MyTest 
refering to somwthing in the XML-files?

Now I am going to have a look at 
<http://cwiki.apache.org/GMOxDOC11/deployment-plans-level-1.html>http://cwiki.apache.org/GMOxDOC11/deployment-plans-level-1.html

and see if that can put me on the right track. But I am looking forward to 
your response Lasantha!

Best regards // Mattias



At 09:06 2006-09-13, you wrote:
>Hi Mattias,
>
>Following are my comments regarding this sample. I think step 1 to 3 you 
>might have already done. Anyway I am going to put it to clarity.
>
>1. web.xml
>You need to add ejb-ref element to the given web.xml as given in below. 
>Missing geronimo-web.xml in will give a warning. But anyway it will work. :)
>
><?xml version="1.0" encoding="UTF-8"?>
><web-app 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/web-app_2_4.xsd"
>version="2.4">
>
><servlet>
><display-name>MyTestServlet</display-name>
><servlet-name>MyTestServlet</servlet-name>
><servlet-class>MyTestServlet</servlet-class>
></servlet>
>
><servlet-mapping>
><servlet-name>MyTestServlet</servlet-name>
><url-pattern>/test</url-pattern>
></servlet-mapping>
>
><ejb-ref>
><ejb-ref-name>ejb/MyTest</ejb-ref-name>
><ejb-ref-type>Session</ejb-ref-type>
><home>MyTestHome</home>
><remote>MyTest</remote>
><ejb-link>MyTestBean</ejb-link>
></ejb-ref>
>
></web-app>
>
>2. Can't find openejb-jar.xml and ejb-jar.xml in your document.
>I can't find the openejb-jar.xml and ejb-jar.xml for the ejb.jar file. It 
>would be some thing like this given in the below.
>
>openejb-jar.xml
><?xml version="1.0" encoding="UTF-8"?>
><openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
><dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
><dep:moduleId>
><dep:groupId>samples</dep:groupId>
><dep:artifactId>my-test-ejb</dep:artifactId>
><dep:version>1.0</dep:version>
><dep:type>car</dep:type>
></dep:moduleId>
><dep:dependencies/>
><dep:hidden-classes/>
><dep:non-overridable-classes/>
></dep:environment>
><enterprise-beans>
><session>
><ejb-name>MyTestBean</ejb-name>
><jndi-name>MyTestBean</jndi-name>
></session>
></enterprise-beans>
></openejb-jar>
>
>ejb-jar.xml
><?xml version="1.0" encoding="UTF-8"?>
>
><ejb-jar 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" version="2.1">
>
><display-name>Generated by XDoclet</display-name>
>
><enterprise-beans>
>
><!-- Session Beans -->
><session >
><description>Test EJB </description>
><ejb-name>MyTestBean</ejb-name>
><home>MyTestHome</home>
><remote>MyTest</remote>
><ejb-class>MyTestBean</ejb-class>
><session-type>Stateless</session-type>
><transaction-type>Container</transaction-type>
></session>
>
></enterprise-beans>
>
></ejb-jar>
>
>3. Create JAR files.
>Hope EJB jar file would have a package structure something similar here.
>my-test-ejb.jar
>|-META-INF/ openejb-jar.xml
>|-META-INF/ ejb-jar.xml
>|- <ejb classes>
>
>4. Create an EAR with following structure. Note I have changed WAR archive 
>as my-test-web.war. ;)
>my-test.ear
>|- META-INF/ application.xml
>my-test-web.war
>my-test-ejb.jar
>
>application.xml
>
>5. Refer EJB from Servlet as given below. (Casting to PortableRemoteObject 
>is unnecessary. Anyway I am leaving it as you given)
>
>MyTestServlet.java
>
>import java.io.IOException;
>import java.io.PrintWriter;
>
>import javax.naming.Context;
>import javax.naming.InitialContext;
>import javax.rmi.PortableRemoteObject;
>import javax.servlet.ServletException;
>import javax.servlet.http.HttpServlet;
>import javax.servlet.http.HttpServletRequest;
>import javax.servlet.http.HttpServletResponse;
>
>import com.test.ejb.MyTest;
>import com.test.ejb.MyTestHome;
>
>
>public class MyTestServlet extends HttpServlet {
>
>
>public void doGet(HttpServletRequest request, HttpServletResponse 
>response) throws ServletException, IOException {
>
>PrintWriter out = response.getWriter();
>out.println("This is a test, time in servlet =" + new 
>java.util.Date().toString() + "<p>");
>// Put the code here that can get the time from the EJB
>// That code might look somthing like this?
>
>try {
>Context initial = new InitialContext();
>Object objref = initial.lookup("java:comp/env/ejb/MyTest");
>MyTestHome home = (MyTestHome)PortableRemoteObject.narrow(objref, 
>MyTestHome.class);
>
>MyTest test = home.create();
>String newtime = test.getTime();
>out.println("This is a new test, time from EJB =" + newtime + "<p>");
>} catch (Exception e) {
>e.printStackTrace();
>out.println("Faild to get time from EJB<p>");
>}
>}
>}
>
>Hope this will help.
>
>BR,
>Lasantha Ranaweera
>
>Mattias Malmgren wrote:
>>Hi!
>>
>>I have prepared something for you here:
>>
>>http://www.freefarm.se/geronimohelp.htm
>>
>>Best regards / Mattias
>>
>>
>>At 15:01 2006-09-12, you wrote:
>>>Hi Mattias,
>>>
>>>I would like to help you on this matter. Post your files to the community.
>>>
>>>Regards,
>>>Lasantha Ranaweera
>>>
>>>Mattias Malmgren wrote:
>>>>Hello!
>>>>
>>>>I have coded Java for 10 years, I know who to write Servlets and so on. 
>>>>Now I would like to write som EJBs and depoy them on geronimo. I can 
>>>>compile my EJBs, but the hard task is to make a ear-file and deploy. I 
>>>>have looked at the Bank-exemaple in the documentation, but it is to 
>>>>compex. Is there a more minimalistic example?
>>>>
>>>>Best regards / Mattias
>>>>
>>
>>



Mime
View raw message