Tags
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:
- Working with FileAdapter in BPEL – Part 1: Reading the file from directory
- Working with FileAdapter in BPEL – Part 2: Reading the file content
- Working with FileAdapter in BPEL – Part 3: Saving the file contents in the database
- Working with FileAdapter in BPEL – Part 4: Renaming or Moving a File
- Working with FileAdapter in BPEL – Part 5: Deleting a file
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
Now open composite.xml the FileAdapterBPEL project and drag a File Adapter for External References and as screen below click Next
Service Name in place LerArquivo and click Next
Let down the option marked Define from operation and schema (specified later)
Below click Synchronous Read File and click Next
Now click Logical Name put FILE_IN and click Next
File Name put the arquivo.txt file name and click Next
Now click on the magnifying glass and look for the dadosArquivo.xsd file we created, click File and then OK
Once this is done we will have the screen below, then click Next:
Now click Finish
We get the following screen now:
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:
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:
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
We will then have the following screen:
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.
Then we should have the following screen:
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
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:
Now drag the arrow of your ReceiveCapturaArquivo to our CapturaArquivo and click the screen below + to define our Input variable and click OK
Check also the option Create Instance
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:
In the screen above click OK now do the same procedure up to now we store our directory to have the screen below:
Click OK on the screen above
It will then be as follows:
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’
In this way we will have the condition $IsEOF = ‘false’ until you do not arrive at the End of File.
Now within your Loop drag an Invoke component
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
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
From now on do the same procedure:
Now below its LerArquivoBPELProcess.bpel click Source
At the end of the process look for the line <bpelx:toProperties> and <bpelx:fromProperties> as below:
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:
‘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
For now we will have the following screen:
Now drag an IF component to below its InvokeLerArquivo, rename the IF to DadosEncontrados and place the following condition:
- $noDataFound = ‘false’
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:
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
Click OK
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>
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:
Click on your project: FileAdapterBEL[1.0]
Note that an instance was created.
Click on this instance and subsequently in LerArquivoBPELProcess
Now click the Flow tab, and then in InvokeLerArquivo
Scroll to the end of file and see your Payload OutPut
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