You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Thusitha Thilina Dayaratne <th...@wso2.com> on 2015/03/09 04:59:20 UTC

How to access JNDI Directory Context in Tomcat 8

Hi,

I want to access the JNDI Directory context in Tomcat8. I've used
*DirContextURLStreamHandler* class which was in Tomcat 7. But now that has
been removed.
Can someone tell me how can I access the JNDI Directory Context in Tomcat 8?

Thanks
Best Regards
/Thusitha

-- 
Thusitha Dayaratne
Software Engineer
WSO2 Inc. - lean . enterprise . middleware |  wso2.com

Mobile  +94712756809
Blog      alokayasoya.blogspot.com
About    http://about.me/thusithathilina

Re: How to access JNDI Directory Context in Tomcat 8

Posted by Thusitha Thilina Dayaratne <th...@wso2.com>.
Hi

2015-04-06 14:33 GMT+03:00 Thusitha Thilina Dayaratne <th...@wso2.com>:
>
> Hi
>
> Is there a Tomcat provided URLStreamHandlerFactory for JNDI in tomcat
> 8.0.20?
> I tried
>
TomcatURLStreamHandlerFactory.getInstance().createURLStreamHandler("jndi");

>>"jndi" schema is removed in Tomcat 8. You may want to check this
discussion
>>[1].
Thanks for the quick response.
So is this implies that there is no way  to get a URLStreamHaandler for
JNDI in Tomcat 8?
If so what should be my approach?

Thanks
Best Regards

On Mon, Apr 6, 2015 at 6:01 PM, Violeta Georgieva <mi...@gmail.com>
wrote:

> Hi,
>
> 2015-04-06 14:33 GMT+03:00 Thusitha Thilina Dayaratne <thusithad@wso2.com
> >:
> >
> > Hi
> >
> > Is there a Tomcat provided URLStreamHandlerFactory for JNDI in tomcat
> > 8.0.20?
> > I tried
> >
> TomcatURLStreamHandlerFactory.getInstance().createURLStreamHandler("jndi");
>
> "jndi" schema is removed in Tomcat 8. You may want to check this discussion
> [1].
>
> Regards,
> Violeta
>
> [1] http://marc.info/?t=137908844800007&r=1&w=2
>
> > But that returns null.
> >
> > Thanks
> > Best Regards
> > /Thusitha
> >
> > On Wed, Mar 25, 2015 at 2:48 PM, Thusitha Thilina Dayaratne <
> > thusithad@wso2.com> wrote:
> >
> > > Hi Mark,
> > >
> > > > Thanks all for responses. But what I actually want is to register a
> > > > URLStreamHandlerService for JNDI
> > >
> > > >>Finally. More than 2 weeks since the first e-mail in this thread the
> > > >>list members know what it is you are actually trying to do.
> > >
> > > >>You want:
> > > >>
> > >
>
> http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html
> > > Thanks a lot for the quick response and I'm really sorry for the delay
> and
> > > any inconvenience caused due to that
> > >
> > > Best Regards
> > > /Thusitha
> > >
> > > On Wed, Mar 25, 2015 at 2:28 PM, Mark Thomas <ma...@apache.org> wrote:
> > >
> > >> On 25/03/2015 08:14, Thusitha Thilina Dayaratne wrote:
> > >> <snip/>
> > >>
> > >> > Thanks all for responses. But what I actually want is to register a
> > >> > URLStreamHandlerService for JNDI
> > >>
> > >> Finally. More than 2 weeks since the first e-mail in this thread the
> > >> list members know what it is you are actually trying to do.
> > >>
> > >> You want:
> > >>
> > >>
>
> http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html
> > >>
> > >> Mark
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > >> For additional commands, e-mail: users-help@tomcat.apache.org
> > >>
> > >>
> > >
> > >
> > > --
> > > Thusitha Dayaratne
> > > Software Engineer
> > > WSO2 Inc. - lean . enterprise . middleware |  wso2.com
> > >
> > > Mobile  +94712756809
> > > Blog      alokayasoya.blogspot.com
> > > About    http://about.me/thusithathilina
> > >
> > >
> >
> >
> > --
> > Thusitha Dayaratne
> > Software Engineer
> > WSO2 Inc. - lean . enterprise . middleware |  wso2.com
> >
> > Mobile  +94712756809
> > Blog      alokayasoya.blogspot.com
> > About    http://about.me/thusithathilina
>



-- 
Thusitha Dayaratne
Software Engineer
WSO2 Inc. - lean . enterprise . middleware |  wso2.com

Mobile  +94712756809
Blog      alokayasoya.blogspot.com
About    http://about.me/thusithathilina

Re: How to access JNDI Directory Context in Tomcat 8

Posted by Violeta Georgieva <mi...@gmail.com>.
Hi,

2015-04-06 14:33 GMT+03:00 Thusitha Thilina Dayaratne <th...@wso2.com>:
>
> Hi
>
> Is there a Tomcat provided URLStreamHandlerFactory for JNDI in tomcat
> 8.0.20?
> I tried
>
TomcatURLStreamHandlerFactory.getInstance().createURLStreamHandler("jndi");

"jndi" schema is removed in Tomcat 8. You may want to check this discussion
[1].

Regards,
Violeta

[1] http://marc.info/?t=137908844800007&r=1&w=2

> But that returns null.
>
> Thanks
> Best Regards
> /Thusitha
>
> On Wed, Mar 25, 2015 at 2:48 PM, Thusitha Thilina Dayaratne <
> thusithad@wso2.com> wrote:
>
> > Hi Mark,
> >
> > > Thanks all for responses. But what I actually want is to register a
> > > URLStreamHandlerService for JNDI
> >
> > >>Finally. More than 2 weeks since the first e-mail in this thread the
> > >>list members know what it is you are actually trying to do.
> >
> > >>You want:
> > >>
> >
http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html
> > Thanks a lot for the quick response and I'm really sorry for the delay
and
> > any inconvenience caused due to that
> >
> > Best Regards
> > /Thusitha
> >
> > On Wed, Mar 25, 2015 at 2:28 PM, Mark Thomas <ma...@apache.org> wrote:
> >
> >> On 25/03/2015 08:14, Thusitha Thilina Dayaratne wrote:
> >> <snip/>
> >>
> >> > Thanks all for responses. But what I actually want is to register a
> >> > URLStreamHandlerService for JNDI
> >>
> >> Finally. More than 2 weeks since the first e-mail in this thread the
> >> list members know what it is you are actually trying to do.
> >>
> >> You want:
> >>
> >>
http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html
> >>
> >> Mark
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
> >
> > --
> > Thusitha Dayaratne
> > Software Engineer
> > WSO2 Inc. - lean . enterprise . middleware |  wso2.com
> >
> > Mobile  +94712756809
> > Blog      alokayasoya.blogspot.com
> > About    http://about.me/thusithathilina
> >
> >
>
>
> --
> Thusitha Dayaratne
> Software Engineer
> WSO2 Inc. - lean . enterprise . middleware |  wso2.com
>
> Mobile  +94712756809
> Blog      alokayasoya.blogspot.com
> About    http://about.me/thusithathilina

Re: How to access JNDI Directory Context in Tomcat 8

Posted by Thusitha Thilina Dayaratne <th...@wso2.com>.
Hi

Is there a Tomcat provided URLStreamHandlerFactory for JNDI in tomcat
8.0.20?
I tried
TomcatURLStreamHandlerFactory.getInstance().createURLStreamHandler("jndi");

But that returns null.

Thanks
Best Regards
/Thusitha

On Wed, Mar 25, 2015 at 2:48 PM, Thusitha Thilina Dayaratne <
thusithad@wso2.com> wrote:

