Wednesday, January 21, 2015

#375 SOA / BPM 12c Bundle Patch released

















Installing the patch


Unzip to a directory of your choice.
Read the README.















Thursday, January 15, 2015

#374 MFT --> Creating Custom Callouts - A simple example

Introduction 

Let's go straight to the MFT docs -


Oracle Managed File Transfer provides built-in compression, decompression, encryption, and decryption actions for transfer preprocessing and postprocessing. See Setting Up Transfer Preprocessing and Postprocessing Actions and Setting Up Source Processing Actions for details.

You can create new preprocessing and postprocessing actions, which are called custom callout
Custom callouts can be associated with either the source or the target. The sequence of processing action execution during a transfer is as follows:

Source preprocessing actions
Target preprocessing actions

Payload delivery

Target postprocessing actions
Source postprocessing actions








Here is the jar containing the interfaces -
YourFMW4MFTDir\mft\modules\oracle.mft_12.1.3.0\core-12.1.1.0.jar



Now before I get to my simple example, I just want to highlight the
excellent MFT resources available on the Oracle SOA PM blog.
Check it out right here

The Simple Example 


So now to my simple example -
I need to parse the files and convert the contents as follows -

Change any occurrences of Ireland to Eire
or
Change any occurrences Eire to Ireland and visa-versa.

The test file I use is as follows -









So I will expect the output to have Eire instead of Ireland.
Eire, for those interested is the Gaelic name for Emerald Isle.

Implement the Callout


I followed this section from the MFT docs to create the Java class that will
do the conversion.

The code is very simple - the main jar required is here -



I add this to the JDev project -










Here is the implementation -

package mftcallout;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import java.util.Map;

import oracle.tip.mft.engine.processsor.plugin.PluginContext;
import oracle.tip.mft.engine.processsor.plugin.PluginOutput;
import oracle.tip.mft.engine.processsor.plugin.PreCalloutPlugin;

public class NcIECallout implements PreCalloutPlugin {
    public NcIECallout() {
        super();
    }
    // Callout changes the payload
    @Override
        public boolean isPayloadChangeRequired(PluginContext context,
                Map calloutParams) {
            return true;
        }
    
    @Override
       public PluginOutput process(PluginContext context, InputStream input,
               Map calloutParams) {
           return null;
       }
    
    @Override
       public PluginOutput process(PluginContext context, InputStream input,
               OutputStream out, Map calloutParams) {
           String type = calloutParams.get("Type");
           if ("Eire2Ireland".equals(type)) {
               doConversionEire2Ireland(input,out);
               
           }
           else{
               doConversionIreland2Eire(input,out);
           }
           return new PluginOutput();
       }
    
