You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by dsthode <da...@juntadeandalucia.es> on 2008/07/01 13:40:28 UTC

Re: Use of a GBean from a Message EJB

Hi manucet,

I've followed your advice and changed the default namespace to openejb
version 2.2 and added a <pattern> element for the <gbean-ref> resolution,
but Geronimo keeps failing on deployment with the message that <ref-name> is
not in geronimo-namespace-1.2 schema but in
http://openejb.apache.org/xml/ns/openejb-jar-2.2, even though you can open
geronimo-naming-1.2 and find <ref-name> defined in this schema.

Also I've tried to find the schema definition for openejb-jar-2.2 but every
URL I've followed links to a missing document.

Even I updated my Geronimo Eclipse plugin to a nightly build of the 2.1
branch, but with no success, Geronimo keeps showing the same error when
deploying:

[severity=ERROR,message=unexpected element
(uri:"http://geronimo.apache.org/xml/ns/naming-1.2", local:"ref-name").
Expected elements are
<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}ref-type>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}pattern>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}ref-name>,locator=[node=null,object=null,url=null,line=44,col=24,offset=-1]]

So I'm a bit lost right now, as I can't deploy my application if I include
the <gbean-ref> part in the ejb deployment descriptor. Nobody here ever
tried to deploy an EJB that references a GBean?

Thank you.


manucet wrote:
> 
> I see 2 errors in the plan
> 
> 1) In your openejb-jar.xml file you are setting the default namespace
> "http://www.openejb.org/xml/ns/openejb-jar-2.1" instead of 2.2 but
> anyway that should be taken care of by g
> 
> 2) In the gbean-ref you are only giving the ref-name but u need to
> provide a mapping of that refname to the actual gbean by giving the
> pattern/ ref-type elements. If you give the pattern element then you
> need to specify the name of your gbean inside that element inside the
> name tag.
> 
> However I guess both these should not cause the problem you are
> experiencing
> 
> Another thing you can try is to call
> org.apache.geronimo.kernel.KernelRegistry.getSingleKernel(); from
> within the ejb. This will give you the kernel from which you can get
> the gbean by executing a gbean query. Using gbean refs is the better
> approach though.
> 
> regards
> Manu
> 
> On Wed, Jun 25, 2008 at 4:39 PM, dsthode
> <da...@juntadeandalucia.es> wrote:
>>
>> Hello all,
>>
>> I'm trying to deploy an enterprise application in Geronimo 2.1.1 wich
>> makes
>> use of a GBean from inside a Message EJB. That GBean is a custom
>> developed
>> GBean that creates a thread and uses the persistence unit defined in my
>> persistence.xml as well as a ConnectionFactory and a Topic for a JMS
>> destination, all of them injected with the <reference> tags in the
>> <gbean>
>> definition. All that does not represent a problem as all the injections
>> work
>> right and I've created the connection to the JMS destination from my
>> GBean
>> with no major trouble.
>>
>> My problem comes when I try to reference that GBean from my Message EJB.
>> I've tried to add a <gbean-ref> to the <message-driven> definition of
>> this
>> MDB but I get the following exception when deploying (see below for the
>> openejb-jar.xml):
>>
>> [severity=ERROR,message=unexpected element
>> (uri:"http://geronimo.apache.org/xml/ns/naming-1.2", local:"ref-name").
>> Expected elements are <{http://openejb.apache.org/xml/n
>> s/openejb-jar-2.2}ref-type>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}pattern>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}ref-name>,locator=[node=null,ob
>> ject=null,url=null,line=38,col=15,offset=-1]]
>>
>> If anyone needs the details for the exception stack trace I can post
>> them,
>> but I think the error message is explanatory enough and the stack trace
>> is
>> quite too long.
>>
>> I've checked all the xsd files and <ref-name> is defined inside a
>> <gbean-ref> tag and it belongs to the geronimo-naming-1.2 schema , so I
>> don't get the meaning of this message.
>>
>> Also I've tried to change the namespace to the <ref-name> tag and set it
>> to
>> <ref-name xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"> as
>> the
>> error message suggests, but fails with the same error message. And i've
>> tried to prepend the "nam:" namespace to the <ref-name> tag also, but
>> with
>> no success either.
>>
>> And another question is, when I set the reference in my openejb-jar.xml,
>> how
>> do I use this GBean from my MDB? I've tried to set a @Reference
>> annotation
>> but I guess this is not going to work as I think it's only for JDBC, JMS
>> and
>> the like resources, not for GBeans.
>>
>> This is my openejb-jar.xml file:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
>>                        
>> xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2"
>>                        
>> xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
>>                        
>> xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
>>                        
>> xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
>>  <sys:environment>
>>    <sys:moduleId>
>>      <sys:groupId>sampleGroup</sys:groupId>
>>      <sys:artifactId>sample_EJB</sys:artifactId>
>>      <sys:version>1.0</sys:version>
>>      <sys:type>car</sys:type>
>>    </sys:moduleId>
>>        <sys:dependencies>
>>                <sys:dependency>
>>                        <sys:groupId>console.dbpool</sys:groupId>
>>                        <sys:artifactId>sampleDS</sys:artifactId>
>>                </sys:dependency>
>>        <sys:dependency>
>>                        <sys:groupId>console.jms</sys:groupId>
>>                       
>> <sys:artifactId>sampleMsgResources</sys:artifactId>
>>                </sys:dependency>
>>        </sys:dependencies>
>>  </sys:environment>
>>  <enterprise-beans>
>>                <session>
>>                        <ejb-name>Bean1</ejb-name>
>>                </session>
>>                <session>
>>                        <ejb-name>Bean2</ejb-name>
>>                </session>
>>                <message-driven>
>>                        <ejb-name>MDBBean1</ejb-name>
>>                        <resource-adapter>
>>                               
>> <resource-link>sampleMsgResources</resource-link>
>>                        </resource-adapter>
>>                        <gbean-ref>
>> <!-- the next tag is causing trouble with an "unexpected element"
>> exception
>> -->
>>                                <ref-name>UpdatesProcessorGBean</ref-name>
>>                        </gbean-ref>
>>                </message-driven>
>>                <message-driven>
>>                        <ejb-name>MDBBean2</ejb-name>
>>                        <resource-adapter>
>>                               
>> <resource-link>sampleMsgResources</resource-link>
>>                        </resource-adapter>
>>                </message-driven>
>>  </enterprise-beans>
>>  <sys:gbean name="UpdatesProcessorGBean"
>> class="sample.gbean.GBeanUpdatesProcessor">
>> <!-- this is the persistence unit defined in persistence.xml -->
>>        <reference name="samplePU">
>>                <name>samplePU</name>
>>        </reference>
>> <!-- this is a connection factory defined in sampleMsgResources -->
>>        <reference name="UpdatesConnectionFactory">
>>                <name>UpdatesListasConnectionFactory</name>
>>        </reference>
>> <!-- this is a Topic defined in sampleMsgResources -->
>>        <reference name="sampleTopic">
>>                <name>sampleTopic</name>
>>        </reference>
>>  </sys:gbean>
>> </openejb-jar>
>>
>> If anyone has an idea, please help me, as I'm stuck and I don't know
>> where
>> to go next.
>>
>> Thank you.
>> --
>> View this message in context:
>> http://www.nabble.com/Use-of-a-GBean-from-a-Message-EJB-tp18109820s134p18109820.html
>> Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Use-of-a-GBean-from-a-Message-EJB-tp18109820s134p18214130.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Use of a GBean from a Message EJB

Posted by Manu George <ma...@gmail.com>.
Hi Damian ,

     Why don't you try giving the namespace for the ref-name element
as ref-name may be present in both the schemas, If still it doesn't
work it will be helpful if you can attach a sample that replicates the
problem

Regards
Manu

On Tue, Jul 1, 2008 at 5:10 PM, dsthode
<da...@juntadeandalucia.es> wrote:
>
> Hi manucet,
>
> I've followed your advice and changed the default namespace to openejb
> version 2.2 and added a <pattern> element for the <gbean-ref> resolution,
> but Geronimo keeps failing on deployment with the message that <ref-name> is
> not in geronimo-namespace-1.2 schema but in
> http://openejb.apache.org/xml/ns/openejb-jar-2.2, even though you can open
> geronimo-naming-1.2 and find <ref-name> defined in this schema.
>
> Also I've tried to find the schema definition for openejb-jar-2.2 but every
> URL I've followed links to a missing document.
>
> Even I updated my Geronimo Eclipse plugin to a nightly build of the 2.1
> branch, but with no success, Geronimo keeps showing the same error when
> deploying:
>
> [severity=ERROR,message=unexpected element
> (uri:"http://geronimo.apache.org/xml/ns/naming-1.2", local:"ref-name").
> Expected elements are
> <{http://openejb.apache.org/xml/ns/openejb-jar-2.2}ref-type>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}pattern>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}ref-name>,locator=[node=null,object=null,url=null,line=44,col=24,offset=-1]]
>
> So I'm a bit lost right now, as I can't deploy my application if I include
> the <gbean-ref> part in the ejb deployment descriptor. Nobody here ever
> tried to deploy an EJB that references a GBean?
>
> Thank you.
>
>
> manucet wrote:
>>
>> I see 2 errors in the plan
>>
>> 1) In your openejb-jar.xml file you are setting the default namespace
>> "http://www.openejb.org/xml/ns/openejb-jar-2.1" instead of 2.2 but
>> anyway that should be taken care of by g
>>
>> 2) In the gbean-ref you are only giving the ref-name but u need to
>> provide a mapping of that refname to the actual gbean by giving the
>> pattern/ ref-type elements. If you give the pattern element then you
>> need to specify the name of your gbean inside that element inside the
>> name tag.
>>
>> However I guess both these should not cause the problem you are
>> experiencing
>>
>> Another thing you can try is to call
>> org.apache.geronimo.kernel.KernelRegistry.getSingleKernel(); from
>> within the ejb. This will give you the kernel from which you can get
>> the gbean by executing a gbean query. Using gbean refs is the better
>> approach though.
>>
>> regards
>> Manu
>>
>> On Wed, Jun 25, 2008 at 4:39 PM, dsthode
>> <da...@juntadeandalucia.es> wrote:
>>>
>>> Hello all,
>>>
>>> I'm trying to deploy an enterprise application in Geronimo 2.1.1 wich
>>> makes
>>> use of a GBean from inside a Message EJB. That GBean is a custom
>>> developed
>>> GBean that creates a thread and uses the persistence unit defined in my
>>> persistence.xml as well as a ConnectionFactory and a Topic for a JMS
>>> destination, all of them injected with the <reference> tags in the
>>> <gbean>
>>> definition. All that does not represent a problem as all the injections
>>> work
>>> right and I've created the connection to the JMS destination from my
>>> GBean
>>> with no major trouble.
>>>
>>> My problem comes when I try to reference that GBean from my Message EJB.
>>> I've tried to add a <gbean-ref> to the <message-driven> definition of
>>> this
>>> MDB but I get the following exception when deploying (see below for the
>>> openejb-jar.xml):
>>>
>>> [severity=ERROR,message=unexpected element
>>> (uri:"http://geronimo.apache.org/xml/ns/naming-1.2", local:"ref-name").
>>> Expected elements are <{http://openejb.apache.org/xml/n
>>> s/openejb-jar-2.2}ref-type>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}pattern>,<{http://openejb.apache.org/xml/ns/openejb-jar-2.2}ref-name>,locator=[node=null,ob
>>> ject=null,url=null,line=38,col=15,offset=-1]]
>>>
>>> If anyone needs the details for the exception stack trace I can post
>>> them,
>>> but I think the error message is explanatory enough and the stack trace
>>> is
>>> quite too long.
>>>
>>> I've checked all the xsd files and <ref-name> is defined inside a
>>> <gbean-ref> tag and it belongs to the geronimo-naming-1.2 schema , so I
>>> don't get the meaning of this message.
>>>
>>> Also I've tried to change the namespace to the <ref-name> tag and set it
>>> to
>>> <ref-name xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"> as
>>> the
>>> error message suggests, but fails with the same error message. And i've
>>> tried to prepend the "nam:" namespace to the <ref-name> tag also, but
>>> with
>>> no success either.
>>>
>>> And another question is, when I set the reference in my openejb-jar.xml,
>>> how
>>> do I use this GBean from my MDB? I've tried to set a @Reference
>>> annotation
>>> but I guess this is not going to work as I think it's only for JDBC, JMS
>>> and
>>> the like resources, not for GBeans.
>>>
>>> This is my openejb-jar.xml file:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
>>>
>>> xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2"
>>>
>>> xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
>>>
>>> xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
>>>
>>> xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
>>>  <sys:environment>
>>>    <sys:moduleId>
>>>      <sys:groupId>sampleGroup</sys:groupId>
>>>      <sys:artifactId>sample_EJB</sys:artifactId>
>>>      <sys:version>1.0</sys:version>
>>>      <sys:type>car</sys:type>
>>>    </sys:moduleId>
>>>        <sys:dependencies>
>>>                <sys:dependency>
>>>                        <sys:groupId>console.dbpool</sys:groupId>
>>>                        <sys:artifactId>sampleDS</sys:artifactId>
>>>                </sys:dependency>
>>>        <sys:dependency>
>>>                        <sys:groupId>console.jms</sys:groupId>
>>>
>>> <sys:artifactId>sampleMsgResources</sys:artifactId>
>>>                </sys:dependency>
>>>        </sys:dependencies>
>>>  </sys:environment>
>>>  <enterprise-beans>
>>>                <session>
>>>                        <ejb-name>Bean1</ejb-name>
>>>                </session>
>>>                <session>
>>>                        <ejb-name>Bean2</ejb-name>
>>>                </session>
>>>                <message-driven>
>>>                        <ejb-name>MDBBean1</ejb-name>
>>>                        <resource-adapter>
>>>
>>> <resource-link>sampleMsgResources</resource-link>
>>>                        </resource-adapter>
>>>                        <gbean-ref>
>>> <!-- the next tag is causing trouble with an "unexpected element"
>>> exception
>>> -->
>>>                                <ref-name>UpdatesProcessorGBean</ref-name>
>>>                        </gbean-ref>
>>>                </message-driven>
>>>                <message-driven>
>>>                        <ejb-name>MDBBean2</ejb-name>
>>>                        <resource-adapter>
>>>
>>> <resource-link>sampleMsgResources</resource-link>
>>>                        </resource-adapter>
>>>                </message-driven>
>>>  </enterprise-beans>
>>>  <sys:gbean name="UpdatesProcessorGBean"
>>> class="sample.gbean.GBeanUpdatesProcessor">
>>> <!-- this is the persistence unit defined in persistence.xml -->
>>>        <reference name="samplePU">
>>>                <name>samplePU</name>
>>>        </reference>
>>> <!-- this is a connection factory defined in sampleMsgResources -->
>>>        <reference name="UpdatesConnectionFactory">
>>>                <name>UpdatesListasConnectionFactory</name>
>>>        </reference>
>>> <!-- this is a Topic defined in sampleMsgResources -->
>>>        <reference name="sampleTopic">
>>>                <name>sampleTopic</name>
>>>        </reference>
>>>  </sys:gbean>
>>> </openejb-jar>
>>>
>>> If anyone has an idea, please help me, as I'm stuck and I don't know
>>> where
>>> to go next.
>>>
>>> Thank you.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Use-of-a-GBean-from-a-Message-EJB-tp18109820s134p18109820.html
>>> Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Use-of-a-GBean-from-a-Message-EJB-tp18109820s134p18214130.html
> Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>
>

