FTP uploads validation with Intel® SOA Expressway

If you are a web services developer and you build a new SOA system, you probably choose HTTP as a transport. However, sometimes you should support legacy systems that use other protocols for information exchange, for example, FTP. There are several technical nuances to be addressed in this case.



    1. If client sends data over HTTP, you may analyze it and reply with error code if it’s incorrect. If client uploads data by FTP, how will you notify him that you can’t accept it?


    1. The incoming directory for clients’ uploads may contain bad data – you should add a verification code to file processing job.





Both problems can be solved using SOA Expressway (www.dynamicperimeter.com), better, more flexible implementation of the XML Gateway pattern.

You can set SOA Expressway as an FTP server that analyzes files uploads and passes through only correct data. Clients will receive error messages if validation fails.



This instruction may seem long because every click is put as a separate item, but in fact coding of this application will take less than 10 minutes. Launch Services Designer and let’s start.



Create an empty Intel SOAE Project. Create an empty SOAE workflow in it. Add ‘Receive’, ‘Invoke’, ‘Reply’ activities to the workflow. Let’s configure them one by one.


Receive


Choose Protocol = ‘FTP’, mode = ‘Listening’. Choose port number you want to use and put it after host name in ‘Host’ field – I use port 2121

Invoke



    • In ‘Advanced: Message structure’ section, ‘Request Data Structure’ subsection check ‘Enable proxy pass through for message request’

    • Request Message Data – choose ‘Receive’ as data source

    • Select Protocol = FTP and Invocation Agent Mode = ‘FTP command’

    • Set host name to a real FTP server you’ll use as a backend




Reply

    • In ‘Advanced: Message structure’ section, ‘Request Data Structure’ subsection check ‘Enable proxy pass through for message request’

    • Set response message data source to ‘Invoke’




The simple FTP pass through application is ready. You can make sure that it works. Start your Intel SOA Expressway instance. Select your project in the navigation panel. Open Service Designer dialog: Run -> Deploy as -> Intel SOAE Application. Enter SOAE host name in the dialog and press ‘Deploy’. After application is deployed you can log in to your SOAE host using FTP client. Use your backend FTP server user log in and password. You can browse directories, upload, download and delete files – SOAE management console will show a number of successful requests.



Now let’s modify workflow to validate uploaded files against schema. To do this we’ll analyze FTP commands – if they are store commands ‘STOR’ or ‘STOU’, then message body is validated.

First let’s add the schema to the project:
echo.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example1.org/example1"
xmlns:tns="http://www.example.org/echo">
<element name="echo">
<complexType>
<sequence>
<element name="Text" type="string"/>
</sequence>
</complexType>
</element>
</schema>


Change incoming message type from ‘Binary’ to ‘Echo’. In ‘Receive’ activity properties change ‘Request data’ checkbox to ‘XML’ and press ‘Browse’ to see available types. Select type from current project and press ‘OK’.

To analyze FTP protocol data we need ‘Get Metadata’ activity – put it after ‘Receive’. Choose ‘Receive’ as the message to get metadata from

Add ‘If’ condition and put ‘XMLSchemaValidation’ into it. To edit XPath expression for ‘If’, press xpath editor icon in the table in ‘If’ properties secton. Use XML Query builder for FTP command name. The resulted XPath expression will be

$GetMessageMetadata/md:transport/md:command/md:name='STOR' or $GetMessageMetadata/md:transport/md:command/md:name='STOU'


Configure XML validation activity:


    • Data to validate is ‘$Receive.body’



    • Target namespace is http://example1.org/example/


    • Element name is ‘echo’




The resulted workflow should look like this screenshot:




Save the application, deploy. Log in to FTP proxy application again. Here is the file that conforms to schema:

input.xml

<ns1:echo xmlns="http://example1.org/example1"
xmlns:ns1="http://example1.org/example1">
<Text xmlns="">hello</Text>
</ns1:echo>


Let's try to upload this file and any text file (not conforming to schema)


ftp> put input.xml
200 Command PORT okay.
150 File status okay; about to open data connection.
226-File successfully transferred
226 0.001 seconds (measured here), 250.95 Kbytes per second
ftp: 146 bytes sent in 0.00Seconds 146000.00Kbytes/sec.
ftp> put input.txt
200 Command PORT okay.
150 File status okay; about to open data connection.
421 Proxy command STOR Failed, Session is terminated.
Connection closed by remote host.
ftp>


As you can see, the file that couldn’t be validated, wasn’t stored



Management console shows




This is the very basic application of such kind. Possible extensions are:


    • do not close connection but send user-friendly error message – implemented using fault catch and reply


    • transform files on upload and download

    • use schema URL – if schema changes, the application will fetch and use a new one


    • Using SFTP instead of FTP



Intel SOA Expressway (www.intel.com/software/soae) runtime enables multi-threading, error handling, fault recovery and other features for this application.

有关编译器优化的更完整信息,请参阅优化通知