> Hi Mark,
>
> > Thanks all for responses. But what I actually want is to register a
> > URLStreamHandlerService for JNDI
>
> >>Finally. More than 2 weeks since the first e-mail in this thread the
> >>list members know what it is you are actually trying to do.
>
> >>You want:
> >>
> http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html
> Thanks a lot for the quick response and I'm really sorry for the delay and
> any inconvenience caused due to that
>
> Best Regards
> /Thusitha
>
> On Wed, Mar 25, 2015 at 2:28 PM, Mark Thomas <ma...@apache.org> wrote:
>
>> On 25/03/2015 08:14, Thusitha Thilina Dayaratne wrote:
>> <snip/>
>>
>> > Thanks all for responses. But what I actually want is to register a
>> > URLStreamHandlerService for JNDI
>>
>> Finally. More than 2 weeks since the first e-mail in this thread the
>> list members know what it is you are actually trying to do.
>>
>> You want:
>>
>> http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html
>>
>> Mark
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
>
> --
> Thusitha Dayaratne
> Software Engineer
> WSO2 Inc. - lean . enterprise . middleware |  wso2.com
>
> Mobile  +94712756809
> Blog      alokayasoya.blogspot.com
> About    http://about.me/thusithathilina
>
>


-- 
Thusitha Dayaratne
Software Engineer
WSO2 Inc. - lean . enterprise . middleware |  wso2.com

Mobile  +94712756809
Blog      alokayasoya.blogspot.com
About    http://about.me/thusithathilina

Re: How to access JNDI Directory Context in Tomcat 8

Posted by Thusitha Thilina Dayaratne <th...@wso2.com>.
Hi Mark,

> Thanks all for responses. But what I actually want is to register a
> URLStreamHandlerService for JNDI

>>Finally. More than 2 weeks since the first e-mail in this thread the
>>list members know what it is you are actually trying to do.

>>You want:
>>
http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html
Thanks a lot for the quick response and I'm really sorry for the delay and
any inconvenience caused due to that

Best Regards
/Thusitha

On Wed, Mar 25, 2015 at 2:28 PM, Mark Thomas <ma...@apache.org> wrote:

> On 25/03/2015 08:14, Thusitha Thilina Dayaratne wrote:
> <snip/>
>
> > Thanks all for responses. But what I actually want is to register a
> > URLStreamHandlerService for JNDI
>
> Finally. More than 2 weeks since the first e-mail in this thread the
> list members know what it is you are actually trying to do.
>
> You want:
>
> http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Thusitha Dayaratne
Software Engineer
WSO2 Inc. - lean . enterprise . middleware |  wso2.com

Mobile  +94712756809
Blog      alokayasoya.blogspot.com
About    http://about.me/thusithathilina

Re: How to access JNDI Directory Context in Tomcat 8

Posted by Mark Thomas <ma...@apache.org>.
On 25/03/2015 08:14, Thusitha Thilina Dayaratne wrote:
<snip/>

> Thanks all for responses. But what I actually want is to register a
> URLStreamHandlerService for JNDI

Finally. More than 2 weeks since the first e-mail in this thread the
list members know what it is you are actually trying to do.

You want:
http://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.html

Mark


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


Re: How to access JNDI Directory Context in Tomcat 8

Posted by Thusitha Thilina Dayaratne <th...@wso2.com>.
Hi

>> how can that be modified to load the jndi.properties file?
>
> The javadoc for InitialContext seems to indicate that this file will be
> processed automatically.
>
> If it isn't processed automatically, I'd suggest trying to figure out
> why.


>>Good to know, thank you.

>>Amazingly, this is the only Java example code I've ever seen which,
>>potentially, enables remote JNDI lookup for JMSContext.

Thanks all for responses. But what I actually want is to register a
URLStreamHandlerService for JNDI
In tomcat 7
I have used DirContextURLStreamHandler for that as follows

Properties properties = new Properties();
properties.put(URLConstants.URL_HANDLER_PROTOCOL, "jndi");
final URLStreamHandler handler = new DirContextURLStreamHandler();

bundleContext.registerService(URLStreamHandlerService.class.getName(),
	new AbstractURLStreamHandlerService() {
		private final static String EMPTY_STRING = "";
		public URLConnection openConnection(URL u) throws IOException {
			return new URL(u, EMPTY_STRING, handler).openConnection();
		}
	}, properties);