Re: Use of a GBean from a Message EJB

Posted by dsthode <da...@juntadeandalucia.es>.
Hello Jacek,

Not exactly, at least following the path of the <gbean-ref>. I took the
other approach manucet suggested, using the Kernel object from my message
bean and finding the GBean. That way it worked quite well.

But now I'm facing another problem: my message bean acquires the reference
to an object (call it UpdatesProcessor) from the GBean, which is in charge
of the inserts and updates to a database using entity beans with the data
received in my message bean. This UpdatesProcessor objects runs on it's own
thread (implements Runnable), and schedules all the operations to the
database to be executed by a timestamp attribute.

My problem comes when this UpdatesProcessor object tries to persist the
entities, because Geronimo says there is no active transaction and throws a
javax.persistence.TransactionRequiredException

The way it works is this: my GBean is injected with the reference to my
PersistenceUnit and from there I get the reference to the EntityManager.
This EntityManager is then passed to the UpdatesProcessor via its
constructor (this UpdatesProcessor is created and started inside the GBean
doStart() method), so it can find entities. Everything works right up to the
line where I call the persist() method of the EntityManager, with the
aforementioned exception.

>From there on, I've tried to find a transaction manager gbean in Geronimo,
to inject it to my own GBean and then to my UpdatesProcessor object. I've
found an object with a promising name,
org.apache.geronimo.transacion.manager.GeronimoTransacionManagerGBean, and
the JMX console shows it has methods for beginning, committing and rolling
back transactions. So, I inject my GBean with a reference to this
GeronimoTransactionManagerGBean, then get its TransactionManager interface
and pass it to my UpdatesProcessor object. But when I try to call persist()
on my EntityManager inside the UpdatesProcessor thread proc, Geronimo keeps
complaining about the same "No active transaction" error message and
TransactionRequiredException, even though I've surrounded this persist()
method call with the corresponding TransactionManager.begin() and
TransactionManager.commit().

