Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] How to use osgi service from job

Hello,
how can I use an osgi service deployed in TESB from a Talend job?
Thanks, Viktor
Labels (2)
5 Replies
Anonymous
Not applicable
Author

Hi 
You can use tRestClient component to call the rest webservcice you have deployed in Runtime.
Best regards
Shong
Anonymous
Not applicable
Author

Hello Shong,
thank you for your answer. My osgi service is not a webservice. It is java interface and implementation, service published using blueprint.
I want to access this service from talend job, that means I need to somehow access this service (something like BundleContext.getServiceReference), use its api without including the jar in the exported job (require/include in manifest).
Thank you,
Viktor
Anonymous
Not applicable
Author

Hi
Maybe you can hard code on tJava or create a routine to access the service, load external jar using tLibraryLoad if needed.
Best regards
Shong
Anonymous
Not applicable
Author

Use sample routine:
package routines;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
public class OsgiHelper {
private OsgiHelper() {
}
public static <T> T getService(Class<T> clazz, String fullJobName) throws InvalidSyntaxException {
Bundle bundle = FrameworkUtil.getBundle(clazz);
if (bundle != null) {
BundleContext context = bundle.getBundleContext();
ServiceReference[] serviceReferences =
context.getServiceReferences(clazz.getName(), "(&(name=" + fullJobName.substring(fullJobName.lastIndexOf('.') + 1) + ")(type=job))");
if (null != serviceReferences) {
return clazz.cast(context.getService(serviceReferences));
}
}
return null;
}
}

And following call in job
System.out.println(routines.OsgiHelper.getService(TalendJob.class, this.getClass().getName()));
In Studio output is null, at runtime like esb.demoserviceconsumer_0_1.DemoServiceConsumer@79ee5eaf
Anonymous
Not applicable
Author

Hello Alex,
thank you, looks very promising.
Not sure how it will work when I need to load api library for class T (interface of service) instead of requiring it in manifest. Will post update.
Viktor