But since with Tomcat 8 DirContextURLStreamHandler have been removed.

So how can I achieve the same thing in Tomcat 8?


Thanks

Best Regards

/Thusitha


On Tue, Mar 10, 2015 at 4:02 AM, Thufir <ha...@gmail.com> wrote:

> On Mon, 09 Mar 2015 14:11:08 -0400, Christopher Schultz wrote:
>
> >> how can that be modified to load the jndi.properties file?
> >
> > The javadoc for InitialContext seems to indicate that this file will be
> > processed automatically.
> >
> > If it isn't processed automatically, I'd suggest trying to figure out
> > why.
>
>
> Good to know, thank you.
>
> Amazingly, this is the only Java example code I've ever seen which,
> potentially, enables remote JNDI lookup for JMSContext.
>
>
>
> -Thufir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Thusitha Dayaratne
Software Engineer
WSO2 Inc. - lean . enterprise . middleware |  wso2.com

Mobile  +94712756809
Blog      alokayasoya.blogspot.com
About    http://about.me/thusithathilina

Re: How to access JNDI Directory Context in Tomcat 8

Posted by Thufir <ha...@gmail.com>.
On Mon, 09 Mar 2015 14:11:08 -0400, Christopher Schultz wrote:

>> how can that be modified to load the jndi.properties file?
> 
> The javadoc for InitialContext seems to indicate that this file will be
> processed automatically.
> 
> If it isn't processed automatically, I'd suggest trying to figure out
> why.


Good to know, thank you.

Amazingly, this is the only Java example code I've ever seen which, 
potentially, enables remote JNDI lookup for JMSContext.



-Thufir


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


Re: How to access JNDI Directory Context in Tomcat 8

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Thufir,

On 3/9/15 12:47 PM, Thufir wrote:
> On Mon, 09 Mar 2015 08:59:33 +0000, Mark Thomas wrote:
> 
>> On 09/03/2015 03:59, Thusitha Thilina Dayaratne wrote:
>>> Hi,
>>> 
>>> I want to access the JNDI Directory context in Tomcat8. I've
>>> used *DirContextURLStreamHandler* class which was in Tomcat 7.
>>> But now that has been removed. Can someone tell me how can I
>>> access the JNDI Directory Context in Tomcat 8?
>> 
>> Via the standard JNDI API.
>> 
>> Mark
> 
> 
> 
> Can you elaborate a little?  For this example:
> 
> 
> public static void main(String[] args) { try { // Gets the JNDI
> context Context jndiContext = new InitialContext(); // Looks up the
> administered objects ConnectionFactory connectionFactory =
> (ConnectionFactory) 
> jndiContext.lookup("jms/javaee7/ConnectionFactory"); Destination
> queue = (Destination) jndiContext.lookup("jms/javaee7/ Queue"); //
> Sends a text message to the queue try (JMSContext context =
> connectionFactory.createContext()) { 
> context.createProducer().send(queue, "Text message sent at " + new
> Date()); } } catch (NamingException e) { e.printStackTrace(); } }
> 
> http://stackoverflow.com/questions/23037845/
> 
> 
> 
> how can that be modified to load the jndi.properties file?

The javadoc for InitialContext seems to indicate that this file will
be processed automatically.

