Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SMILA/Documentation/HowTo/How to integrate the HelloWorld webservice as a Pipelet"

Line 38: Line 38:
  
 
* create a package <tt>org.eclipse.smila.sample.pipelet</tt> and a Java class <tt>HelloWorldPipelet</tt>
 
* create a package <tt>org.eclipse.smila.sample.pipelet</tt> and a Java class <tt>HelloWorldPipelet</tt>
* use the following code as a template for your new class. It contains empty method bodies and a reference to the logger (for your convenience you may also download the complete zipped source file [[Media:HelloWorldPipelet.zip|HelloWorldPipelet.zip]])
+
* use the following code as a template for your new class. It contains empty method bodies and a reference to the logger. The comments are successively replaced with code snippets in the following sections. For your convenience you may also download the complete zipped source file [[Media:HelloWorldPipelet.zip|HelloWorldPipelet.zip]].
 
<source lang="Java">
 
<source lang="Java">
 
package org.eclipse.smila.sample.pipelet
 
package org.eclipse.smila.sample.pipelet

Revision as of 12:11, 26 September 2008

This tutorial illustrates all steps that need to be performed in order to integrate the HelloWorld webservice as a Pipelet in SMILA

Preparations

It may be helpful to first take a look at the SMILA Development_Guidelines as many topics that are beyond the scope of this tutorial are illustrated there in detail.

Create a new Bundle

  • First you have to create a new bundle that will contain the Pipelet. Please follow the instructions on How to create a bundle and use the following settings:
Project name: org.eclipse.smila.sample.pipelet
Plug-in ID: org.eclipse.smila.sample.pipelet
Plug-in Version: 1.0.0
Plug-in Name: Sample Pipelet Bundle
Plug-in Provider: your name or company
  • Then you have to integrate your new bundle into the SMILA build process. Therefore please follow the instructions on How to integrate a new bundle into build process.
  • Edit file META-INF/MANIFEST.MF and add the following import-package dependencies as those are required to implement the basic functionalities of your Pipelet:
Import-Package: org.apache.commons.logging;version="1.1.1",
org.eclipse.smila.blackboard.BlackboardService;version="0.5.0",
org.eclipse.smila.datamodel.id.Id;version="0.5.0",
org.eclipse.smila.processing.ProcessingException;version="0.5.0",
org.eclipse.smila.processing.SimplePipelet;version="0.5.0",
org.eclipse.smila.processing.configuration.PipeletConfiguration;version="0.5.0"
  • In order for the PipeletTrackerService to detect your new Pipelet you have to add the following line to file META-INF/MANIFEST.MF to register the class that will implement your SMILA Pipelet:
SMILA-Pipelets: org.eclipse.smila.sample.pipelet.HelloWorldPipelet

Create Java classes from WSDL

comming soon ...


Implementation

  • create a package org.eclipse.smila.sample.pipelet and a Java class HelloWorldPipelet
  • use the following code as a template for your new class. It contains empty method bodies and a reference to the logger. The comments are successively replaced with code snippets in the following sections. For your convenience you may also download the complete zipped source file HelloWorldPipelet.zip.
package org.eclipse.smila.sample.pipelet
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.eilf.blackboard.BlackboardService;
import org.eclipse.eilf.blackboard.path.Path;
import org.eclipse.eilf.datamodel.id.Id;
import org.eclipse.eilf.datamodel.record.Literal;
import org.eclipse.eilf.datamodel.record.RecordFactory;
import org.eclipse.eilf.processing.ProcessingException;
import org.eclipse.eilf.processing.SimplePipelet;
import org.eclipse.eilf.processing.configuration.PipeletConfiguration;
 
public class HelloWorldPipelet implements SimplePipelet {
 
  // additional member variables 
  private final Log _log = LogFactory.getLog(HelloWorldPipelet.class);
 
  public HelloWorldPipelet(){
  }
 
  public void configure(PipeletConfiguration configuration) throws ProcessingException {
    // read the configuration properties
  }
 
  public Id[] process(BlackboardService blackboard, Id[] recordIds) throws ProcessingException {
    // process the recordIds and create a result
  }
}


Read PipeletConfiguration

  • first let's create two member variables that store the names of the in- and output Attributes as well as String constants for the property names used in the configuration. Replace the comment "// additional member variables " with the following code snippet.
private final String PROP_IN_ATT_NAME= "IN_ATT_NAME";
private final String PROP_OUT_ATT_NAME= "OUT_ATT_NAME";
 
private String _inAttName;
private String _outAttName;
  • then we will fill those members with the Attribute names provided by the PipeletConfiguration in method configure(PipeletConfiguration configuration). The method getPropertyFirstValueNotNull(String) will check that the value of the property is not null. If it is null a ProcessingException will be thrown. In addition we should ensure, that the provided String is not empty or consists only of whitespaces. Replace the comment "// read the configuration properties" with the following code snippet.