I'm sure there is something wrong in my doings, but as I have not much idea
of Geronimo internals, I can't do much more. Now, I'll have to look inside
Geronimo to try to figure out how the persistence layer handles transactions
and see if I can somehow link the TransactionManager reference with the
EntityManager object to make them work together.

If anyone has advice, it's more than welcome :)



Jacek Laskowski wrote:
> 
> On Tue, Jul 1, 2008 at 1:40 PM, dsthode
> <da...@juntadeandalucia.es> wrote:
> 
>> I've followed your advice and changed the default namespace to openejb
>> version 2.2 and added a <pattern> element for the <gbean-ref> resolution,
>> but Geronimo keeps failing on deployment with the message that <ref-name>
>> is
>> not in geronimo-namespace-1.2 schema but in
>> http://openejb.apache.org/xml/ns/openejb-jar-2.2, even though you can
>> open
>> geronimo-naming-1.2 and find <ref-name> defined in this schema.
> 
> Did you happen to sort it out? What was the solution?
> 
> Jacek
> 
> -- 
> Jacek Laskowski
> Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl
> 
> 

-- 
View this message in context: http://www.nabble.com/Use-of-a-GBean-from-a-Message-EJB-tp18109820s134p18313576.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Use of a GBean from a Message EJB

Posted by Janko Heilgeist <ja...@rzg.mpg.de>.
Jacek Laskowski wrote:
> On Tue, Jul 1, 2008 at 1:40 PM, dsthode
> <da...@juntadeandalucia.es> wrote:
> 
>> I've followed your advice and changed the default namespace to openejb
>> version 2.2 and added a <pattern> element for the <gbean-ref> resolution,
>> but Geronimo keeps failing on deployment with the message that <ref-name> is
>> not in geronimo-namespace-1.2 schema but in
>> http://openejb.apache.org/xml/ns/openejb-jar-2.2, even though you can open
>> geronimo-naming-1.2 and find <ref-name> defined in this schema.
> 
> Did you happen to sort it out? What was the solution?
> 
> Jacek
> 

