BPEL

Working with FileAdapter in BPEL – Part 2: Reading the file contents

In this Part 2 we will continue the previous post where we create the process to read the file in a directory, now in this post we will create the process to read the file contents with our BPEL.

Something that will add to our process will be a dynamic reading of the contents of this file as we will read the bits in file if this file is too large.

See the links below to check the other parts:

Our first step will be to create a dadosArquivo.xsd file where will the information on the content of our file, so it creates the file and copy and paste the content below.

<?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"
            xmlns:tns="http:/uanscarvalho/blog/ArquivoFile"
            targetNamespace="http:/uanscarvalho/blog/ArquivoFile"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified"

            nxsd:version="NXSD"
            nxsd:stream="chars"
            nxsd:encoding="US-ASCII"
>


  <xsd:element name="Arquivo">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Arquivo" minOccurs="1" maxOccurs="unbounded">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="header" type="xsd:string" nxsd:style="fixedLength" nxsd:length="5" />
              <xsd:element name="detail" type="xsd:string" nxsd:style="fixedLength" nxsd:length="5" />
              <xsd:element name="detail" type="xsd:string" nxsd:style="fixedLength" nxsd:length="9" />
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

See where we should save the file dadosArquivo.xsd

Imagem Blog UansCarvalho

Now open composite.xml the FileAdapterBPEL project and drag a File Adapter for External References and as screen below click Next

Imagem Blog UansCarvalho

Service Name in place LerArquivo and click Next

Imagem Blog UansCarvalho

Let down the option marked Define from operation and schema (specified later)

Imagem Blog UansCarvalho

Below click Synchronous Read File and click Next

Imagem Blog UansCarvalho

Now click Logical Name put FILE_IN and click Next

Imagem Blog UansCarvalho

File Name put the arquivo.txt file name and click Next

Imagem Blog UansCarvalho

Now click on the magnifying glass and look for the dadosArquivo.xsd file we created, click File and then OK

Imagem Blog UansCarvalho

Once this is done we will have the screen below, then click Next:

Imagem Blog UansCarvalho

Now click Finish

Imagem Blog UansCarvalho

We get the following screen now:

Imagem Blog UansCarvalho

So far, just create a file adapter making a synchronous read, now we modify it so that it reads the file into pieces. This is done by modifying the file LerArquivo_file.jca.

Then open the file as follows:

Imagem Blog UansCarvalho

See above the line tag <interaction-spec where we have:

<interaction-spec className="oracle.tip.adapter.file.outbound.FileReadInteractionSpec">

Change to:

<interaction-spec className="oracle.tip.adapter.file.outbound.ChunkedInteractionSpec">

And add the property below the value of this property “50” I am stating that the file is read in lines 50 to 50, in a later post I will show how to use this function step by step, an hour‘s interesting you know that there

<property name="ChunkSize" value="50"/>

So should look like this:

Imagem Blog UansCarvalho

Save and close the file.

Let’s now create the BPEL process that will actually read the content of our file.

  • Drag a BPEL Process for Components
  • Check the BPEL 2.0 Specification
  • Put the name LerArquivoBPELProcess
  • In Template choose option Define Service Later
  • Click on OK

Imagem Blog UansCarvalho

We will then have the following screen:

Imagem Blog UansCarvalho

So now LerArquivo drag the arrow to your BPEL process and then drag the arrow of your CapturaArquivo also see that the screen below, then click OK.

Imagem Blog UansCarvalho

Then we should have the following screen:

Imagem Blog UansCarvalho

Open your BPEL process and add the following variables:

  • dir, type string – will store the filename
  • file, type string – will store the directory where the file is
  • isEOF, type string – Specifies the end of file
  • lineNumber, type string – Specifies the file line number
  • columnNumber, type string – Specifies the number of File column
  • noDataFound, type string – Specifies whether there is more data to read
  • isMessageRejected, type string – Specifies whether error occurs in the process
  • rejectionReason, type string – Specifies the error process in the event

Imagem Blog UansCarvalho

The BPEL process should begin when the file is captured by our File Adapter “CapturaArquivo

So even in your BPEL process within him drag the Receive component then rename it to ReceiveCapturaArquivo and should stay as screen below:

Imagem Blog UansCarvalho

Now drag the arrow of your ReceiveCapturaArquivo to our CapturaArquivo and click the screen below + to define our Input variable and click OK

Imagem Blog UansCarvalho

Check also the option Create Instance

Imagem Blog UansCarvalho

Now click on Properties and will add two properties to we store the name and directory of the received file.

Properties click the + and Name: Look for the jca.file.name name and variable Variable browse our file and we should have the following screen:

Imagem Blog UansCarvalho

In the screen above click OK now do the same procedure up to now we store our directory to have the screen below:

Imagem Blog UansCarvalho

Click OK on the screen above

It will then be as follows:

Imagem Blog UansCarvalho

Now we get to process each line of the file you need to create a loop.

While drag the component so that it is below the ReceiveCapturaArquivo and rename it to LendoArquivo and within seven IsEOF to false Condition:

$isEOF = ‘false’

Imagem Blog UansCarvalho

In this way we will have the condition $IsEOF = ‘false’ until you do not arrive at the End of File.

Imagem Blog UansCarvalho

Now within your Loop drag an Invoke component

Imagem Blog UansCarvalho

Now drag the arrow of your Invoke to LerArquivo your Parter Links and within Edit Invoke leave as below:

  • Name: InvokeLerArquivo
  • Input: Click the + to create your Input variable automatically
  • Output: Click the + to create your Output variable automatically

Imagem Blog UansCarvalho

Now click on the Properties tab To and click the + sign to add and connect the following variables

  • jca.file.FileName to $file
  • jca.file.Directory to $dir

