<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [resolved] How to retrieve datasource with it's JNDI name in Talend Route? in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195467#M66</link>
    <description>Resolved with walk around approach&amp;nbsp;&lt;A href="https://www.talendforge.org/forum/viewtopic.php?pid=178256#p178256" target="_blank" rel="nofollow noopener noreferrer"&gt;https://www.talendforge.org/forum/viewtopic.php?pid=178256#p178256&lt;/A&gt;</description>
    <pubDate>Sat, 20 Feb 2016 05:25:15 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-02-20T05:25:15Z</dc:date>
    <item>
      <title>[resolved] How to retrieve datasource with it's JNDI name in Talend Route?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195463#M62</link>
      <description>Hi Team,
&lt;BR /&gt;I am trying to retrieve all available data sources and their JNDI names in Talend Runtime. However, I only can get either all data sources or all JNDIs, but cannot map JNDIs to relavent data source instances.&amp;nbsp;
&lt;BR /&gt;For example, I managed to get all JNDIs and then try to get data sources with below code:
&lt;BR /&gt;
&lt;PRE&gt;Registry reg = camelContext.getRegistry();&lt;BR /&gt;Set&amp;lt;org.apache.karaf.jndi.JndiService&amp;gt; s = reg.findByType(org.apache.karaf.jndi.JndiService.class);&lt;BR /&gt;if(s == null)&lt;BR /&gt;	System.out.println("JndiService is null");&lt;BR /&gt;else{&lt;BR /&gt;	for(org.apache.karaf.jndi.JndiService js : s)&lt;BR /&gt;	{&lt;BR /&gt;		try{&lt;BR /&gt;			Map&amp;lt;String, String&amp;gt; jndis = js.names();&lt;BR /&gt;			for(Map.Entry&amp;lt;String, String&amp;gt; row_jndi : jndis.entrySet() )&lt;BR /&gt;			{&lt;BR /&gt;				String key = row_jndi.getKey();&lt;BR /&gt;				String value = row_jndi.getValue();&lt;BR /&gt;				System.out.println("Key = " + key + "; Value = " + value);&lt;BR /&gt;				Object obj =  reg.lookupByName(key);&lt;BR /&gt;				if(obj != null)&lt;BR /&gt;					System.out.println("Obj is " + obj.toString());&lt;BR /&gt;				else&lt;BR /&gt;					System.out.println("Obj is null" ); &lt;BR /&gt;			}&lt;BR /&gt;			&lt;BR /&gt;		}catch(Exception e)&lt;BR /&gt;		{&lt;BR /&gt;                   ....................&lt;BR /&gt;		}&lt;BR /&gt;	}&lt;BR /&gt;}	&lt;/PRE&gt;
&lt;BR /&gt;However, the&amp;nbsp;
&lt;FONT face="consolas, monaco, 'bitstream vera sans mono', 'courier new', courier, monospace"&gt;reg.lookupByName(key)&lt;/FONT&gt;&amp;nbsp;failed to get objects and log shows:
&lt;BR /&gt;
&lt;PRE&gt;Key = osgi:service/WeChatDS; Value = org.apache.commons.dbcp2.managed.ManagedDataSource&lt;BR /&gt;Obj is null&lt;BR /&gt;Key = osgi:service/jndi; Value = org.apache.karaf.jndi.internal.JndiServiceImpl&lt;BR /&gt;Obj is null&lt;BR /&gt;Key = osgi:service/MobileCRMDS; Value = org.apache.commons.dbcp2.managed.ManagedDataSource&lt;BR /&gt;Obj is null&lt;BR /&gt;Key = osgi:service/jdbc/WeChat2; Value = org.postgresql.ds.PGPoolingDataSource&lt;BR /&gt;Obj is null&lt;BR /&gt;&lt;/PRE&gt;
&lt;BR /&gt;When I try to use code of: "Set&amp;lt;javax.sql.DataSource&amp;gt; o = reg.findByType(javax.sql.DataSource.class);", it only gives me instances of data sources, but I cannot use data source instance to fetch JNDI name.
&lt;BR /&gt;Anyone could advice me how to get JNDI and relevant data source instance? BTW, I am working on TOS 6.0</description>
      <pubDate>Sat, 16 Nov 2024 10:47:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195463#M62</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T10:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] How to retrieve datasource with it's JNDI name in Talend Route?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195464#M63</link>
      <description>You could try to use plain jndi like:&lt;BR /&gt;Context context = new InitialContext();&lt;BR /&gt;and then use the context to look up and retrieve the DataSources.&lt;BR /&gt;Another option is to get hold of the OSGi BundleContext and lookup the DataSources as OSGi services.</description>
      <pubDate>Fri, 19 Feb 2016 12:55:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195464#M63</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-19T12:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] How to retrieve datasource with it's JNDI name in Talend Route?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195465#M64</link>
      <description>Hi Schneider, 
