KB Article #62051

Managing unexpected HTTP GET requests with HTTP asynchronous mode.

Problem

My integration includes a sequential activity with a MBC stage that manages asynchronous HTTP requests. Only POST requests are supposed to be taken into account but I would like to manage GET requests and say return HTML pages to the requester.


Resolution

Let the HTTP input channel accept all HTTP methods and the MBC decide what to do for each method. For  instance, when a GET request is captured, the MBC could parse the accompanying URL and accordingly read an HTML file and forward its contents to the requester.



Sample code for a GET alternative:



       $NewMessageId = MBC_HIERCHMSGENV.CreateMessage($SessionId, $MessageId);
       $attributeString = MBC_HIERCHMSGENV.GetAttribute($SessionId, $MessageId,
                                                                         HTTPRCONFIG.$HttpServerReceiveInfoAttribute);
       $receiveInfoAttributes = HTTPRCONFIG.HttpServerReceiveInfoUnpack($attributeString);
       $METHOD = $receiveInfoAttributes.$HTTPRequest.$Method;
       $URI = $receiveInfoAttributes.$HTTPRequest.$Uri;



       IF ($METHOD = "GET") {
           IF ($URI = "/") {
              $fileName = "Home.html";
           } ELSE {
               $fileName = $URI[2, STRLEN($URI)];
           }
           TRY {
               /* Read file contents into $fileContents variable */
               .
               .
               .
               $asynchronousAttributes.$responseCode = "200 OK";
               $hData = HTTPUTIL.WriteToStore($fileContents);
           } CATCH $exception
               WHEN OTHERS {
                   $asynchronousAttributes.$responseCode = "404 Resource not found";
                   $hData = HTTPUTIL.WriteToStore("404 Resource not found.");
               }
           }
      .
      .
      .