Question
· Mar 9, 2016

Using Ensemble for MIME multipart/form-data

I currently have an Ensemble production which accepts and handles SOAP requests.  I now need to support the exact same data, but instead of coming in as a SOAP request, comes in as a multipart/form-data request.  The body of the message would look something like:

 

------------------------------j1ks0od6m45rjpgz5208y85917swo61hl3u63
Content-Disposition: form-data; name="TimeStamp"
 
2016-02-22T07:26:49Z
------------------------------j1ks0od6m45rjpgz5208y85917swo61hl3u63
Content-Disposition: form-data; name="ID"
 
TEST
------------------------------j1ks0od6m45rjpgz5208y85917swo61hl3u63—

 

I have looked into using Ensemble with an HTTP.InboundAdapter.  This seems to have two problems:

1) The use of the HTTP.InboundAdapter forces Ensemble to bind the service to a different port than the current CSP port.

2) The HTTP.InboundAdapter isn't correctly reading the multipart data.  

 

I also looked at using a CSP page.  This solves both of the above problems, correctly reading and populating the %request object.  However then I am stuck with the need to recreate a lot of the same logic that existed in handling the SOAP request for this alternate format. 

 

I'm thinking I'm going to need to create my own Adapter for Ensemble, but I'd rather not reinvent the wheel if I don't have to.  Has anybody already solved this problem, or can point me in the right direction?

Discussion (4)0
Log in or sign up to continue

Hi Mike,

Would it help to have your service extend EnsLib.HTTP.GenericService?  That would support using the standard CSP port, while also giving you the Ensemble Business Service functionality.  Per the class reference docs:

 

----------------

class EnsLib.HTTP.GenericService extends EnsLib.HTTP.Service

Ensemble Generic HTTP Service based BusinessService class. Can use an HTTP InboundAdapter listener, or the standard CSP Service mechanism, or both. In order for the CSP mechanism to work, HTTP Services using this class must be configured with the invoking URL including ?CfgItem= giving the config item name. (Configured Services exposed using the HTTP Inbound Adapter may also be invoked with this URL parameter but because each configured Inbound Adapter listens on its own TCP/IP port this parameter is just a safety check for them.)

---------------------------

 

Or if you're already doing this, can you elaborate on which logic you would have to recreate here that the InboundAdapter gave you?

 

I am also curious to hear from others who have solved this problem who can offer the best approach.

 

Thanks,

Steve 

Hi Mike,
To retrive multi-part from %resquest you have do to this in the %CSP.REST class :

    // Get properties
    set body = %request.Get("body")
    if '$d(body) {
      $$$ThrowOnError($$$ERROR(9200,"no parameters"))
    }
    set dynaBody = {}.%FromJSON(body)

    // Get stream
    set stream = %request.GetMimeData("file")
    if ('$IsObject(stream) {
      $$$ThrowOnError($$$ERROR(9200,"no file"))
    }

To get property you have to use Get and for stream GetMimeData
In my example my body is a json.