Hi,
is there a way to access the content of the pipeline using Java code?
I think it should be possible, but I couldn’t find any documentation.
Thanks in advance for any answer,
Holger.
Hi,
is there a way to access the content of the pipeline using Java code?
I think it should be possible, but I couldn’t find any documentation.
Thanks in advance for any answer,
Holger.
There certainly is a way to do it. The developer guide is pretty good about explaining it, but here’s the simple upfront explanation.
IDataHashCursor idhc = pipeline.getHashCursor();
idhc.first( “fileContents” );
String fileContents = (String) idhc.getValue();
idhc.first( “fileName” );
String fileName = (String) idhc.getValue();
idhc.destroy();
Now you have two inputs. To create an output, it would appear as follows:
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, “value”, value);
pipelineCursor_1.destroy();
“value” is the pipeline output variable name.
value without the quotes is the literal value from the java code:
value = String “hello”;
Hope this helps. The guide is pretty good about this and the code can be generated automatically in the Developer.
Review the Integrator Guide, Building Coded Services. It describes how to write Java services and how to interact with the pipeline. You can also review the Creating Client Code if your Java code is not in the Integration Server environment.
Here is a java service contents which shows the contentes of the pipeline. It prints out key and its value.
public static final void showPipelineContents( IData pipeline ) throws ServiceException
{
System.out.println(“**>Pipeline Contents:”);
IDataCursor pipelineCursor = pipeline.getCursor();
int i=0;
while(pipelineCursor.next())
{
i++;
System.out.println(i+“: Key :”+pipelineCursor.getKey());
System.out.println(i+“: Value:”+pipelineCursor.getValue());
}
pipelineCursor.destroy();
return;
}
Hope this is what you were looking for.
Cheers
As usual Ray is correct, but I have a little nit about the code sample:
IDataHashCursor idhc = pipeline.getHashCursor();
String fileContents;
if (idhc.first( “fileContents” ))
fileContents = (String) idhc.getValue();
Fred,
I wouldn’t say that I am right as usual. I’ve been known to be wrong on rare occasion. There are several ways that I have seen to access the pipeline and they all seem to work. The reason I decided to post is that I remember the first time I tried to write my first java service. It was hard and I had no clue. So I try to help.
Here’s the many ways to do this:
Assume input is “filename”
#1-----
IDataCursor pipelineCursor = pipeline.getCursor();
String filename = IDataUtil.getString( pipelineCursor, “filename” );
pipelineCursor.destroy();
#2----- (we used this to close an open file handle)
IDataHashCursor.pipelineCursor = pipeline.getHashCursor();
pipeline.Cursor.first( “filename” );
BufferedReader in = (BufferedReader) pipeline.getValue();
— do some code -----
pipelineCursor.destoy();
#3-----
IdataHashCursor pipelineCursor = pipeline getHashCursor();
pipelineCursor.first( “filename” );
String filename = (String) pipelineCursor.getValue();
pipelineCursor.destroy();
#4----
IDataCursor pipelineCursor = pipeline.getCursor();
String rawFileName = IDataUtil.getString( pipelineCursor, “rawFileName” );
String FILE_TYPE = IDataUtil.getString( pipelineCursor, “FILE_TYPE” );
String WM_BASE = IDataUtil.getString( pipelineCursor, “WM_BASE” );
String SERVER_ROOT = IDataUtil.getString( pipelineCursor, “SERVER_ROOT” );
pipelineCursor.destroy();
All work but use something a little different.
Ray
thanks! That was exactly what I was looking for. I couldn’t figure out how to get the name of a variable.
Thanks again,
Holger.