When creating a Java service, beware of a couple code generation bugs in the B2B Integrator environment. The steps below identify how to correct the problems (which may be corrected in later versions of the B2B Integrator–I’m using 4.0.1).
To create a new Java service:
1 Select File | New from the menu or click on the toolbar.
2 Select the Java Service radio button and click Next>.
3 Type a name for the service, select the folder where the service is to be created and click Finish.
4 Add any imports desired to the Import field on the Shared tab. For example, you might import java.io.* if your service will use any file operations.
5 Define the input and output fields for the service on the Input/Output tab.
6 Select Compose | Generate Code… to generate the code needed to read the input fields from the pipeline into Java variables and to put Java variables into the output fields.
7 Select the For Implementing this service radio button and click Next>.
8 Select the desired options for Which records? and Which fields? settings. The defaults are normally what you want.
9 Select the Source tab, position the cursor in edit field and press Ctrl+V or select from the menu to paste the generated code.
10 The first bug in the code generator is that it places the variable declarations inside if blocks. This makes the variables unavailable outside of the blocks. Move the variable declarations outside of the blocks to the top of the code. Remember to remove the type declarations from the statements within the if blocks.
11 The second bug in the code generator is that it places quotes around the variable name in the pipelineCursor_1.insertAfter call. Remove the quotes from the second parameter.
12 The third bug in the code generator is that it does not generate variable declarations for the output fields. Define any variables that are needed. If the variable is not a String, you will need to convert it to a String when passing it to pipelineCursor_1.insertAfter.
13 Place your code as indicated in this sample:
String var1 = “”;
String var2 = “”;
String var3 = “”;
IDataHashCursor pipelineCursor = pipeline.getHashCursor();
if ( pipelineCursor.first( “var1” ) )
var1 = (String) pipelineCursor.getValue();
if ( pipelineCursor.first( “var2” ) )
var2 = (String) pipelineCursor.getValue();
// PLACE YOUR CODE HERE
IDataHashCursor pipelineCursor_1 = pipeline.getHashCursor();
pipelineCursor_1.insertAfter( “var3”, var3 );
Refer to the “Building Coded Services