Return-Path: Delivered-To: apmail-geronimo-dev-archive@www.apache.org Received: (qmail 98602 invoked from network); 14 Apr 2011 07:44:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Apr 2011 07:44:23 -0000 Received: (qmail 12308 invoked by uid 500); 14 Apr 2011 07:44:23 -0000 Delivered-To: apmail-geronimo-dev-archive@geronimo.apache.org Received: (qmail 12255 invoked by uid 500); 14 Apr 2011 07:44:22 -0000 Mailing-List: contact dev-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list dev@geronimo.apache.org Received: (qmail 12237 invoked by uid 99); 14 Apr 2011 07:44:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Apr 2011 07:44:20 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of xhhsld@gmail.com designates 209.85.210.182 as permitted sender) Received: from [209.85.210.182] (HELO mail-iy0-f182.google.com) (209.85.210.182) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Apr 2011 07:44:14 +0000 Received: by iyj12 with SMTP id 12so1585127iyj.13 for ; Thu, 14 Apr 2011 00:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=9Ss6aXxRQRpfD/v24u3xw3hczlaNkpzxLChDpNE67FE=; b=ZmOcD9cq/3fZSTXnrK+tQPbHmeVgwCgPa11/YTTtIsUQK0n8rFtPV+NLgvZC/4cyTu T8lsBPuOl8aEc1joKLfKMXXYyX3VTcjAPyfF0S825fkJSVx7dpXL/W68FsxQpy6TBQrS vdcEAoiQU4liZqcPvSVCLRV7wqM6UxJ6Du8xI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=A9/NuWMvwFOnBTfY18cz5MpKB9H3hQdAHMKr17zWsZycQStjiRND/YsVK6634yydGg WkUAS1oVnc9b8XVK1/g2yp2e+DkwipKNNHa0VWVL/59DG9nxeO5Z/9Ly+rpTXWq27346 4mxj5YUespv3U/DQkNbJC7UPFbSaUueiG7EKE= MIME-Version: 1.0 Received: by 10.231.193.133 with SMTP id du5mr404135ibb.100.1302767033981; Thu, 14 Apr 2011 00:43:53 -0700 (PDT) Received: by 10.231.145.193 with HTTP; Thu, 14 Apr 2011 00:43:53 -0700 (PDT) In-Reply-To: References: Date: Thu, 14 Apr 2011 15:43:53 +0800 Message-ID: Subject: Re: [Disscussion] Reference binded in JNDI is not dereferenced properly when lookup From: Ivan To: dev@geronimo.apache.org Content-Type: multipart/alternative; boundary=005045017434491a0604a0dc1608 --005045017434491a0604a0dc1608 Content-Type: text/plain; charset=ISO-8859-1 I investigated it a bit, the problem should be we need to register the TranqlDataSource.SelfObjectFactory as a service somewhere, maybe it should be done by tranql itself, or be done while Geronimo binds the datasource into the jndi tree. 2011/4/14 Shenghao Fang > Actually I thought the problem is caused by that we use > OSGiObjectFactoryBuilder to initialize the object, and > OSGiObjectFactoryBuilder tries to initialize the object by OSGi > services, but the jdbc driver (tranql) is not a bundle (it is not > required to be a bundle), so the initialization fails and the > Reference itself returned. > > I debugged into the following method, it uses OSGi services to > initialize the object, but since the jdbc driver is not a bundle, > ServiceReference[] refs is null, and the initialization fails. > > org.apache.aries.jndi.ObjectFactoryHelper: 196 > > private Object getObjectInstanceUsingClassName(Object reference, > String className, > Object obj, > Name name, > Context nameCtx, > Hashtable > environment) > throws Exception { > ServiceReference serviceReference = null; > > try { > ServiceReference[] refs = > defaultContext.getServiceReferences(className, null); > if (refs != null && refs.length > 0) { > serviceReference = refs[0]; > } > } catch (InvalidSyntaxException e) { > // should not happen > throw new RuntimeException("Invalid filter", e); > } > > Object result = null; > > if (serviceReference != null) { > ObjectFactory factory = (ObjectFactory) > defaultContext.getService(serviceReference); > try { > result = factory.getObjectInstance(reference, name, > nameCtx, environment); > } finally { > defaultContext.ungetService(serviceReference); > } > } > > return (result == null) ? obj : result; > } > > And in doGetObjectInstance method, the methods > 'getObjectInstanceUsingRefAddress', > 'getObjectInstanceUsingObjectFactoryBuilders', > 'getObjectInstanceUsingObjectFactories' also use the OSGi way as what > getObjectInstanceUsingClassName does. > > org.apache.aries.jndi.ObjectFactoryHelper: 62 > > private Object doGetObjectInstance(Object obj, > Name name, > Context nameCtx, > Hashtable environment) > throws Exception { > > // Step 1 > if (obj instanceof Referenceable) { > obj = ((Referenceable) obj).getReference(); > } > > Object result = obj; > > // Step 2 > if (obj instanceof Reference) { > Reference ref = (Reference) obj; > String className = ref.getFactoryClassName(); > > if (className != null) { > // Step 3 > result = getObjectInstanceUsingClassName(obj, > className, obj, name, nameCtx, environment); > } else { > // Step 4 > result = > getObjectInstanceUsingRefAddress(ref.getAll(), obj, name, nameCtx, > environment); > } > } > > // Step 5 > if (result == null || result == obj) { > result = getObjectInstanceUsingObjectFactoryBuilders(obj, > name, nameCtx, environment); > } > > // Step 6 > if (result == null || result == obj) { > if ((obj instanceof Reference && ((Reference) > obj).getFactoryClassName() == null) || > !(obj instanceof Reference)) { > result = getObjectInstanceUsingObjectFactories(obj, > name, nameCtx, environment); > } > } > > return (result == null) ? obj : result; > } > > The solution in mind currently is setting a different > ObjectFactoryBuilder instead of OSGiObjectFactoryBuilder on > NamingManager for those plain jars. But where shall I do this? Any > idea? > > 2011/4/14 Shenghao Fang : > > Hi Ivan, > > > > Thanks for your hits. > > > > 2011/4/14 Ivan : > >> From the codes in DataSourceBuilder, the jndi reference is with prefix > >> aries:service, so there should be something like an ObjectFactory would > take > >> care of it. I could see a service > org\apache\aries\jndi\url\Activator.class > >> support this schema is registered in the activator, I simply compared > that > >> Java file between 0.2 and 0.3 seems that some logic is changed, think > this > >> should be a place to begin the debugging. > >> Hope it helps. > >> > >> 2011/4/14 Shenghao Fang > >>> > >>> Hi, > >>> > >>> When I did the enablement for the monitoring portlet, I lookup the > >>> datasource from JNDI and got an object of type javax.naming.Reference > >>> instead of javax.sql.DataSource. > >>> > >>> I debugged into JNDI related modules and found the following clues: > >>> > >>> 1. If the object to be bound is of type javax.naming.Referenceable, > >>> then the object of type javax.naming.Reference retrieved by > >>> Referenceable.getReference() will be bound. And the object should be > >>> dereferenced automatically when lookup. > >>> > >>> 2. When lookup from JNDI, javax.naming.spi.NamingManager tries to use > >>> the ObjectFactoryBuilder set to dereference. In current > >>> implementation, we set org.apache.aries.jndi.OSGiObjectFactoryBuilder > >>> to ObjectFactoryBuilder. > >>> > >>> 3. Since the datasource is not packaged as an OSGi bundle, > >>> OSGiObjectFactoryBuilder returns the Reference directly. > >>> > >>> > >>> I have no idea on how to fix this, any idea? Thanks. > >>> > >>> > >>> -- > >>> Michael > >> > >> > >> > >> -- > >> Ivan > >> > > > > > > > > -- > > Michael > > > > > > -- > Michael > -- Ivan --005045017434491a0604a0dc1608 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I investigated it a bit, the problem should be we need to register the Tran= qlDataSource.SelfObjectFactory as a service somewhere, maybe it should be d= one by tranql itself, or be done while Geronimo binds the datasource into t= he jndi tree.

2011/4/14 Shenghao Fang &l= t;michael1224.fang@gmail.com<= /a>>
Actually I thought the problem is caused by that we use
OSGiObjectFactoryBuilder to initialize the object, and
OSGiObjectFactoryBuilder tries to initialize the object by OSGi
services, but the jdbc driver (tranql) is not a bundle (it is not
required to be a bundle), so the initialization fails and the
Reference itself returned.

I debugged into the following method, it uses OSGi services to
initialize the object, but since the jdbc driver is not a bundle,
ServiceReference[] refs is null, and the initialization fails.

org.apache.aries.jndi.ObjectFactoryHelper: 196

=A0 =A0private Object getObjectInstanceUsingClassName(Object reference, =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 String className,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 Object obj,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 Name name,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 Context nameCtx,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 Hashtable<?, ?> environment)
=A0 =A0 =A0 =A0throws Exception {
=A0 =A0 =A0 =A0ServiceReference serviceReference =3D null;

=A0 =A0 =A0 =A0try {
=A0 =A0 =A0 =A0 =A0 =A0ServiceReference[] refs =3D
defaultContext.getServiceReferences(className, null);
=A0 =A0 =A0 =A0 =A0 =A0if (refs !=3D null && refs.length > 0) {=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0serviceReference =3D refs[0];
=A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0} catch (InvalidSyntaxException e) {
=A0 =A0 =A0 =A0 =A0 =A0// should not happen
=A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException("Invalid filter&quo= t;, e);
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0Object result =3D null;

=A0 =A0 =A0 =A0if (serviceReference !=3D null) {
=A0 =A0 =A0 =A0 =A0 =A0ObjectFactory factory =3D (ObjectFactory)
defaultContext.getService(serviceReference);
=A0 =A0 =A0 =A0 =A0 =A0try {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0result =3D factory.getObjectInstance(refere= nce, name,
nameCtx, environment);
=A0 =A0 =A0 =A0 =A0 =A0} finally {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0defaultContext.ungetService(serviceReferenc= e);
=A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0return (result =3D=3D null) ? obj : result;
=A0 =A0}

And in doGetObjectInstance method, the methods
'getObjectInstanceUsingRefAddress',
'getObjectInstanceUsingObjectFactoryBuilders',
'getObjectInstanceUsingObjectFactories' also use the OSGi way as wh= at
getObjectInstanceUsingClassName does.

org.apache.aries.jndi.ObjectFactoryHelper: 62

=A0 =A0private Object doGetObjectInstance(Object obj,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 Name name,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 Context nameCtx,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 Hashtable<?, ?> environment)
throws Exception {

=A0 =A0 =A0 =A0// Step 1
=A0 =A0 =A0 =A0if (obj instanceof Referenceable) {
=A0 =A0 =A0 =A0 =A0 =A0obj =3D ((Referenceable) obj).getReference();
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0Object result =3D obj;

=A0 =A0 =A0 =A0// Step 2
=A0 =A0 =A0 =A0if (obj instanceof Reference) {
=A0 =A0 =A0 =A0 =A0 =A0Reference ref =3D (Reference) obj;
=A0 =A0 =A0 =A0 =A0 =A0String className =3D ref.getFactoryClassName();

=A0 =A0 =A0 =A0 =A0 =A0if (className !=3D null) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// Step 3
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0result =3D getObjectInstanceUsingClassName(= obj,
className, obj, name, nameCtx, environment);
=A0 =A0 =A0 =A0 =A0 =A0} else {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// Step 4
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0result =3D
getObjectInstanceUsingRefAddress(ref.getAll(), obj, name, nameCtx,
environment);
=A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0// Step 5
=A0 =A0 =A0 =A0if (result =3D=3D null || result =3D=3D obj) {
=A0 =A0 =A0 =A0 =A0 =A0result =3D getObjectInstanceUsingObjectFactoryBuild= ers(obj,
name, nameCtx, environment);
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0// Step 6
=A0 =A0 =A0 =A0if (result =3D=3D null || result =3D=3D obj) {
=A0 =A0 =A0 =A0 =A0 =A0if ((obj instanceof Reference && ((Referenc= e)
obj).getFactoryClassName() =3D=3D null) ||
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0!(obj instanceof Reference)) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0result =3D getObjectInstanceUsingObjectFact= ories(obj,
name, nameCtx, environment);
=A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0return (result =3D=3D null) ? obj : result;
=A0 =A0}

The solution in mind currently is setting a different
ObjectFactoryBuilder instead of OSGiObjectFactoryBuilder on
NamingManager for those plain jars. But where shall I do this? Any
idea?

2011/4/14 Shenghao Fang <
m= ichael1224.fang@gmail.com>:
> Hi Ivan,
>
> Thanks for your hits.
>
> 2011/4/14 Ivan <xhhsld@gmail.co= m>:
>> From the codes in DataSourceBuilder, the jndi reference is with pr= efix
>> aries:service, so there should be something like an ObjectFactory = would take
>> care of it. I could see a service org\apache\aries\jndi\url\Activa= tor.class
>> support this schema is registered in the activator, I simply compa= red that
>> Java file between 0.2 and 0.3 seems that some logic is changed, th= ink this
>> should be a place to begin the debugging.
>> Hope it helps.
>>
>> 2011/4/14 Shenghao Fang <michael1224.fang@gmail.com>
>>>
>>> Hi,
>>>
>>> When I did the enablement for the monitoring portlet, I lookup= the
>>> datasource from JNDI and got an object of type javax.naming.Re= ference
>>> instead of javax.sql.DataSource.
>>>
>>> I debugged into JNDI related modules and found the following c= lues:
>>>
>>> 1. If the object to be bound is of type javax.naming.Reference= able,
>>> then the object of type javax.naming.Reference retrieved by >>> Referenceable.getReference() will be bound. And the object sho= uld be
>>> dereferenced automatically when lookup.
>>>
>>> 2. When lookup from JNDI, javax.naming.spi.NamingManager tries= to use
>>> the ObjectFactoryBuilder set to dereference. In current
>>> implementation, we set org.apache.aries.jndi.OSGiObjectFactory= Builder
>>> to ObjectFactoryBuilder.
>>>
>>> 3. Since the datasource is not packaged as an OSGi bundle,
>>> OSGiObjectFactoryBuilder returns the Reference directly.
>>>
>>>
>>> I have no idea on how to fix this, any idea? Thanks.
>>>
>>>
>>> --
>>> Michael
>>
>>
>>
>> --
>> Ivan
>>
>
>
>
> --
> Michael
>



--
Michael



--
Ivan
--005045017434491a0604a0dc1608--