Dynamically Passing File Name

Embed Size (px)

Citation preview

  • 8/3/2019 Dynamically Passing File Name

    1/13

    http://rahullahiri.blogspot.com/2011/02/dynamically-passing-file-

    namedirectory.html

    Dynamically passing file name,directory and file content to a file adapter

    In this post, I am going to show the steps for passing name,directory and content of a file at runtime to a file adapter.

    The first approach is implemented using a mediator.The steps are discussed below:-

    First,create a new application and a project.

    Now add a file adapter service to your composite.Press next and specify a name for the fileadapter service and press next.

    In the next screen, select Define from operation and schema(specified later) option.Press next.

  • 8/3/2019 Dynamically Passing File Name

    2/13

    In the next screen, select Write file operation.

    In the next screen ,choose physical path.Alternatively you could have chosen logical path also.If

    you specify a logical path, then the process will differ slightly, which is discussed in the section"Using a logical path in the File Adapter Configuration" below.In case of physical path, this

    value is going to be overridden by a value.In case of a logical path, a property(a variable) will be created for the file adapter which we will

    have to populate before invoking the file adapter service.We can specify a static value or anexpression for populating the property.Notice that we can't specify logical file name.Just input a

    name.We are going to override the file name too by the value specified by us.

  • 8/3/2019 Dynamically Passing File Name

    3/13

    Next choose the schema element.Click the magnifying glass icon on the next screen that appears.

  • 8/3/2019 Dynamically Passing File Name

    4/13

    Choose the element that you want to use as file content.The source for the schema file that I used

    is given below.

    FileDetails.xsd---------------------------------------------------

    Take a moment to investigate the source.I have two root level elements:- file_details which isbased on a complex type and the file_content which is a string element.The file_content element

    is used by the file adapter as the content of the file.The file_details element comprises threeelements:- file_name i.e. the name of the file, file_directory i.e the the name of the directory

  • 8/3/2019 Dynamically Passing File Name

    5/13

    where the file is to be written and the contents of the file.The mediator we expose uses thefile_details element.

    We shall choose the file_content element from the FileDetails.xsd

    Hit ok and then hit next.Click finish to close the file adapter configuration wizard.Now drag anddrop a mediator to your composite.Choose a name and select one way interface.Make sure to

    expose the mediator through a web service binding.Select the file_details element as the input.

  • 8/3/2019 Dynamically Passing File Name

    6/13

    Wire the mediator service to the File Adapter Service.Your composite should look like thefollowing figure:-

    Now we shall assign the file name and file paths to the file adapter service.Double click to openthe mplan.We should have only one routing rule.Click on the assign button(marked by the red

    circle in the follwing figure).

    In the window that comes up, click on the green plus icon to add an assign activity.

  • 8/3/2019 Dynamically Passing File Name

    7/13

    In the from action of the assign dialog, select expression from the drop down dialog.Click on thebutton that is highlighted in the image below to bring up the expression builder.

    In the expression builder, select the file_name element under the request part of the 'in' variable

    and then hit the 'Insert into Expression' button.

  • 8/3/2019 Dynamically Passing File Name

    8/13

    Hit Ok.Then on the To side of the assign dialog, select property from the drop down list if notalready selected and then choose the jca.file.FileName property.

  • 8/3/2019 Dynamically Passing File Name

    9/13

    Hit ok.Again add another assign activity.Follow the same steps.On the From side of the assigndialog, select the file_directory element and on the To side, select jca.file.Directory property.

  • 8/3/2019 Dynamically Passing File Name

    10/13

  • 8/3/2019 Dynamically Passing File Name

    11/13

    Hit Ok twice to come back to the mediator mplan.Now add a transform activity to populate the

    file contents.Click on the transform button as highlighted in the following image.

  • 8/3/2019 Dynamically Passing File Name

    12/13

    In the new window that pops up, select "Create new mapper file" radio button and provide a

    name for the xsl file.Hit ok.Create the follwing mapping as shown in the followingfigure.Connect the content from the left hand side to the file_content on the right hand side.

  • 8/3/2019 Dynamically Passing File Name

    13/13

    So we are done.Deploy your composite, go the EM console and test.Provide a file name, a validlocation and the contents of the file and invoke the mediator.If all goes well, the file with the

    given name,content will be written.at the provided location.

    Using a logical path in the File Adapter Configuration:

    If you choose a logical path, then a property will be created for the adapter.You can see theproperty when you select the database adapter and go to properties inspector;the property should

    be visible in the property section;you should provide a value which we shall override in the sameway as explained above.

    The rest of the steps are the same.Go ahead and deploy the service.We can achieve this same thing using BPEL. However, I guess you can figure that out once

    you're done with this tutorial.Hope this helps.