You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael-O <19...@gmx.net> on 2012/03/15 21:54:27 UTC

Writing a custom resource factory

Hi folks,

I'd like to write a custom ldap resource factory as same as a data 
source factory. The getObjectInstance method shall return 
InitialDirContext object. I have written a mock factory and noticed that 
the output is cached by Tomcat. So the object is created only once (same 
id in Eclipse debugger).

Now I need to verify that the InitialDirContext is still valid (conn 
timeout, etc.), same as testOnBorrow with DataSource. I won't have any 
reference to it after its creation. This means that I would need to wrap 
that object somehow and perform the operation myself?
This is how Tomcat JDBC Pool does.

Is my assumption correct? If yes, I would need to wrap every sing method 
defined in DirContext and InitialDirContext.

Thanks,

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writing a custom resource factory

Posted by Felix Schumacher <fe...@internetallee.de>.
Am 16.03.2012 09:34, schrieb 1983-01-06@gmx.net:
>> Am 16.03.2012 08:24, schrieb Felix Schumacher:
>> > Am 15.03.2012 21:54, schrieb Michael-O:
>> >> Hi folks,
>> >>
>> >> I'd like to write a custom ldap resource factory as same as a 
>> data
>> >> source factory. The getObjectInstance method shall return
>> >> InitialDirContext object. I have written a mock factory and 
>> noticed
>> >> that the output is cached by Tomcat. So the object is created 
>> only
>> >> once (same id in Eclipse debugger).
>> > I think you can change that behavior, but it will not be necessary 
>> in
>> > your case.
>> I have found it. In
>> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
>> look for "singleton". But I still believe, that you will not need 
>> it.
>
> Felix,
>
> I checked that already. I am on Tomcat 6.0.35, so this is not an
> option for me. Although the Tomcat Pool works great since the
> DataSource is created once. It would contradict if the DataSouce and
> its pool would exist several times.
That is why the singleton property defaults to true. That resembles
the behavior of older tomcats.

And as I told you already, you want a singleton created by tomcat and 
given
to your application. That singleton/factory can then be used to create
DirContext objects.

Look at the example for JavaBean resources in the documentation.

Felix
>
> I'll will share my implementation idea shortly on the list as soon as
> it works.
>
> Mike


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writing a custom resource factory

Posted by 19...@gmx.net.
> Am 16.03.2012 08:24, schrieb Felix Schumacher:
> > Am 15.03.2012 21:54, schrieb Michael-O:
> >> Hi folks,
> >>
> >> I'd like to write a custom ldap resource factory as same as a data
> >> source factory. The getObjectInstance method shall return
> >> InitialDirContext object. I have written a mock factory and noticed
> >> that the output is cached by Tomcat. So the object is created only
> >> once (same id in Eclipse debugger).
> > I think you can change that behavior, but it will not be necessary in
> > your case.
> I have found it. In 
> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
> look for "singleton". But I still believe, that you will not need it.

Felix,

I checked that already. I am on Tomcat 6.0.35, so this is not an option for me. Although the Tomcat Pool works great since the DataSource is created once. It would contradict if the DataSouce and its pool would exist several times.

I'll will share my implementation idea shortly on the list as soon as it works.

Mike
-- 
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                                  
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writing a custom resource factory

Posted by Felix Schumacher <fe...@internetallee.de>.
Am 16.03.2012 08:24, schrieb Felix Schumacher:
> Am 15.03.2012 21:54, schrieb Michael-O:
>> Hi folks,
>>
>> I'd like to write a custom ldap resource factory as same as a data
>> source factory. The getObjectInstance method shall return
>> InitialDirContext object. I have written a mock factory and noticed
>> that the output is cached by Tomcat. So the object is created only
>> once (same id in Eclipse debugger).
> I think you can change that behavior, but it will not be necessary in
> your case.
I have found it. In 
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
look for "singleton". But I still believe, that you will not need it.

Regards
  Felix
>>
>> Now I need to verify that the InitialDirContext is still valid (conn
>> timeout, etc.), same as testOnBorrow with DataSource. I won't have 
>> any
>> reference to it after its creation. This means that I would need to
>> wrap that object somehow and perform the operation myself?
>> This is how Tomcat JDBC Pool does.
>>
>> Is my assumption correct? If yes, I would need to wrap every sing
>> method defined in DirContext and InitialDirContext.
> If you look at the example, you gave. You will see, that the resource 
> created
> a factory for you. That factory manages a pool and creates and 
> validates
> connection objects for you.
>
> So, by using
> 
> http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#Generic_JavaBean_Resources
> you can easily define a resource, which creates a
> DirContext-factory/pool object.
>
> That factory can be the same for the whole application, if you make
> it thread safe.
>
> The factory-method can than manage the pool and validate each
> DirContext object, before it
> hands it out to you. Just remember to give it back to the 
> pool/factory.
>
> Regards
>  Felix
>>
>> Thanks,
>>
>> Mike
>>
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to leave this list?

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/3/16 Purvis Robert (NHS CONNECTING FOR HEALTH) <ro...@nhs.net>:
> Can anyone tell me how to leave this email list? I have tried sending an email to the unsubscribe address, but that has not worked.