_inAttName = (String) configuration.getPropertyFirstValueNotNull(PROP_IN_ATT_NAME);
if (_inAttName.trim().length() == 0) {
    throw new ProcessingException("Property " + PROP_IN_ATT_NAME + " must not be an empty String");
}
 
_outAttName = (String) configuration.getPropertyFirstValueNotNull(PROP_OUT_ATT_NAME);
if (_outAttName.trim().length() == 0) {
    throw new ProcessingException("Property " + PROP_OUT_ATT_NAME + " must not be an empty String");
}

Note: Of course it is also possible to store the PipeletConfiguration in a member variable and access the properties as needed in the process(BlackboardService blackboard, Id[] recordIds) method.

Processing of IDs and exception handling

The method process(BlackboardService blackboard, Id[] recordIds) has two parameters:

  • a reference to the BlackboardService that allows access on Records
  • a list of Record IDs to process

The HelloWorldPipelet should therefor iterate over the IDs in parameter recordIds, get the required data from the Record identified by the ID, process this data and store the Result in the Record. Let's place a try ... catch() block in the for loop to ensure that errors do only interrupt the processing of the current ID. The comments in the code serve as placeholders for the functionality described in the following sections. At the end we return the unmodified input parameter recordIds as the result of the Pipelet. Replace the comment "// process the recordIds and create a result" with the following code snippet.

for (Id id : recordIds) {
    try {
        // Read Input Data
 
        // Process Input Data
 
        // Write Output Data
 
    } catch (final Exception ex) {
        if (_log.isErrorEnabled()) {
            _log.error("error during execution of HelloWorldPipelet with record " + id, ex);
        }
    }
} // for
 
return recordIds;

Note: Most of the time the return value of a Pipelet is the unmodified input parameter recordIds. However, in some cases a Pipelet may filter Record IDs or even create new Records. Then the return value has to be adopted appropriately.


Read Input Data

Now we want to read the data of the Attribute with the name stored in _inAttName. Therefore we first have to create a Path object with the Attribute's name. Before accessing the literal value we check if the Record contains a Attribute with the given Path. In this Tutorial we know that the value of the Attribute is a String value, so we directly access the value by calling the methodgetStringValue(). Replace the comment "// Read Input Data" with the following code snippet.

String inputValue = "";
final Path path = new Path(_inAttName);
if (blackboard.hasAttribute(id, path)) {
  inputValue = blackboard.getLiteral(id, path).getStringValue();
}

Note: The accessing of Attribute values can be done more generic. Therefore you have to check what DataType a certain Literal contains using method getDataType(). Then you can use the appropriate getter method to access thee raw data.

Process Input Data

At this point the HelloWorld webservice should be called with parameter inputValue and storing the result in variable outputValue, using the classes generated from WSDL.
Until this tutorial description is complete simply assign the content of variable inputValue to variable outputValue and append a constant string value. Replace the comment "// Process Input Data" with the following code snippet.

    String outputValue = inputValue + " modified by HelloWorldPipelet";

Write Output Data

Finally we want to store the content of variable outputValue in the Record Attribute with the name contained in variable _outAttName. Therefore we have to create a new Literal object and set it's value. Then we only need to set this Literal for the current ID on the Blackboard. Replace the comment "// Write Output Data" with the following code snippet.

final Literal literal = RecordFactory.DEFAULT_INSTANCE.createLiteral();
literal.setStringValue(outputValue);
blackboard.setLiteral(id, new Path(_outAttName), literal);

Note: The method commit(Id) of the BlackboardService does not need to be called in every Pipelet. It is automatically called at the end of the Pipeline.


Configuration and Invocation in BPEL

In this tutorial we will integrate the HelloWorldPipelet in the SMILA indexing process just before the Record is stored in the Lucene index. With this configuration the input for the HelloWorldPipelet will be read from Attribute Title and the modified output will be stored in the same Attribute, overwriting the previous value.

  • edit file configuration\org.eclipse.eilf.processing.bpel\pipelines\addpipeline.bpel and add the following right between <extensionActivity name="convertDocument"> and <extensionActivity name="invokeLuceneService">
<extensionActivity name="invokeHelloWorldPipelet">
    <proc:invokePipelet>
        <proc:pipelet class="org.eclipse.smila.sample.pipelet.HelloWorldPipelet" />
        <proc:variables input="request" output="result" />
        <proc:PipeletConfiguration>
            <proc:Property name="IN_ATT_NAME">
                <proc:Value>Title</proc:Value>
            </proc:Property>
            <proc:Property name="OUT_ATT_NAME">
                <proc:Value>Title</proc:Value>
            </proc:Property>
        </proc:PipeletConfiguration>       
    </proc:invokePipelet>
</extensionActivity>


Test your Pipelet

comming soon ...

Back to the top