You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Dain Sundstrom <da...@iq80.com> on 2007/09/18 01:37:25 UTC

Annotations working in Tomcat

I got annotations mostly working in Tomcat.  To try this out, install  
OpenEJB into Tomcat as noted before and simply add @EJB and @Resource  
annotations to your servlet fields.  I added an very simply servlet- 
samples application which can be checked out with:

   svn co http://svn.apache.org/repos/asf/openejb/trunk/openejb3/ 
examples/servlet-samples

This is a completely standalone sample and should be an easy starting  
point.  One critical thing to note about the example is the use of  
<scope>provided</scope> in the maven pom.xml file to stop maven from  
including duplicate copies of the annotation classes into the web  
application.


For those that don't want to download the code, here is it:

public class AnnotatedServlet extends HttpServlet {
     @EJB private AnnotatedEJBLocal ejb;

     @Resource private DataSource ds;

     protected void doGet(HttpServletRequest request,  
HttpServletResponse response) throws ServletException, IOException {
         response.setContentType("text/plain");
         ServletOutputStream out = response.getOutputStream();

         out.println("@EJB=" + ejb);
         if (ejb != null) {
             out.println("@EJB.getName()=" + ejb.getName());
             out.println("@EJB.getDs()=" + ejb.getDs());
         }

         out.println("@Resource=" + ds);
     }
}

@Stateless
public class AnnotatedEJB implements AnnotatedEJBLocal {
     @Resource private DataSource ds;
     private String name = "foo";

     public String getName() {
         return name;
     }

     public void setName(String name) {
         this.name = name;
     }

     public DataSource getDs() {
         return ds;
     }

     public void setDs(DataSource ds) {
         this.ds = ds;
     }

     public String toString() {
         return "AnnotatedEJB[name=" + name + "]";
     }
}

public interface AnnotatedEJBLocal {
     String getName();

     void setName(String name);

     DataSource getDs();

     void setDs(DataSource ds);
}

<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">

   <display-name>OpenEJB Servlet Examples</display-name>

   <servlet>
     <servlet-name>AnnotatedServlet</servlet-name>
     <servlet- 