Hi,

I think I've traced the problem to a bug in OpenEJB:

OpenEJB forces the namespace of the tags <ref-name> and <ref-type> to 
"http://geronimo.apache.org/xml/ns/naming-1.2" in 
container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb2/NamespaceFilter.java 
regardless of the namespace specified in the openejb-jar.xml deployment 
descriptor. On the other hand the "namespace" attributes in the 
@XmlElement annotations in 
container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb2/GbeanRefType.java
are missing for these variables and therefore during the parsing of the 
deployment descriptor the wrong default namespace of 
"http://openejb.apache.org/xml/ns/openejb-jar-2.2" is expected. The 
patch attached to this mail fixes this by adding the missing attributes.

I used my patched version of OpenEJB with Geronimo to access a GBean 
from a stateless EJB:

openejb-jar.xml:
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.2">
	<enterprise-beans>
		<session>
			<ejb-name>DummyEJB</ejb-name>
			<gbean-ref>
				<ref-name>LocalGBeanName</ref-name>
				<pattern>
					<name>GlobalGBeanName</name>
				</pattern>
			</gbean-ref>
		</session>
	</enterprise-beans>
</openejb-jar>

geronimo-application.xml:
[...]
<sys:gbean name="GlobalGBeanName"
class="com.heilgeist.tests.tst_geronimo_gbean.gbean.TheGBeanClass"/>
[...]

Inside a @PostConstruct of the EJB class:
[...]
InitialContext ic = new InitialContext();
this.theGBean = (TheGBeanClass)
	ic.lookup("java:comp/geronimo/env/LocalGBeanName");
[...]

Everything deploys without any errors and the EJB can correctly access 
the GBean and call methods of the GBean. There doesn't seem to be a way 
to actually inject the GBean with something like a @Resource annotation. 
Is this supposed to work or can GBeans only be injected into an EJBs 
JNDI environment and have to be looked up manually?

Anyway, this should fix most of Damians original problems.

Janko

Re: Use of a GBean from a Message EJB

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Tue, Jul 1, 2008 at 1:40 PM, dsthode
<da...@juntadeandalucia.es> wrote:

> I've followed your advice and changed the default namespace to openejb
> version 2.2 and added a <pattern> element for the <gbean-ref> resolution,
> but Geronimo keeps failing on deployment with the message that <ref-name> is
> not in geronimo-namespace-1.2 schema but in
> http://openejb.apache.org/xml/ns/openejb-jar-2.2, even though you can open
> geronimo-naming-1.2 and find <ref-name> defined in this schema.

Did you happen to sort it out? What was the solution?

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl