Skip to content

This mediator writes the contents of a base64-encoded binary element in message payload to a file in the local file system and replaces the binary content in the element with full path of the file.

License

Notifications You must be signed in to change notification settings

Unikie/wso2-esb-write-binary-file-mediator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WSO2 ESB Write Binary File Mediator

Build status

What is WSO2 ESB?

WSO2 ESB is an open source Enterprise Service Bus that enables interoperability among various heterogeneous systems and business applications.

Features

This mediator writes the contents of a base64-encoded binary element in message payload to a file in the local file system and replaces the binary content in the element with full path of the file.

E.g. if you have retrieved a BLOB from a database using WSO2 DSS (or a binary file using a VFS proxy), you can store file contents locally using this mediator.

Usage

1. Get the WSO2 ESB Write Binary File Mediator

You have two options:

a) Add as a Maven/Gradle/Ivy dependency to your project. Get the dependency snippet from here.

b) Download it manually from here.

2. Install the mediator to the ESB

Copy the wso2-esb-write-binary-file-mediator-X.Y.Z.jar to $WSO2_ESB_HOME/repository/components/dropins/.

3. Use it in your proxies/sequences

Examples

Minimal example:

<writeBinaryFile>
   <binaryElementXPath value="//binaryContent"/>
   <targetDirectory value="/tmp"/>
   <targetFileName value="foo.zip"/>
</writeBinaryFile>

Full example:

<writeBinaryFile>
   <binaryElementXPath value="//binaryContent"/>
   <targetDirectory value="/tmp"/>
   <targetFileName value="foo.zip"/>
   <forceUniqueFileName value="false"/>
   <allowOverwrite value="false"/>
</writeBinaryFile>
Example scenario

Sample payload before mediator:

<Entries xmlns="http://ws.wso2.org/dataservice">
  <Entry>
    <id>8</id>
    <image>iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY2BgYAAAAAQAAVzN/2kAAAAASUVORK5CYII=</image>
  </Entry>
</Entries>

Using mediator config:

<writeBinaryFile>
   <binaryElementXPath xmlns:ns1="http://ws.wso2.org/dataservice" value="//ns1:image"/>
   <targetDirectory value="/tmp"/>
   <targetFileName value="temppi.png"/>
</writeBinaryFile>

Payload after mediation:

<Entries xmlns="http://ws.wso2.org/dataservice">
  <Entry>
    <id>8</id>
    <image>/tmp/temppi.png</image>
  </Entry>
</Entries>

And the file exists in /tmp/temppi.png

Input fields

Field Value type Description Required
binaryElementXPath value XPath to the element with the binary content Yes
targetDirectory value/expression The folder where output file is written Yes
targetFileName value/expression Name of the file to be written Yes
forceUniqueFileName value Whether or not the mediator forces a unique file name for output.

If "true", message context id will be appended to the start of the output file name (e.g. with targetFileName="temppi.png" the actual output file would be something like urn:uuid:e6e188f0-fd9b-4871-af09-8e36733023b5_temppi.png)

Default is "false"
No
allowOverwrite value Whether or not BinaryFileMediator is allowed to overwrite an existing file.

Default is "true"
No

Technical Requirements

Usage

  • Oracle Java 6 or above
  • WSO2 ESB
    • Wrapper Mediator has been tested with WSO2 ESB versions 4.8.1, 4.9.0 & 5.0.0

Development

  • Java 6 + Maven 3.0.X

Contributors

Copyright © 2016 Mystes Oy. Licensed under the Apache 2.0 License.

About

This mediator writes the contents of a base64-encoded binary element in message payload to a file in the local file system and replaces the binary content in the element with full path of the file.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages