[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[smila-user] Call an OSGI bundle service from a pipelet

Hi,

I'm trying to call a dummy service from a pipelet (TranslatorPipelet). Such service is implemented in an OSGi bundle (TranslatorService). The service interface is ITranslatorService.

interface ITranslatorService

package org.eclipse.smila.integration. pipelet.interfaces;

public interface ITranslatorService {
    public String getTranslation(String sentence);
}


bundle TranslatorService

package it.polimi.osgi. traslatorservice.internal;

import org.eclipse.smila.integration.pipelet.interfaces.ITranslatorService;

public class TranslatorService implements ITranslatorService {

    @Override
    public String getTranslation(String sentence) {
        return "No translation available";
    }

}


MANIFEST.MF (bundle TranslatorService)

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Traslatorservice
Bundle-SymbolicName: it.polimi.osgi.
traslatorservice
Bundle-Version: 1.0.0
Bundle-Activator: it.polimi.osgi.traslatorservice.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.eclipse.smila.integration.pipelet.interfaces,
 org.osgi.framework;version="1.3.0"
Export-Package: it.polimi.osgi.traslatorservice
Service-Component: OSGI-INF/TranslatorService.xml

TranslatorService.xml

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="it.polimi.osgi.traslatorservice">
   <implementation class="it.polimi.osgi.traslatorservice.internal.TranslatorService"/>
   <service>
      <provide interface="org.eclipse.smila.integration.pipelet.interfaces.ITranslatorService"/>
   </service>
</scr:component>

Pipelet

package org.eclipse.smila.integration.pipelet;

...

public class TranslatorPipelet implements Pipelet {

      ....
     
      private ITranslatorService _driver;

      /** {@inheritDoc}
     * @throws ProcessingException */
      @Override
      public String[] process(final Blackboard blackboard, final String[] recordIds) throws ProcessingException{
        final ParameterAccessor paramAccessor = new ParameterAccessor(blackboard, _config);
        final ResultCollector resultCollector = new ResultCollector(paramAccessor, _log, ProcessingConstants.DROP_ON_ERROR_DEFAULT);
        for (final String id : recordIds) {
          try {
            paramAccessor.setCurrentRecord(id);
            String inValue = "";
            String outValue = "";
            // get parameter either from record or configuration via parameter accessor.
            final String sourceAttr = paramAccessor.getRequiredParameter(SOURCE_ATT);
            final String targetAttr = paramAccessor.getRequiredParameter(TARGET_ATT);

            if (blackboard.getMetadata(id).containsKey(sourceAttr)) {
              inValue = blackboard.getMetadata(id).getStringValue(sourceAttr);
            }

            outValue = this.getTranslation(inValue);

            ....
          } catch (final Exception e) {
            resultCollector.addFailedResult(id, e);
          }
        }
        return resultCollector.getResultIds();
      }

      /** {@inheritDoc} */
      @Override
      public void configure(final AnyMap config) {
        _config = config;
      }
     
      public String getTranslation(String sentence){
          return _driver.getTranslation(sentence);
      }
     
      public void setTranslatorService(ITranslatorService driver){
          _driver=driver;
      }
}

MANIFEST.MF (Pipelet)

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Example bundle for pipelet development
Bundle-SymbolicName: org.eclipse.smila.integration.pipelet
Bundle-Version: 0.9.0
Bundle-Vendor: Eclipse RT SMILA project
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.apache.commons.logging;version="1.1.1",
 org.eclipse.smila.blackboard;version="0.8.0",
 org.eclipse.smila.datamodel;version="0.8.0",
 org.eclipse.smila.processing;version="0.8.0",
 org.eclipse.smila.processing.parameters;version="0.9.0",
 org.eclipse.smila.processing.util;version="0.9.0",
 org.eclipse.smila.utils;version="0.9.0",
 org.osgi.framework
Export-Package: org.eclipse.smila.integration.pipelet;version="0.9.0",
 org.eclipse.smila.integration.pipelet.interfaces
SMILA-Pipelets: org.eclipse.smila.integration.pipelet.TranslatorPipelet
Service-Component: OSGI-INF/TranslatorPipelet.xml
Bundle-Activator: org.eclipse.smila.integration.pipelet.Activator

TranslatorPipelet.xml

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.smila.integration.pipelet" immediate="true">
   <implementation class="org.eclipse.smila.integration.pipelet.TranslatorPipelet"/>
   <reference bind="setTranslatorService" cardinality="1..1" interface="org.eclipse.smila.integration.pipelet.interfaces.ITranslatorService" name="ITranslatorService" policy="static"/>
</scr:component>

SMILA launch

osgi> Persistence bundle starting...
Persistence bundle started.
ProviderTracker: New service detected...
ProviderTracker: Added service org.eclipse.persistence.jpa.osgi.PersistenceProviderOSGi
TranslatorService started!
....
....
....
[INFO ] HTTP server started successfully on port 8080.

When running SMILA from Eclipse what I obtain as soon as the pipelt call the bundle method getTranslation() is this exception:

2011-11-16 08:56:21,035 WARN  [ODEServerImpl-1 ]  pipelet.TranslatorPipelet                     - Error while processing record with id 'web:<Url="" href="http://wiki.eclipse.org/SMILA">http://wiki.eclipse.org/SMILA>'.
java.lang.NullPointerException
    at org.eclipse.smila.integration.pipelet.TranslatorPipelet.process(TranslatorPipelet.java:64)
    at org.eclipse.smila.processing.bpel.PipeletManager.doInvoke(PipeletManager.java:294)
    at org.eclipse.smila.processing.bpel.PipeletManager.invokePipelet(PipeletManager.java:252)
    at org.eclipse.smila.processing.bpel.PipeletManager.invokeActivity(PipeletManager.java:190)
    at org.eclipse.smila.processing.bpel.SMILAExtensionBundle$InvokePipeletActivity.run(SMILAExtensionBundle.java:67)
    at org.eclipse.smila.processing.bpel.SMILAExtensionBundle$InvokePipeletActivity.run(SMILAExtensionBundle.java:79)
    at org.apache.ode.bpel.rtrep.v2.EXTENSIONACTIVITY.run(EXTENSIONACTIVITY.java:62)
    at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.ode.jacob.vpu.JacobVPU$JacobThreadImpl.run(JacobVPU.java:451)
    at org.apache.ode.jacob.vpu.JacobVPU.execute(JacobVPU.java:139)
    at org.apache.ode.bpel.rtrep.v2.RuntimeInstanceImpl.execute(RuntimeInstanceImpl.java:639)
    at org.apache.ode.bpel.engine.BpelRuntimeContextImpl.execute(BpelRuntimeContextImpl.java:593)
    at org.apache.ode.bpel.engine.BpelRuntimeContextImpl.executeCreateInstance(BpelRuntimeContextImpl.java:581)
    at org.apache.ode.bpel.engine.ODEProcess.executeCreateInstance(ODEProcess.java:373)
    at org.apache.ode.bpel.engine.ODEProcess$2.call(ODEProcess.java:295)
    at org.apache.ode.bpel.engine.ODEProcess$2.call(ODEProcess.java:294)
    at org.apache.ode.bpel.engine.ODEProcess$ProcessCallable.call(ODEProcess.java:1206)
    at org.apache.ode.bpel.engine.BpelInstanceWorker.doInstanceWork(BpelInstanceWorker.java:174)
    at org.apache.ode.bpel.engine.BpelInstanceWorker.execInCurrentThread(BpelInstanceWorker.java:108)
    at org.apache.ode.bpel.engine.ODEProcess.doInstanceWork(ODEProcess.java:487)
    at org.apache.ode.bpel.engine.ODEProcess.invokeProcess(ODEProcess.java:293)
    at org.apache.ode.bpel.engine.MyRoleMessageExchangeImpl.doInvoke(MyRoleMessageExchangeImpl.java:122)
    at org.apache.ode.bpel.engine.UnreliableMyRoleMessageExchangeImpl$1.call(UnreliableMyRoleMessageExchangeImpl.java:44)
    at org.apache.ode.bpel.engine.UnreliableMyRoleMessageExchangeImpl$1.call(UnreliableMyRoleMessageExchangeImpl.java:43)
    at org.apache.ode.bpel.engine.ODEProcess$ProcessCallable.call(ODEProcess.java:1206)
    at org.apache.ode.bpel.engine.Contexts.execTransaction(Contexts.java:106)
    at org.apache.ode.bpel.engine.BpelServerImpl$TransactedCallable.call(BpelServerImpl.java:968)
    at org.apache.ode.bpel.engine.BpelServerImpl$ServerCallable.call(BpelServerImpl.java:948)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)


Any idea?

Thank you,

Nicolò Aquilini