&lt;BR /&gt;Thank you for your reply. However, it throws exceptions as such: 
&lt;BR /&gt; 
&lt;PRE&gt;javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial&lt;BR /&gt;        at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)&lt;BR /&gt;        at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)&lt;BR /&gt;        at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)&lt;BR /&gt;        at javax.naming.InitialContext.lookup(Unknown Source)&lt;BR /&gt;        at test_datasource.mysqljob_0_1.mysqljob.tJava_1Process(mysqljob.java:737)&lt;BR /&gt;        at test_datasource.mysqljob_0_1.mysqljob.tPostgresqlConnection_1Process(mysqljob.java:663)&lt;BR /&gt;        at test_datasource.mysqljob_0_1.mysqljob.tPrejob_1Process(mysqljob.java:528)&lt;BR /&gt;        at test_datasource.mysqljob_0_1.mysqljob.runJobInTOS(mysqljob.java:2152)&lt;BR /&gt;        at org.talend.camel.TalendProducer.invokeTalendJob(TalendProducer.java:109)&lt;BR /&gt;        at org.talend.camel.TalendProducer.process(TalendProducer.java:65)&lt;BR /&gt;        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)&lt;BR /&gt;        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:129)&lt;BR /&gt;        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)&lt;BR /&gt;        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)&lt;BR /&gt;        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)&lt;BR /&gt;        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)&lt;BR /&gt;        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)&lt;BR /&gt;        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)&lt;BR /&gt;        at org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:162)&lt;BR /&gt;        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)&lt;BR /&gt;        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)&lt;BR /&gt;        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)&lt;BR /&gt;        at org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:146)&lt;BR /&gt;        at org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43)&lt;BR /&gt;        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)&lt;BR /&gt;        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)&lt;BR /&gt;        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)&lt;BR /&gt;        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)&lt;BR /&gt;        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)&lt;BR /&gt;        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)&lt;BR /&gt;        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)&lt;BR /&gt;        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)&lt;BR /&gt;        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)&lt;BR /&gt;        at org.eclipse.jetty.server.Server.handle(Server.java:497)&lt;BR /&gt;        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)&lt;BR /&gt;        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)&lt;BR /&gt;        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)&lt;BR /&gt;        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)&lt;BR /&gt;        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)&lt;BR /&gt;        at java.lang.Thread.run(Unknown Source)&lt;/PRE&gt; 
&lt;BR /&gt;The codes are: 
&lt;BR /&gt; 
&lt;PRE&gt;javax.naming.Context ctx = new javax.naming.InitialContext();&lt;BR /&gt;Object o = ctx.lookup("somename");&lt;/PRE&gt; 
&lt;BR /&gt;Am I using a wrong Context class? Context is unknown class in Talend....</description>
      <pubDate>Fri, 19 Feb 2016 14:32:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195465#M64</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-19T14:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] How to retrieve datasource with it's JNDI name in Talend Route?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195466#M65</link>
      <description>Finally, I managed to achieve my requirements using bundleContext...here are my codes in cConfig in Talend Route:
&lt;BR /&gt;
&lt;PRE&gt;import org.osgi.framework.Bundle;&lt;BR /&gt;import org.osgi.framework.Constants;&lt;BR /&gt;import org.osgi.framework.ServiceReference;&lt;BR /&gt;&lt;BR /&gt;Bundle[] bundles = bundleContext.getBundles();&lt;BR /&gt;for (Bundle bundle : bundles) {&lt;BR /&gt;	&lt;BR /&gt;	ServiceReference[] services = bundle.getRegisteredServices();&lt;BR /&gt;	if (services != null) {&lt;BR /&gt;		for (ServiceReference serviceReference : services) {&lt;BR /&gt;			String[] objectClasses = (String[])serviceReference.getProperty(Constants.OBJECTCLASS);&lt;BR /&gt;			boolean t = false;&lt;BR /&gt;			for(String s : objectClasses){&lt;BR /&gt;				if(s.equals("javax.sql.DataSource"))&lt;BR /&gt;				{&lt;BR /&gt;					t = true;&lt;BR /&gt;					break;&lt;BR /&gt;				}&lt;BR /&gt;			}&lt;BR /&gt;			if(t){&lt;BR /&gt;				Object actualService = bundleContext.getService(serviceReference);&lt;BR /&gt;				System.out.println("actualService is " + actualService);&lt;BR /&gt;				String jndiProperty = (String)serviceReference.getProperty("osgi.jndi.service.name");&lt;BR /&gt;				System.out.println("actualService JNDI is " + jndiProperty);				&lt;BR /&gt;			}&lt;BR /&gt;			&lt;BR /&gt;		}&lt;BR /&gt;	}&lt;BR /&gt;}&lt;BR /&gt;&lt;/PRE&gt;
&lt;BR /&gt;So&amp;nbsp;actualService here refers to real data source and&amp;nbsp;jndiProperty is its JNDI name.</description>
      <pubDate>Fri, 19 Feb 2016 15:59:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195466#M65</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-19T15:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] How to retrieve datasource with it's JNDI name in Talend Route?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195467#M66</link>
      <description>Resolved with walk around approach&amp;nbsp;&lt;A href="https://www.talendforge.org/forum/viewtopic.php?pid=178256#p178256" target="_blank" rel="nofollow noopener noreferrer"&gt;https://www.talendforge.org/forum/viewtopic.php?pid=178256#p178256&lt;/A&gt;</description>
      <pubDate>Sat, 20 Feb 2016 05:25:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-How-to-retrieve-datasource-with-it-s-JNDI-name-in/m-p/2195467#M66</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-20T05:25:15Z</dc:date>
    </item>
  </channel>
</rss>