class>org.apache.openejb.examples.servlet.AnnotatedServlet</servlet- 
class>
   </servlet>

   <servlet-mapping>
     <servlet-name>AnnotatedServlet</servlet-name>
     <url-pattern>/annotated/*</url-pattern>
   </servlet-mapping>
</web-app>

I'm going to be tuning the code over the next couple of days, but it  
generally works now.  Let me know if you find any bugs, or most  
importantly if it doesn't work as you would expect Tomcat to work.   
One of my goals is to not violate any expectations of Tomcat users,  
so if something stops working like is used to do, let me know ASAP.   
The integration should feel like the Tomcat team wrote it themselves.

-dain

Re: Annotations working in Tomcat

Posted by Karan Malhi <ka...@gmail.com>.
>I've updated the "New Instructions"
Excellent!! , thanks a lot

> I tried out your example by adding it to the previous example Karan posted but even
> that one no longer works for me:
> javax.naming.NameNotFoundException: Name "GreetingBeanBusinessRemote" not found.
>
> Maybe I'm still missing something?

Thats my bad. I should've updated the example. The default JNDI name
strategy has changed. Now the default JNDI name of the bean is going
to be "GreetingBeanRemote".
-- 
Karan Singh Malhi

Re: Annotations working in Tomcat

Posted by Dain Sundstrom <da...@iq80.com>.
I implemented redeploy in trunk and 3.0-beta-1.  I also refreshed all  
the jars in my home dir http://people.apache.org/~dain/openejb-temp/

-dain

On Sep 21, 2007, at 12:32 PM, Dario Laverde wrote:

> Thanks again, I got it working now from svn (still need to update  
> the openejb-tmp
> downloads).
>
> One more thing, the 21 errors that occur from running the tests  
> twice, is it really
> a "unknown reason"?  Seems like a hsqldb driver message due to  
> still having some
> lock on previously closed sessions.
>
> -Dario
>
>> On Sep 21, 2007, at 1:35 AM, Dario Laverde wrote:
>>
>>> Thanks Dain,
>>>
>>>> I added the @Local annotation to the AnnotatedEJBLocal interface  
>>>> and
>>>> added a @Remote AnnotatedEJBRemote interface to the example; both
>>>> work fine for me.
>>>>
>>>> Can you try the servlet-examples war?
>>>
>>> You don't have the remote interface in your examples,
>>
>> If you check the servlet-samples, you will see I added an annotated
>> remote interface to the code.
>>
>> http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/servlet-
>> samples/src/main/java/org/apache/openejb/examples/servlet/
>>
>>
>>> but adding one still gives me
>>> the following when getting the datasource:
>>>
>>> java.io.NotSerializableException:
>>> org.apache.openejb.resource.jdbc.BasicManagedDataSource
>>> 	java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java: 
>>> 1081)
>>> 	java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:
>>> 302)	org.apache.openejb.core.ivm.BaseEjbProxyHandler.copyObj
>>> (BaseEjbProxyHandler.java:503)
>>> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke
>>> (BaseEjbProxyHandler.java:259)
>>> org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke
>>> (Jdk13InvocationHandler.java:49)
>>> 	$Proxy42.getDs(Unknown
>>> Source)	org.apache.openejb.examples.servlet.AnnotatedServlet.doGet
>>> (AnnotatedServlet.java:44)
>>
>> Based on the stacktrace it appears that your remote interface
>> includes the "DataSource getDs();" method.  When you call this
>> method, you get a NotSerializableException because a DataSource
>> object is not serializable.  The EJB specification restricts remote
>> interface to only use serializable data types.
>>
>> If you remove this method, I bet your code will work.
>>
>>>> As for the test client jar, I rewrote the packing configuration for
>>>> it the other day, and tested it on linux and windows.  So, if it  
>>>> was
>>>> broken before, I'm confident it is fixed now :)
>>>
>>> It's fixed in your war file but still broken in the current  
>>> snapshot.
>>>
>>> I also noticed that I can't "undeploy" the beans by reloading the
>>> web application
>>> (or both the web app and openejb for that matter). Is it possible
>>> to avoid
>>> restarting Tomcat every time one just wants to reload the web app?
>>
>> Yes it is possible... I just need to code up the stop listener :)
>> I'll try to implement that today.
>>
>> -dain
>>
>
>


Re: Annotations working in Tomcat

Posted by David Blevins <db...@visi.com>.
On Sep 21, 2007, at 12:32 PM, Dario Laverde wrote:

> Thanks again, I got it working now from svn (still need to update  
> the openejb-tmp
> downloads).
>
> One more thing, the 21 errors that occur from running the tests  
> twice, is it really
> a "unknown reason"?  Seems like a hsqldb driver message due to  
> still having some
> lock on previously closed sessions.

That could be.  "Unknown reason" is really "hasn't been  
investigated".  Might be our test suite isn't cleaning up properly?

-David

>
> -Dario
>
>> On Sep 21, 2007, at 1:35 AM, Dario Laverde wrote:
>>
>>> Thanks Dain,
>>>
>>>> I added the @Local annotation to the AnnotatedEJBLocal interface  
>>>> and
>>>> added a @Remote AnnotatedEJBRemote interface to the example; both
>>>> work fine for me.
>>>>
>>>> Can you try the servlet-examples war?
>>>
>>> You don't have the remote interface in your examples,
>>
>> If you check the servlet-samples, you will see I added an annotated
>> remote interface to the code.
>>
>> http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/servlet-
>> samples/src/main/java/org/apache/openejb/examples/servlet/
>>
>>
>>> but adding one still gives me
>>> the following when getting the datasource:
>>>
>>> java.io.NotSerializableException:
>>> org.apache.openejb.resource.jdbc.BasicManagedDataSource
>>> 	java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java: 
>>> 1081)
>>> 	java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:
>>> 302)	org.apache.openejb.core.ivm.BaseEjbProxyHandler.copyObj
>>> (BaseEjbProxyHandler.java:503)
>>> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke
>>> (BaseEjbProxyHandler.java:259)
>>> org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke
>>> (Jdk13InvocationHandler.java:49)
>>> 	$Proxy42.getDs(Unknown
>>> Source)	org.apache.openejb.examples.servlet.AnnotatedServlet.doGet
>>> (AnnotatedServlet.java:44)
>>
>> Based on the stacktrace it appears that your remote interface
>> includes the "DataSource getDs();" method.  When you call this
>> method, you get a NotSerializableException because a DataSource
>> object is not serializable.  The EJB specification restricts remote
>> interface to only use serializable data types.
>>
>> If you remove this method, I bet your code will work.
>>
>>>> As for the test client jar, I rewrote the packing configuration for
>>>> it the other day, and tested it on linux and windows.  So, if it  
>>>> was
>>>> broken before, I'm confident it is fixed now :)
>>>
>>> It's fixed in your war file but still broken in the current  
>>> snapshot.
>>>
>>> I also noticed that I can't "undeploy" the beans by reloading the
>>> web application
>>> (or both the web app and openejb for that matter). Is it possible
>>> to avoid
>>> restarting Tomcat every time one just wants to reload the web app?
>>
>> Yes it is possible... I just need to code up the stop listener :)
>> I'll try to implement that today.
>>
>> -dain
>>
>
>
>


Re: Annotations working in Tomcat

Posted by Dario Laverde <da...@nycjava.net>.
Thanks again, I got it working now from svn (still need to update the openejb-tmp
downloads).

One more thing, the 21 errors that occur from running the tests twice, is it really
a "unknown reason"?  Seems like a hsqldb driver message due to still having some
lock on previously closed sessions.

-Dario

> On Sep 21, 2007, at 1:35 AM, Dario Laverde wrote:
>
>> Thanks Dain,
>>
>>> I added the @Local annotation to the AnnotatedEJBLocal interface and
>>> added a @Remote AnnotatedEJBRemote interface to the example; both
>>> work fine for me.
>>>
>>> Can you try the servlet-examples war?
>>
>> You don't have the remote interface in your examples,
>
> If you check the servlet-samples, you will see I added an annotated
> remote interface to the code.
>
> http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/servlet-
> samples/src/main/java/org/apache/openejb/examples/servlet/
>
>
>> but adding one still gives me
>> the following when getting the datasource:
>>
>> java.io.NotSerializableException:
>> org.apache.openejb.resource.jdbc.BasicManagedDataSource
>> 	java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
>> 	java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:
>> 302)	org.apache.openejb.core.ivm.BaseEjbProxyHandler.copyObj
>> (BaseEjbProxyHandler.java:503)
>> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke
>> (BaseEjbProxyHandler.java:259)
>> org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke
>> (Jdk13InvocationHandler.java:49)
>> 	$Proxy42.getDs(Unknown
>> Source)	org.apache.openejb.examples.servlet.AnnotatedServlet.doGet
>> (AnnotatedServlet.java:44)
>
> Based on the stacktrace it appears that your remote interface
> includes the "DataSource getDs();" method.  When you call this
> method, you get a NotSerializableException because a DataSource
> object is not serializable.  The EJB specification restricts remote
> interface to only use serializable data types.
>
> If you remove this method, I bet your code will work.
>
>>> As for the test client jar, I rewrote the packing configuration for
>>> it the other day, and tested it on linux and windows.  So, if it was
>>> broken before, I'm confident it is fixed now :)
>>
>> It's fixed in your war file but still broken in the current snapshot.
>>
>> I also noticed that I can't "undeploy" the beans by reloading the
>> web application
>> (or both the web app and openejb for that matter). Is it possible
>> to avoid
>> restarting Tomcat every time one just wants to reload the web app?
>
> Yes it is possible... I just need to code up the stop listener :)
> I'll try to implement that today.
>
> -dain
>



Re: Annotations working in Tomcat

Posted by Dain Sundstrom <da...@iq80.com>.
On Sep 21, 2007, at 1:35 AM, Dario Laverde wrote:

> Thanks Dain,
>
>> I added the @Local annotation to the AnnotatedEJBLocal interface and
>> added a @Remote AnnotatedEJBRemote interface to the example; both
>> work fine for me.
>>
>> Can you try the servlet-examples war?
>
> You don't have the remote interface in your examples,

If you check the servlet-samples, you will see I added an annotated  
remote interface to the code.

http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/servlet- 
samples/src/main/java/org/apache/openejb/examples/servlet/


> but adding one still gives me
> the following when getting the datasource:
>
> java.io.NotSerializableException:
> org.apache.openejb.resource.jdbc.BasicManagedDataSource
> 	java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
> 	java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java: 
> 302)	org.apache.openejb.core.ivm.BaseEjbProxyHandler.copyObj 
> (BaseEjbProxyHandler.java:503)	 
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke 
> (BaseEjbProxyHandler.java:259)	 
> org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke 
> (Jdk13InvocationHandler.java:49)
> 	$Proxy42.getDs(Unknown
> Source)	org.apache.openejb.examples.servlet.AnnotatedServlet.doGet 
> (AnnotatedServlet.java:44)

Based on the stacktrace it appears that your remote interface  
includes the "DataSource getDs();" method.  When you call this  
method, you get a NotSerializableException because a DataSource  
object is not serializable.  The EJB specification restricts remote  
interface to only use serializable data types.

If you remove this method, I bet your code will work.

>> As for the test client jar, I rewrote the packing configuration for
>> it the other day, and tested it on linux and windows.  So, if it was
>> broken before, I'm confident it is fixed now :)
>
> It's fixed in your war file but still broken in the current snapshot.
>
> I also noticed that I can't "undeploy" the beans by reloading the  
> web application
> (or both the web app and openejb for that matter). Is it possible  
> to avoid
> restarting Tomcat every time one just wants to reload the web app?

Yes it is possible... I just need to code up the stop listener :)   
I'll try to implement that today.

-dain

Re: Annotations working in Tomcat

Posted by Dario Laverde <da...@nycjava.net>.
Thanks Dain,

> I added the @Local annotation to the AnnotatedEJBLocal interface and
> added a @Remote AnnotatedEJBRemote interface to the example; both
> work fine for me.
>
> Can you try the servlet-examples war?

You don't have the remote interface in your examples, but adding one still gives me
the following when getting the datasource:

java.io.NotSerializableException:
org.apache.openejb.resource.jdbc.BasicManagedDataSource
	java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
	java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)	org.apache.openejb.core.ivm.BaseEjbProxyHandler.copyObj(BaseEjbProxyHandler.java:503)	org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:259)	org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
	$Proxy42.getDs(Unknown
Source)	org.apache.openejb.examples.servlet.AnnotatedServlet.doGet(AnnotatedServlet.java:44)


> As for the test client jar, I rewrote the packing configuration for
> it the other day, and tested it on linux and windows.  So, if it was
> broken before, I'm confident it is fixed now :)

It's fixed in your war file but still broken in the current snapshot.

I also noticed that I can't "undeploy" the beans by reloading the web application
(or both the web app and openejb for that matter). Is it possible to avoid
restarting Tomcat every time one just wants to reload the web app?

This is what I get when I try to reload (from Tomcat manager):

javax.servlet.ServletException: Error instantiating servlet class
org.apache.openejb.examples.servlet.AnnotatedServlet
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	java.lang.Thread.run(Thread.java:613)

root cause:

java.lang.IllegalArgumentException
	sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
	java.lang.reflect.Field.set(Field.java:656)
org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:208)	org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:139)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

-Dario


> -dain
>
> On Sep 20, 2007, at 11:16 AM, Dario Laverde wrote:
>
>> Dain,
>>
>> Correct, I can't get remote interfaces working (you left out the
>> @Local annotation
>> in your example). I also noticed that the optional tests client jar
>> is packaged
>> incorrectly (had to unpack it to be able to find and run the Main
>> class).
>>
>> -Dario
>>
>>> Forgot to click the send button on this email yesterday :(
>>>
>>> On Sep 18, 2007, at 2:17 PM, Dario Laverde wrote:
>>>
>>>> Dain,
>>>>
>>>> Thanks for the work! I've updated the "New Instructions" adding the
>>>> manual steps for
>>>> Windows users, you can try including this in your installer.
>>>
>>> I updated the installer and tested it.
>>>
>>>> Just a minor comment, I
>>>> also copied the agent jar in addition to the loader jar into
>>>> Tomcat's lib folder
>>>> because hardcoding to webapps/openejb/lib may be a problem should
>>>> webapps be changed
>>>> or openejb be deployed w/o unpacking the war/zip.
>>>
>>> Interesting idea.  I'll give that a try also.
>>>
>>>> Now for the example, I'm getting the following error:
>>>> javax.naming.NameNotFoundException: Name "org.acme.TestServlet/ejb"
>>>> not found.
>>>>
>>>> I tried out your example by adding it to the previous example Karan
>>>> posted but even
>>>> that one no longer works for me:
>>>> javax.naming.NameNotFoundException: Name
>>>> "GreetingBeanBusinessRemote" not found.
>>>>
>>>> Maybe I'm still missing something?
>>>
>>> Can you try my example directly?  There may be something wrong with
>>> Karan's example or maybe remote business interfaces are broken.
>>>
>>> -dain
>>>
>>
>>
>
>



Re: Annotations working in Tomcat

Posted by Dain Sundstrom <da...@iq80.com>.
I added the @Local annotation to the AnnotatedEJBLocal interface and  
added a @Remote AnnotatedEJBRemote interface to the example; both  
work fine for me.

Can you try the servlet-examples war?

As for the test client jar, I rewrote the packing configuration for  
it the other day, and tested it on linux and windows.  So, if it was  
broken before, I'm confident it is fixed now :)

-dain

On Sep 20, 2007, at 11:16 AM, Dario Laverde wrote:

> Dain,
>
> Correct, I can't get remote interfaces working (you left out the  
> @Local annotation
> in your example). I also noticed that the optional tests client jar  
> is packaged
> incorrectly (had to unpack it to be able to find and run the Main  
> class).
>
> -Dario
>
>> Forgot to click the send button on this email yesterday :(
>>
>> On Sep 18, 2007, at 2:17 PM, Dario Laverde wrote:
>>
>>> Dain,
>>>
>>> Thanks for the work! I've updated the "New Instructions" adding the
>>> manual steps for
>>> Windows users, you can try including this in your installer.
>>
>> I updated the installer and tested it.
>>
>>> Just a minor comment, I
>>> also copied the agent jar in addition to the loader jar into
>>> Tomcat's lib folder
>>> because hardcoding to webapps/openejb/lib may be a problem should
>>> webapps be changed
>>> or openejb be deployed w/o unpacking the war/zip.
>>
>> Interesting idea.  I'll give that a try also.
>>
>>> Now for the example, I'm getting the following error:
>>> javax.naming.NameNotFoundException: Name "org.acme.TestServlet/ejb"
>>> not found.
>>>
>>> I tried out your example by adding it to the previous example Karan
>>> posted but even
>>> that one no longer works for me:
>>> javax.naming.NameNotFoundException: Name
>>> "GreetingBeanBusinessRemote" not found.
>>>
>>> Maybe I'm still missing something?
>>
>> Can you try my example directly?  There may be something wrong with
>> Karan's example or maybe remote business interfaces are broken.
>>
>> -dain
>>
>
>


Re: Annotations working in Tomcat

Posted by Dario Laverde <da...@nycjava.net>.
Dain,

Correct, I can't get remote interfaces working (you left out the @Local annotation
in your example). I also noticed that the optional tests client jar is packaged
incorrectly (had to unpack it to be able to find and run the Main class).

-Dario

> Forgot to click the send button on this email yesterday :(
>
> On Sep 18, 2007, at 2:17 PM, Dario Laverde wrote:
>
>> Dain,
>>
>> Thanks for the work! I've updated the "New Instructions" adding the
>> manual steps for
>> Windows users, you can try including this in your installer.
>
> I updated the installer and tested it.
>
>> Just a minor comment, I
>> also copied the agent jar in addition to the loader jar into
>> Tomcat's lib folder
>> because hardcoding to webapps/openejb/lib may be a problem should
>> webapps be changed
>> or openejb be deployed w/o unpacking the war/zip.
>
> Interesting idea.  I'll give that a try also.
>
>> Now for the example, I'm getting the following error:
>> javax.naming.NameNotFoundException: Name "org.acme.TestServlet/ejb"
>> not found.
>>
>> I tried out your example by adding it to the previous example Karan
>> posted but even
>> that one no longer works for me:
>> javax.naming.NameNotFoundException: Name
>> "GreetingBeanBusinessRemote" not found.
>>
>> Maybe I'm still missing something?
>
> Can you try my example directly?  There may be something wrong with
> Karan's example or maybe remote business interfaces are broken.
>
> -dain
>



Re: Annotations working in Tomcat

Posted by Dain Sundstrom <da...@iq80.com>.
Forgot to click the send button on this email yesterday :(

On Sep 18, 2007, at 2:17 PM, Dario Laverde wrote:

> Dain,
>
> Thanks for the work! I've updated the "New Instructions" adding the  
> manual steps for
> Windows users, you can try including this in your installer.

I updated the installer and tested it.

> Just a minor comment, I
> also copied the agent jar in addition to the loader jar into  
> Tomcat's lib folder
> because hardcoding to webapps/openejb/lib may be a problem should  
> webapps be changed
> or openejb be deployed w/o unpacking the war/zip.

Interesting idea.  I'll give that a try also.

> Now for the example, I'm getting the following error:
> javax.naming.NameNotFoundException: Name "org.acme.TestServlet/ejb"  
> not found.
>
> I tried out your example by adding it to the previous example Karan  
> posted but even
> that one no longer works for me:
> javax.naming.NameNotFoundException: Name  
> "GreetingBeanBusinessRemote" not found.
>
> Maybe I'm still missing something?

Can you try my example directly?  There may be something wrong with  
Karan's example or maybe remote business interfaces are broken.

-dain

Re: Annotations working in Tomcat

Posted by Dario Laverde <da...@nycjava.net>.
Dain,

Thanks for the work! I've updated the "New Instructions" adding the manual steps for
Windows users, you can try including this in your installer. Just a minor comment, I
also copied the agent jar in addition to the loader jar into Tomcat's lib folder
because hardcoding to webapps/openejb/lib may be a problem should webapps be changed
or openejb be deployed w/o unpacking the war/zip.

Now for the example, I'm getting the following error:
javax.naming.NameNotFoundException: Name "org.acme.TestServlet/ejb" not found.

I tried out your example by adding it to the previous example Karan posted but even
that one no longer works for me:
javax.naming.NameNotFoundException: Name "GreetingBeanBusinessRemote" not found.

Maybe I'm still missing something?

-Dario

> I got annotations mostly working in Tomcat.  To try this out, install
> OpenEJB into Tomcat as noted before and simply add @EJB and @Resource
> annotations to your servlet fields.  I added an very simply servlet-
> samples application which can be checked out with:
>
>    svn co http://svn.apache.org/repos/asf/openejb/trunk/openejb3/
> examples/servlet-samples
>
> This is a completely standalone sample and should be an easy starting
> point.  One critical thing to note about the example is the use of
> <scope>provided</scope> in the maven pom.xml file to stop maven from
> including duplicate copies of the annotation classes into the web
> application.
>
>
> For those that don't want to download the code, here is it:
>
> public class AnnotatedServlet extends HttpServlet {
>      @EJB private AnnotatedEJBLocal ejb;
>
>      @Resource private DataSource ds;
>
>      protected void doGet(HttpServletRequest request,
> HttpServletResponse response) throws ServletException, IOException {
>          response.setContentType("text/plain");
>          ServletOutputStream out = response.getOutputStream();
>
>          out.println("@EJB=" + ejb);
>          if (ejb != null) {
>              out.println("@EJB.getName()=" + ejb.getName());
>              out.println("@EJB.getDs()=" + ejb.getDs());
>          }
>
>          out.println("@Resource=" + ds);
>      }
> }
>
> @Stateless
> public class AnnotatedEJB implements AnnotatedEJBLocal {
>      @Resource private DataSource ds;
>      private String name = "foo";
>
>      public String getName() {
>          return name;
>      }
>
>      public void setName(String name) {
>          this.name = name;
>      }
>
>      public DataSource getDs() {
>          return ds;
>      }
>
>      public void setDs(DataSource ds) {
>          this.ds = ds;
>      }
>
>      public String toString() {
>          return "AnnotatedEJB[name=" + name + "]";
>      }
> }
>
> public interface AnnotatedEJBLocal {
>      String getName();
>
>      void setName(String name);
>
>      DataSource getDs();
>
>      void setDs(DataSource ds);
> }
>
> <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">
>
>    <display-name>OpenEJB Servlet Examples</display-name>
>
>    <servlet>
>      <servlet-name>AnnotatedServlet</servlet-name>
>      <servlet-
> class>org.apache.openejb.examples.servlet.AnnotatedServlet</servlet-
> class>
>    </servlet>
>
>    <servlet-mapping>
>      <servlet-name>AnnotatedServlet</servlet-name>
>      <url-pattern>/annotated/*</url-pattern>
>    </servlet-mapping>
> </web-app>
>
> I'm going to be tuning the code over the next couple of days, but it
> generally works now.  Let me know if you find any bugs, or most
> importantly if it doesn't work as you would expect Tomcat to work.
> One of my goals is to not violate any expectations of Tomcat users,
> so if something stops working like is used to do, let me know ASAP.
> The integration should feel like the Tomcat team wrote it themselves.
>
> -dain
>



Re: Annotations working in Tomcat

Posted by Manu George <ma...@gmail.com>.
This is super cool. Great job Dain.

Regards
Manu

On 9/18/07, Dain Sundstrom <da...@iq80.com> wrote:
> I got annotations mostly working in Tomcat.  To try this out, install
> OpenEJB into Tomcat as noted before and simply add @EJB and @Resource
> annotations to your servlet fields.  I added an very simply servlet-
> samples application which can be checked out with:
>
>    svn co http://svn.apache.org/repos/asf/openejb/trunk/openejb3/
> examples/servlet-samples
>
> This is a completely standalone sample and should be an easy starting
> point.  One critical thing to note about the example is the use of
> <scope>provided</scope> in the maven pom.xml file to stop maven from
> including duplicate copies of the annotation classes into the web
> application.
>
>
> For those that don't want to download the code, here is it:
>
> public class AnnotatedServlet extends HttpServlet {
>      @EJB private AnnotatedEJBLocal ejb;
>
>      @Resource private DataSource ds;
>
>      protected void doGet(HttpServletRequest request,
> HttpServletResponse response) throws ServletException, IOException {
>          response.setContentType("text/plain");
>          ServletOutputStream out = response.getOutputStream();
>
>          out.println("@EJB=" + ejb);
>          if (ejb != null) {
>              out.println("@EJB.getName()=" + ejb.getName());
>              out.println("@EJB.getDs()=" + ejb.getDs());
>          }
>
>          out.println("@Resource=" + ds);
>      }
> }
>
> @Stateless
> public class AnnotatedEJB implements AnnotatedEJBLocal {
>      @Resource private DataSource ds;
>      private String name = "foo";
>
>      public String getName() {
>          return name;
>      }
>
>      public void setName(String name) {
>          this.name = name;
>      }
>
>      public DataSource getDs() {
>          return ds;
>      }
>
>      public void setDs(DataSource ds) {
>          this.ds = ds;
>      }
>
>      public String toString() {
>          return "AnnotatedEJB[name=" + name + "]";
>      }
> }
>
> public interface AnnotatedEJBLocal {
>      String getName();
>
>      void setName(String name);
>
>      DataSource getDs();
>
>      void setDs(DataSource ds);
> }
>
> <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">
>
>    <display-name>OpenEJB Servlet Examples</display-name>
>
>    <servlet>
>      <servlet-name>AnnotatedServlet</servlet-name>
>      <servlet-
> class>org.apache.openejb.examples.servlet.AnnotatedServlet</servlet-
> class>
>    </servlet>
>
>    <servlet-mapping>
>      <servlet-name>AnnotatedServlet</servlet-name>
>      <url-pattern>/annotated/*</url-pattern>
>    </servlet-mapping>
> </web-app>
>
> I'm going to be tuning the code over the next couple of days, but it
> generally works now.  Let me know if you find any bugs, or most
> importantly if it doesn't work as you would expect Tomcat to work.
> One of my goals is to not violate any expectations of Tomcat users,
> so if something stops working like is used to do, let me know ASAP.
> The integration should feel like the Tomcat team wrote it themselves.
>
> -dain
>