Was the mail lost, or there was some specific error message?

There are more detailed instructions here:
http://www.apache.org/foundation/mailinglists.html

If that does not help you can send mail to "list owner" address and he
will unsubscribe you manually.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to leave this list?

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/3/16 Purvis Robert (NHS CONNECTING FOR HEALTH) <ro...@nhs.net>:
> I got no error message. I tried about 5 times (just tried again), emailing to users-unsubscribe@tomcat.apache.org as it says in the footer to this list's emails.


Did your message have subject and some text in the body? Otherwise it
could be rejected by spam filter.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to leave this list?

Posted by Giles Coochey <gi...@coochey.net>.
On 16/03/2012 10:49, Purvis Robert (NHS CONNECTING FOR HEALTH) wrote:
> I got no error message. I tried about 5 times (just tried again), emailing to users-unsubscribe@tomcat.apache.org as it says in the footer to this list's emails.
>
> Rob
>
>
>
Are you sure that you are subscribed with the email that you are 
unsubscribing from?

(Sometimes mailforwarding etc... can deceive you on this).

The best approach would be to contact the list owner directly, I'm sure 
they're not intending to send you emails if they knew you didn't want them.

-- 
Best Regards,

Giles Coochey
NetSecSpec Ltd
UK Mobile: +44 7983 877 438
Business Email: giles.coochey@netsecspec.co.uk
Email/MSN/Live Messenger: giles@coochey.net
Skype: gilescoochey



RE: How to leave this list?

Posted by "Purvis Robert (NHS CONNECTING FOR HEALTH)" <ro...@nhs.net>.
I got no error message. I tried about 5 times (just tried again), emailing to users-unsubscribe@tomcat.apache.org as it says in the footer to this list's emails.

Rob


-----Original Message-----
From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com]
Sent: 16 March 2012 10:24
To: Tomcat Users List
Subject: Re: How to leave this list?

2012/3/16 Purvis Robert (NHS CONNECTING FOR HEALTH) <ro...@nhs.net>:
> Can anyone tell me how to leave this email list? I have tried sending an email to the unsubscribe address, but that has not worked.

Was the mail lost, or there was some specific error message?

There are more detailed instructions here:
http://www.apache.org/foundation/mailinglists.html

If that does not help you can send mail to "list owner" address and he
will unsubscribe you manually.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


********************************************************************************************************************

This message may contain confidential information. If you are not the intended recipient please inform the
sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take any action in reliance on its contents:
to do so is strictly prohibited and may be unlawful.

Thank you for your co-operation.

NHSmail is the secure email and directory service available for all NHS staff in England and Scotland
NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and GSi recipients
NHSmail provides an email address for your career in the NHS and can be accessed anywhere
For more information and to find out how you can switch, visit www.connectingforhealth.nhs.uk/nhsmail

********************************************************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


How to leave this list?

Posted by "Purvis Robert (NHS CONNECTING FOR HEALTH)" <ro...@nhs.net>.
Can anyone tell me how to leave this email list? I have tried sending an email to the unsubscribe address, but that has not worked.

********************************************************************************************************************

This message may contain confidential information. If you are not the intended recipient please inform the
sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take any action in reliance on its contents:
to do so is strictly prohibited and may be unlawful.

Thank you for your co-operation.

NHSmail is the secure email and directory service available for all NHS staff in England and Scotland
NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and GSi recipients
NHSmail provides an email address for your career in the NHS and can be accessed anywhere
For more information and to find out how you can switch, visit www.connectingforhealth.nhs.uk/nhsmail

********************************************************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writing a custom resource factory

Posted by Felix Schumacher <fe...@internetallee.de>.
Am 15.03.2012 21:54, schrieb Michael-O:
> Hi folks,
>
> I'd like to write a custom ldap resource factory as same as a data
> source factory. The getObjectInstance method shall return
> InitialDirContext object. I have written a mock factory and noticed
> that the output is cached by Tomcat. So the object is created only
> once (same id in Eclipse debugger).
I think you can change that behavior, but it will not be necessary in 
your case.
>
> Now I need to verify that the InitialDirContext is still valid (conn
> timeout, etc.), same as testOnBorrow with DataSource. I won't have 
> any
> reference to it after its creation. This means that I would need to
> wrap that object somehow and perform the operation myself?
> This is how Tomcat JDBC Pool does.
>
> Is my assumption correct? If yes, I would need to wrap every sing
> method defined in DirContext and InitialDirContext.
If you look at the example, you gave. You will see, that the resource 
created
a factory for you. That factory manages a pool and creates and 
validates
connection objects for you.

So, by using 
http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#Generic_JavaBean_Resources
you can easily define a resource, which creates a 
DirContext-factory/pool object.

That factory can be the same for the whole application, if you make it 
thread safe.

The factory-method can than manage the pool and validate each 
DirContext object, before it
hands it out to you. Just remember to give it back to the pool/factory.

Regards
  Felix
>
> Thanks,
>
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org