If it isn't processed automatically, I'd suggest trying to figure out why.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJU/eI8AAoJEBzwKT+lPKRY+YgP/2BdznexT1XxxBa751DdQEAc
n3C0MhqpBb5udv+yL3PLasyoPozPEcS+7Ql3nK6PRBseXqbzmzRVuuJdsAIP7EPI
4lhWMnk3BzoVwz2VNaAfNKAp6ZZhKVBHvhKk5iOI62exJFHKhgPgk72HTGB8FuxJ
emRxfWPJ1L1xu+bX0MSPuxmrKXjKlhy2/VZD99LFvazeCzoB+TgmNhYH9MmCXKI1
nXRz9fPc0nKwAXo8EIBaUluTcMte++//MsoJTWqZaFOBDtPTXnE/twRdHDtyY+3R
AlKDBxPVPx1OsouyJs0Ajq89CHdIEVjDS2SIMqt//ZNsyqN7BpUdR3KnojuR5rvk
fzaFia6m13t/oIMvC6T+V6CwNTcp5sSR3yezSAKNjEk2drg5LKczj45uyTiRnfwU
hYMB7vV9iyRqRPhJRtHzHyisOsZrYGi0ZaFsTxuJL3AMuahiax7QC4zLEtB6nN2Z
P/CQne/6KNGV92u8baOd0C7GVojtVVfmGgEqt1iEBF1LQn/LXZlg4eKvoajjtxXs
FF9AdiWeAZNKoXipk86NgDHRehgvhvBW6wea+3uiHpvTHgSCRbkE1CmSqznVOn8c
IS9Q2c0bS3Nq5OHdDmvhoH71Q5xCXOrlGCasI12iyBt/syByZO44tkFSgc3a8uOq
AYwMwB9xPqV731AUsGC3
=nIZi
-----END PGP SIGNATURE-----

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


Re: How to access JNDI Directory Context in Tomcat 8

Posted by Thufir <ha...@gmail.com>.
On Mon, 09 Mar 2015 08:59:33 +0000, Mark Thomas wrote:

> On 09/03/2015 03:59, Thusitha Thilina Dayaratne wrote:
>> Hi,
>> 
>> I want to access the JNDI Directory context in Tomcat8. I've used
>> *DirContextURLStreamHandler* class which was in Tomcat 7. But now that
>> has been removed.
>> Can someone tell me how can I access the JNDI Directory Context in
>> Tomcat 8?
> 
> Via the standard JNDI API.
> 
> Mark



Can you elaborate a little?  For this example:


public static void main(String[] args) {
    try {
        // Gets the JNDI context
        Context jndiContext = new InitialContext();
        // Looks up the administered objects
        ConnectionFactory connectionFactory = (ConnectionFactory)
                jndiContext.lookup("jms/javaee7/ConnectionFactory");
        Destination queue = (Destination) jndiContext.lookup("jms/javaee7/
Queue");
        // Sends a text message to the queue
        try (JMSContext context = connectionFactory.createContext()) {
            context.createProducer().send(queue, "Text message sent at " 
+ new Date());
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
}

http://stackoverflow.com/questions/23037845/



how can that be modified to load the jndi.properties file?


thanks,

Thufir


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


Re: How to access JNDI Directory Context in Tomcat 8

Posted by Thusitha Thilina Dayaratne <th...@wso2.com>.
Hi Mark,

Thanks for the quick response.

Regards
/Thusitha

On Mon, Mar 9, 2015 at 2:29 PM, Mark Thomas <ma...@apache.org> wrote:

> On 09/03/2015 03:59, Thusitha Thilina Dayaratne wrote:
> > Hi,
> >
> > I want to access the JNDI Directory context in Tomcat8. I've used
> > *DirContextURLStreamHandler* class which was in Tomcat 7. But now that
> has
> > been removed.
> > Can someone tell me how can I access the JNDI Directory Context in
> Tomcat 8?
>
> Via the standard JNDI API.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Thusitha Dayaratne
Software Engineer
WSO2 Inc. - lean . enterprise . middleware |  wso2.com

Mobile  +94712756809
Blog      alokayasoya.blogspot.com
About    http://about.me/thusithathilina

Re: How to access JNDI Directory Context in Tomcat 8

Posted by Mark Thomas <ma...@apache.org>.
On 09/03/2015 03:59, Thusitha Thilina Dayaratne wrote:
> Hi,
> 
> I want to access the JNDI Directory context in Tomcat8. I've used
> *DirContextURLStreamHandler* class which was in Tomcat 7. But now that has
> been removed.
> Can someone tell me how can I access the JNDI Directory Context in Tomcat 8?

Via the standard JNDI API.

Mark


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