Sending Binary messages via REST
- Neuron ESB
- Samples and Walkthroughs
- Services (Samples)
- REST Samples
- Sending Binary messages via REST
This sample demonstrates how to make RESTful service calls that contain binary data to Neuron. A REST client sends a jpg file to Neuron, which in turn saves the image to the file system.
The ESB Configuration contains a Process named Publish Image which demonstrates using some of the properties available when a REST request is received. This process checks for the source of the message. If the message was sent from a RESTful client, then the message routed to a file adapter endpoint to save the jpg to the file system. The process retrieves the image filename from the MessageHeader.LocalPath message property and uses the value to set the filename the file adapter will use when saving the file. If the message was received from the file system, it is routed to a RESTful service. For this route, the process retrieves the filename from the file adapter message properties and uses it to set the LocalPath message property. The process also sets the Method, Content-Type and WebBodyFormatMessageProperty property.
This sample uses the same Neuron solution as the other five REST samples. The solution contains five processes. This sample utilizes the “Publish Image” process, the service endpoints named “ImageClientConnector” and “ImageServiceConnector”, and the File Adapter endpoints “ImageFileSubscriberEndpoint” and “ImageFilePublisherEndpoint”.
Running the Sample
Open the Sample
To open this sample, see the topic Using the Neuron Samples and select the REST Client and Service with Binary Payloads sample.
Before running this sample, follow these instructions:
- In the Visual Studio project that opens, build the entire solution.
- Using the Neuron ESB Explorer, verify the Folder Path in the File Adapter Endpoints ImageFilePublisherEndpoint and ImageFileSubscriberEndpoint. If necessary, change the path to a valid location.
Receiving Binary Data
- Start the ImageRESTClient project from Samples\Services\RESTServices\ImageREST\ImageRESTClient\bin\Debug\ImageRESTClient.exe
- In the ImageRESTClient console window, press Enter to start sending messages to Neuron.
- As the sample runs, the client sends an image to the service and displays the HTTP response code.
- The Neuron file adapter endpoint will save the image to the folder Samples\Services\RESTServices\ImageREST\Out.
- When the client completes, press <ENTER> in the client console to close the application.
Sending Binary Data
- Start the REST Service from Samples\Services\RESTServices\ImageREST\ImageRESTService\bin\Debug\ImageRESTService.exe
- Using Windows Explorer, navigate to Samples\Services\RESTServices\ImageREST and copy the file Neuron.jpg.
- Navigate to the “In” folder and paste the file. The file should disappear shortly once the file adapter retrieves it.
- The console window will display a notification when it receives the file, and the service will write the image to the folder Samples\Services\RESTServices\ImageREST\Out.