BPEL - Adding a File Adapter
| Note that for ESBs follow the guide at the end of this link. [ESB - Adding a File Adapter] |
All you have to do to add a file adapter in a BPEL is either drag and drop a File Adapter from the services tab within the palette or just drop a generic Partner Link within onto you BPEL work area, for the purposes of this guide, I ashall follow the steps for the File Adapter option.
Structure

Note: If you wish you can use an assign activity node instead of the transform activity to initialise the variables. Also note that if you simply use a transform as I have done, you will always get the warning flag (the yellow flag above the Invoke activity) this warning is simply saying that you have not initialised the variable.
Setting it up
Specifying the output format
First thing you need before writing a file adapter is to have some kind of output format for the file, I have chosen a space delimited file format with each message terminated with a newline, please note that by default the File Adapter does not append to the file, if the file does not exist, it will create it, however if it does, it will attempt to overwrite it, please follow the steps in the "Appending to a file" section to find out how to get the adapter to append to a file as opposed to writing over it.
In order to specify the file output format, like most things in Oracle Fusion development, you are required to set up a XML schema (XSD file) detailing the input nodes as well as the output format, for the purposes of this example, here is the file adapter that I have used, for those who have participated in the 2 day SOA training course, this schema was based on the requirement that I have to get the first and last name of the customer, as well as what they bought, space delimited (so the namespace will match to the namespaces within the sample BPEL workflow given in that course).
<?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" targetNamespace="http://www.globalcompany.com/ns/order" xmlns:tns="http://www.globalcompany.com/ns/order" elementFormDefault="qualified" attributeFormDefault="unqualified" nxsd:encoding="ASCII" nxsd:stream="chars" nxsd:version="NXSD"> <xsd:element name="filecontent"> <xsd:complexType> <xsd:sequence> <xsd:element name="firstname" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy=" " nxsd:quotedBy='"'></xsd:element> <xsd:element name="lastname" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy=" " nxsd:quotedBy='"'></xsd:element> <xsd:element name="product" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy='"'></xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
When complete, take a look at the Design view of the XSD file and you should get something similar to the picture below (if you used the same file I have, if you are specifying your own schema, then the result will be different depending on how you decided to set up your schema).

This schema basically represents a complex type containing 3 string values for those who are very Javaish, heres what the java structure would look like:
public class filecontent { public String firstname; public String lastname; public String product; public String toString() { return firstname + " " + lastname + " " + product + "\n"; } }
This schema should be placed within the bpel folder inside your BPEL project.
Setting Up The File Adapter
Simply drag and drop a File Adapter from the Services tab of the Palette onto your BPEL, this should bring up the wizard, skip the welcome message for the wizard and .
Fill in the details as described below:
Adapter Configuration Wizard
| Step | Details to fill |
|---|---|
| Welcome | Just skip this |
| Service Name | Service Name: Give your service a name, I have chosen "MyFileWriter" for my File Adapter (seen in the screenshot in the Structure section) Description: A description for your service (Optional). |
| Operation | Operation Type: Write File Operation Name: Name it whatever you like, I just kept the default "Write" |
| File Configuration | Directory specified as: Just leave this as the physical path for now Directory for Outgoing Files (physical path): Pick a directory where the created files will go, I recommend an empty folder just so you wont have the problem of accidentally overwriting a file that you need File Naming Convention: Anything.txt will do Leave the other options as is for now |
| Messages | The most complicated step in my opinion this is where the schema created in the previous section comes into play, as we already created the schema, we only have to fill out one section. Schema Location: Click browse, try to find your schema within the Project Schema Files folder, then just select the right message type (in my case this was "filecontent") Schema Element: Should be automatically populated |
Once the configuration is done, you should have a new File Adapter available on your BPEL.
Setting Up The Variable
After setting up the File Adapter, you now require some kind of variable within your system, from here you have 2 major design options, which is to either make a global variable or limit the scope of the variable by dragging on a Scope process activity. Here is the instructions for each case:
Global
- Go to the structure
- Expand out Variables folder within your BPEL Structure
- Expand out the Process schema
- Right click the Variables folder underneath the Process Schema and select Create Variable
Scope
- Go to the structure
- Expand out Variables folder within your BPEL Structure
- Expand out the Process schema
- Expand out the Scope that you have created for this File Adapter
- Right click the Variables folder underneath your Scope and select Create Variable
Both
After completing the previous steps should bring up the Create Variable screen, fill in the details as explained below
| Tab | Details to fill |
|---|---|
| General | Name: A name for the variable, I shall call it MyVariable for the purposes of this example Type: Select Message Type, then use the flashlght icon to open up the Type Choose screen, expand out the Message Types folder, then the partner Links folder, now find and expand out your File Adapter, under your File Adapter, expand out the wsdl, then the Message Types, and choose the msg type that matches the schema you defined earlier for the File Adapter |
| Sensors | This is like a listener for the variable, not required for this |
You should now have a new varable to play with in your BPEL.
Setting Up The Transform
Drag a Transform Process Activity from the Process Activity Palette onto your workspace, in the location where you want to call the File Adapter service, note that if you used a scope for your variable, you have to make sure that the Transform is within that scope.
This will create a Transform Process node, feel free to rename this to anything you want, double click and open the Transform, here you can specify the actual transformation process.
In the Transformation tab, fill out the following:
Source Variable: Select the source that you want to read from, in most cases this would be the inputVariable, however you may select any other variable that contains the data you require.
Target Variable: The destination of the transform, for the purposes of this example, the target varable should be MyVariable (or whatever you named it in the previous section.
Source Part: The part of the variable, if inputVariable is selected, then just leave this as payload, if you are selecting other variables, you may want to select a different value depending on where your variables are stored within the parts.
Target Part: The message name, in this case it is filecontent
Mapper Configuration: Give a name for the new transform file, then click the wand to create a new XML mapping file.
The above steps wll bring up a new window showing the mapping file in a graphical format, from here you can expand out the source and target variables and then map them from one to the other by just drag and drop, there are also a variety of String funtions that can be used within the transform, simply drag the function that you wish to use into the middle of the transform, then drag the input variables from the left into the function, these would become the inputs of the function, then drag the function to the destination variable, the output of the function will be piped to the selected variable.
For this example, simply find the firstname, lastname and productname fields from the input variable, then drag them directly onto the corresponding output variables, save the transform and you are done.
When complete, take a look at the Design view of the XSL Transformation file and you should get something similar to the picture below (if you used the same mappings I have, if you have decided on a different mapping or used your own schema, then the result will be slightly different however the core concepts will be the same).

Setting Up The Invoke
With the Transform set up to populate your variable, you can now Invoke your File Adapter, simply drag am Invoke node from the Process Activities tab of the Palette to right after the Transform, this will create an Invoke Process node, now just drag a line from the arrow of the Invoke to your File Adapter, this will bring up the Edit screen for the Invoke node.
The Partner Link and the Operation fields should be automatically filled out for you (in this example this is true as the destination partner link only has 1 possible operation called Write, in cases where the target contains more than 1 operation, then you may have to change the operation that the invoke actually calls), all you have to do now is click the flashlight icon next to the Input Variable field, then find the Variable that you created in the previous sections (that I have called MyVariable), click Ok and you are done.
Congratulations
If you have followed all of the above instructions, you should now have a functional File Adapter which writes to a file.