Imagem Blog UansCarvalho

From now on do the same procedure:

Imagem Blog UansCarvalho

Now below its LerArquivoBPELProcess.bpel click Source

Imagem Blog UansCarvalho

At the end of the process look for the line <bpelx:toProperties> and <bpelx:fromProperties> as below:

Imagem Blog UansCarvalho

Here we connect a few more variables, in this case should” be able to do this for the graphic screen as we did previously for jca.file.Directory and jca.file.FileName but unfortunately we could not because the process list to add the properties not appear jca.file.LineNumber and jca.file.ColumnNumber among others, for some Bug tool, and then we do around here, so add the following variables to:

<bpelx:toProperties>

  • <bpelx:toProperty name=”jca.file.LineNumber” variable=”lineNumber”/>
  • <bpelx:toProperty name=”jca.file.ColumnNumber” variable=”columnNumber”/>

is for:

<bpelx:fromProperties>

  • <bpelx:fromProperty name=”jca.file.LineNumber” variable=”lineNumber”/>
    <bpelx:fromProperty name=”jca.file.ColumnNumber” variable=”columnNumber”/>
  • <bpelx:fromProperty name=”jca.file.IsEOF” variable=”isEOF”/>
    <bpelx:fromProperty name=”jca.file.IsMessageRejected” variable=”isMessageRejected”/>
  • <bpelx:fromProperty name=”jca.file.RejectionReason” variable=”rejectionReason”/>
  • <bpelx:fromProperty name=”jca.file.NoDataFound” variable=”noDataFound”/>

Note: See that exclude the jca.file.Directory and jca.file.FileName property because it was previously necessary add them only to appear in the source code in Source

So we are left with the following source code:

Imagem Blog UansCarvalho

‘false’ to variable ‘isEOF’, ‘1’ to ‘lineNumber’ and ‘columnNumber’.

Go back to the Design screen, drag an Assign before our Loop to begin some variables:

Rename our Assing to IniciaVariaveis and within seven assign the following variables:

  • isEOF = ‘false’
  • lineNumber = 1
  • columnNumber = 1

Imagem Blog UansCarvalho

For now we will have the following screen:

Imagem Blog UansCarvalho

Now drag an IF component to below its InvokeLerArquivo, rename the IF to DadosEncontrados and place the following condition:

  • $noDataFound = ‘false’

Imagem Blog UansCarvalho

In his IF add an Empty component and rename to DadosProcessados and drag another Empty for your ELSE and rename it to DadosNaoEncontrados

We will then have the following screen:

Imagem Blog UansCarvalho

Now just as we did in the first part we will generate a new Config Plan, so delete the previous and create again.

Click the right button on your composite.xml and click Generate Config Plan

Imagem Blog UansCarvalho

Click OK

Imagem Blog UansCarvalho

Open your file FileAdapterBPEL_cfgplan.xml and search by tag <service name=”CapturaArquivo”> and below; <replace> place /home/uans/Arquivos (or as you want but remember to create this directories sequence in your home with the necessary permissions)

<service name=”CapturaArquivo”>
<property name=”FILE_IN”>
<replace>/home/uans/Arquivos</replace>
</property>
<binding type=”jca”/>
</service>

Do the same procedure to tag <reference name=”LerArquivo”>

<reference name=”LerArquivo”>
<property name=”FILE_IN”>
<replace>/home/uans/Arquivos</replace>
</property>
<binding type=”jca”/>
</reference>

Imagem Blog UansCarvalho

Make deploy your project using this Config Plan:

Note: If you have questions how to do this procedure check in Part 1

Create a file named arquivo.txt and place the structure below:

UANS BLOG CARVALHO
FILE READ ARQUIVOS

Attention to the end of the CARVALHO not have blanks and FILES also because the process is positional, ie will respect the position of the characters, see also put as the characters: letters 4 + 4 + space + space + 8 letters letters as defined in our dadosArquivo.xsd

Now copy and paste this arquivo.txt into /home/uans/arquivos (or whatever you defined in your Config Plan)

In your browser go to http://localhost:10000/em

Note: The port 10000 is the number that chose to create my domain.

Login:

Imagem Blog UansCarvalho

Click on your project: FileAdapterBEL[1.0]

Imagem Blog UansCarvalho

Note that an instance was created.

Imagem Blog UansCarvalho

Click on this instance and subsequently in LerArquivoBPELProcess

Imagem Blog UansCarvalho

Now click the Flow tab, and then in InvokeLerArquivo

Imagem Blog UansCarvalho

Scroll to the end of file and see your Payload OutPut

Imagem Blog UansCarvalho

See it created a <Arquivo> for each line of your arquivo.txt

To carry out more tests and see what our project can now try to change the dadosArquivo.xsd file and modify the arquivo.txt
Doubts? Leave your comment and download this Projet :-)

 

Hugs and until the Next

/:-D

 

 

Criei este Blog destinado a desenvolvedores e interessados na Tecnologia Oracle SOA Suite, minha idéia é que no futuro ele sirva de referência para Analistas e Desenvolvedores desde aprendizes a especialistas. Já existem alguns Posts interessantes que abordam um pouco do meu dia a dia, no passar do tempo irei alimentar este Blog com o máximo de informações possíveis, por isso peço por gentileza aos interessados e afins que caso tenham alguma dúvida, sugestão ou crítica que me digam para que eu possa da melhor forma suprir as expectativas e na medida do possível sanar todas as duvidas que vierem a surgir ou até mesmo criar novos Posts abordando algum tópico que venha a ser relevante para todos os interessados. Obrigado Uans Carvalho

Leave a Reply

Your email address will not be published. Required fields are marked *