BPEL

Working with FileAdapter in BPEL – Part 4: Renaming or Moving a File

Post this we use our FileAdapter to Rename or Move a File, this post will not be a result of the above and the part can be done.

See the links below to check the other parts of our project:

Let’s do a project for the part if you need it in the future just to engage in any specific project, so we will first create a project called FileAdapterUtilBPEL as follows:

Imagem Blog UansCarvalho

Let us now import a WSDL which will set our operations and it contain our input (Request) and output (Response) responsible for our input and output parameters which we will use in our project BPEL

Then import the WSDL for our project FileAdapterUtilBPEL clicking here

Now copy this WSDL into SOA Content of your project

Imagem Blog UansCarvalho

Creating the BPEL:

Drag a BPEL Process component, and check the options as follows:

  • Choose BPEL 2.0 Specification
  • Name it RenameOrMoveBPELProcess
  • In Template select Base on a WSDL
  • In Service Name put RenameOrMoveFile
  • Let marked the flag Expose as a SOAP serivice
  • In WSDL URL look for the WSDL that lowered: FileUtilContract.wsdl

Imagem Blog UansCarvalho

Now drag a File Adapter into your composite.xml and name it RenameOrMoveFileAdapter

Imagem Blog UansCarvalho

Leave checked the Define from operation and schema (specified later)

Imagem Blog UansCarvalho

Below check the Write

Imagem Blog UansCarvalho

Below you do not need much because we specify the data that we insert here will be lost later because we will change the properties of this component so we can put whatever we want in this step.

Then, put just one bar / in Directory for Outgoing Files and put a * in File Naming Convention and click in Next

Imagem Blog UansCarvalho

Check the Native format translation is not required

Imagem Blog UansCarvalho

Click Finish

Imagem Blog UansCarvalho

Now connect your RenameOrMoveBPELProcess with her File Adapter and will be as follows:

Imagem Blog UansCarvalho

In his search for the Project RenameOrMoveFileAdapter_file.jca file because in it we will change the component properties.

Imagem Blog UansCarvalho

Stay tuned the <interaction-spec as we will change the ClassName and their properties, then only replace this line and the properties as follows:

<interaction-spec className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
      <property name="SourcePhysicalDirectory" value="/tmp"/>
      <property name="SourceFileName" value="arquivo.txt"/>
      <property name="TargetPhysicalDirectory" value="/tmp"/>
      <property name="TargetFileName" value="arquivo2.txt"/>
      <property name="Type" value="MOVE"/>
</interaction-spec>

That done our open Processo BPEL:

Imagem Blog UansCarvalho

In Variables… set the following variables:

  • nomeArquivoOrigem type String
  • diretorioOrigem type String
  • nomeArquivoDestino type String
  • diretorioDestino type String
  • retornoSucesso type Integer
  • retornoErro type Integer

Imagem Blog UansCarvalho

Now into his drag a BPEL Assign and rename it to Variaveis_Entrada

Imagem Blog UansCarvalho

Open this Assign and connect the variables of your left Request with the variables we created above that are the right and $retornoSucesso variable boot with 0, see below how it should be:

  • $inputVariable.parameters/ns1:request/ns2:nomeArquivoOrigem call in $nomeArquivoOrigem
  • $inputVariable.parameters/ns1:request/ns2:diretorioOrigem call in $diretorioOrigem
  • $inputVariable.parameters/ns1:request/ns2:nomeArquivoDestino call in $nomeArquivoDestino
  • $inputVariable.parameters/ns1:request/ns2:diretorioDestino call in $diretorioDestino
  • Put zero 0 in $retornoSucesso

Imagem Blog UansCarvalho

Drag a Invoke below its Assign Variaveis_Entrada and put the name Invoke_RenameOrMoveFileAdapter, then click the + in Input to create the Variable Input as below, then click OK.

Imagem Blog UansCarvalho

Now click the Properties tab and click the + To and Name: choose option jca.file.FileName and in Variable select variable $nomeArquivoOrigem

Imagem Blog UansCarvalho

Note: This is just a tactic to appear in our source code the properties that need to change.

Imagem Blog UansCarvalho

Click OK up and its BPEL RenameOrMoveBPELProcess click on your Invoke_RenameOrMoveFileAdapter box and then click Source below:

Imagem Blog UansCarvalho

Below the cursor will stay in his Invoke and then we have the code between the <bpelx: toProperty> as follows:

Imagem Blog UansCarvalho

Now change this property with the following:

<bpelx:toProperty name="jca.file.SourceDirectory"
                          variable="diretorioOrigem"/>
        <bpelx:toProperty name="jca.file.SourceFileName"
                          variable="nomeArquivoOrigem"/>
        <bpelx:toProperty name="jca.file.TargetDirectory"
                          variable="diretorioDestino"/>
        <bpelx:toProperty name="jca.file.TargetFileName"
                          variable="nomeArquivoDestino"/>
</bpelx:toProperties>

Here’s how it was:

Imagem Blog UansCarvalho

Okay, now below its Invoke drag another Assign and put the name Variaveis_Saida.

Imagem Blog UansCarvalho

Double click on Variaveis_Saida and turn the variable $retornoSucesso that is to your left side with $outputVariable.parameters/ns1:response/ns2:codigoRetorno on your right.

Imagem Blog UansCarvalho

Note: In this example I am adding some variables retornoSucesso and retornoErro if necessary perform some error handling, however I will not make this post because it will not be our focus.

Create a file in any one location with the arquivo.txt file name and put something into this file to make sure that we will not move within this file.

In my case created in /home/uans/Arquivos

It is with the following content:

Imagem Blog UansCarvalho

Make deploy your application

Imagem Blog UansCarvalho

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

Note: The port 10000 is the number that chose to create my Domain BPEL

Login:

Imagem Blog UansCarvalho

Click on your project: FileAdapterUtilBPEL[1.0]

Imagem Blog UansCarvalho

The screen right click Test

Imagem Blog UansCarvalho

Then fill in as below and put the data where you created the file, in my case are as follows:

Imagem Blog UansCarvalho

Note: See we’re renamingo arquivo.txt that is /home/uans/Arquivos to arquivoTeste.txt and we are movendo to the folder /home/uans/Arquivos/BKP

Then click on Test Web Service the upper right of the screen

Imagem Blog UansCarvalho

Below the return of our service:

Imagem Blog UansCarvalho

 

Doubts? Leave your comment and download this Projet :-)

 

Hugs and see you 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

2 Comments

Leave a Reply

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