    private void doConversionIreland2Eire(InputStream in, OutputStream out) {
            BufferedReader bufferIn = null;
            BufferedWriter bufferOut = null;
            try {
                DataInputStream dataIn = new DataInputStream(in);
                bufferIn = new BufferedReader(new InputStreamReader(dataIn));
                DataOutputStream dataOut = new DataOutputStream(out);
                bufferOut = new BufferedWriter(new OutputStreamWriter(dataOut));
                // For each line in the un-normalized file
                String line;
                while ((line = bufferIn.readLine()) != null) {
                    if(line.equalsIgnoreCase("Ireland")){
                        line = "Eire";
                    }
                    bufferOut.write(line);
                    bufferOut.write("\r\n");
                          }
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    bufferIn.close();
                    bufferOut.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    private void doConversionEire2Ireland(InputStream in, OutputStream out) {
            BufferedReader bufferIn = null;
            BufferedWriter bufferOut = null;
            try {
                DataInputStream dataIn = new DataInputStream(in);
                bufferIn = new BufferedReader(new InputStreamReader(dataIn));
                DataOutputStream dataOut = new DataOutputStream(out);
                bufferOut = new BufferedWriter(new OutputStreamWriter(dataOut));
                // For each line in the un-normalized file
                String line;
                while ((line = bufferIn.readLine()) != null) {
                    if(line.equalsIgnoreCase("Eire")){
                        line = "Ireland";
                    }
                    bufferOut.write(line);
                    bufferOut.write("\r\n");
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    bufferIn.close();
                    bufferOut.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
}

Now to the creation of the callout definition file -
The details here surface in the MFT console - i.e. the MFT user will be
able to add a pre-processing action - "Eire to Ireland text conversion"









I jar up the Java class and copy it, along with the xml file above to the following directory -
YourFMW4MFTDir\user_projects\domains\mft_domain\mft\callouts e.g.










Create this directory, is it doesn't already exist.








Now the next step is to register the new callout with MFT. We do this via WLST -



wls:/mft_domain/serverConfig> crtCalls('D:\Work\envs\FMW12c\MFT\user_projects\do
mains\mft_domain\mft\callouts\EireCalloutDef.xml')

Create a simple MFT Transfer to leverage the callout


Now I create a new source (File) in MFT and add a pre-processing step -










Now you can see how all of these values come from the callout definition file.
I then create a target and a transfer and test with the following file -







the output file is as follows -







btw. the Gaelic for England is Sasana, for France, is an Fhrainc.
  
Java Project here

#373 MFT --> Leveraging Remote sFTP as target / WLST support

Simple scenario: MFT transfer from local file to remote sFTP server.

I am using Cerberus FTP server here.
It is configured for sFTP as follows -


















I used PuttyGen to generate keys - they are here -












My Cerberus user - niall - is configured as follows -














Folder is D:\Work\envs\CerberusFTP\NcFolder

niall will use the public key, generated earlier.























I now import the private key into MFT using wlst -




















type help("mft") to see all mft related commands.





















now import the key -

importCSFKey('SSH', 'PRIVATE', 'ncMFTssh', 'D:\Work\keys\myPriv.ppk')




Now to the MFT Console - Administration tab

I set the SSH Keystore - PrivateKey password

















I now define my remote sFTP target -

















I create a file source -

























and then a transfer -


















I deploy and test -

source folder -











target directory -



Friday, January 9, 2015

#372 File Adapter Valves --> convert xlsx to csv

Simple scenario here - I need to process an excel .xlsx file in SOA Suite.

This was very straightforward, as Mark Foster from the A-Team has detailed the steps for doing this, albeit with BPM. He details exactly how to implement the file adapter valve, leveraging Apache POI for the xlsx to csv conversion.

Check out his post here

Btw. I am using JDev SOA Suite 12c Quickstart.

I just followed Mark's instructions and then copied the valve implementation jar to the following directories -













and










I re-started the integrated server.

My composite is as follows -
















The BPEL process does nothing, except accept in the payload.

I deploy and test -

Here is the sample .xlsx file from Mark -










Here is the audit trail from the BPEL instance -


















Java project for xlsx conversion here

SOA project there

Again, a big thank you to Mark!


#371 how to execute a shell script command from SOA Suite

Simple approach here -

execute the shell cmd from Java.
Expose the Java class as a web service.
Invoke from BPEL.

I got the Java code from here
Essentially the web service operation accepts in a website as string.
All I do is execute a ping and then return the result.

I massaged it a bit and then deployed as a web service to Weblogic.

I then created the composite -







Deploy and test -












Java project here
SOA project there

Thursday, January 8, 2015

#370 MFT --> Resubmitting successfully transferred files


I have a simple MFT transfer --> MyAA 2 MyBB













As you can see, MFT has successfully transferred the following file -







Here is the monitoring view from the MFT console -




Here are the current contents of the file at the target -











Now I edit the file at the source -














I now go back to the MFT Monitoring console and click resubmit transfer.




























#369 UMS Email adapter (part 2)--> send PDF file as an email attachment

Simple scenario -

Read in a pdf file and send it as a pdf attachment.









fileService_4 configuration -














































































The strategy I am using here, is not to read the contents, so I get the file and
directory names from the header. These I copy into process variables -


















This information will be used in a function to
add the file as an attachment to the email.

I will be using the ora:readFile function -
e.g. ora:readFile('file:///c:/docs/My.pdf'')

I need to swap the "\" to "/" in the directory variable.
I then create a variable with the value'file:///c:/docs/My.pdf''






I then set the attachment values on the EmailPDF activity as follows -








I deploy and test -

For testing purposes, I will drop the BAM pdf into the input directory.










The email arrives with the attachment -














I open the pdf -