ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

http_url_post_raw failing for content-disposition error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • http_url_post_raw failing for content-disposition error

    Hello All
    I am trying to execute webservice from RPG with multipart formdata. Below is request which I am trying but getting (RESTEASY007500: Could find no Content-Disposition header within part) in debuglog. I tried to include header until content-type and rest is formatted in body.

    Can someone please help if boundary should be part of header or body? I am using http_url_post_raw to create header and body

    Using postman below request is working fine but when doing it from as400 it is failing.

    Below is postman HTTP generated code:
    Header: in RPG

    POST /webpost HTTP/1.1
    Host: d.testing.com
    Authorization: Basic password
    Cookie: sessioncookie
    Content-Length: 1747
    Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

    Body: in RPG

    ----WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="options"
    Content-Type: application/json

    {
    "requestId": "b2f3021d-b53b-4a75-9ff9-085e6b64d3c0",
    "importOption":{
    "importType": "IMORT_CANGES",
    "filename" : "Testing.xml",
    "activateConflictFileGeneration" : true,
    "createWorkspace" : true,
    "importVersion": "WORKING"
    },
    "versionOption": {
    "label": "Test_V_2",
    "date": 1607987202358,
    "description": "Test V 2"
    },
    "notifOption":{
    "notifEmail": {
    "smtpHost": "smtp.comp.com",
    "smtpPort": 25,
    "from": "test@comp.com",
    "to": ["test@gmail.com"],
    "subject": "Result Process E : ${requestId}",
    "body": "Transaction ${requestId} : <br/> Started : ${startDate}, Ended : ${endDate} <br/> Status: ${status} <br/> ${errorMessage} <br/> Export slotid : ${extD}"
    }
    }
    }

    ----WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="importFile"; filename="/C:/Users/Test1.xml"
    Content-Type: <Content-Type header here>

    (data)
    ----WebKitFormBoundary7MA4YWxkTrZu0gW

  • #2
    Well it is hard to diagnose your problem without seeing your code ... what have you tried?

    Comment


    • #3
      Thanks JonBoy.

      Below is debug log if it helps and should give code I am trying -


      POST /asd/asdfg/launch/ HTTP/1.1
      Host: d.testing.com
      User-Agent: http-api/1.39
      Content-Type: multipart/form-data; boundary=----aROS
      Content-Length: 974
      Authorization: Basic Basickey

      senddoc(): entered
      ----aROS
      Content-Disposition: form-data; name="options"
      Content-Type: application/json
      {
      "requestId": "b2f3021d-b53b-4a75-9ff9-085e6b64d3c0",
      "importOption": {
      "importType": "IMPORT_OVER_CHGS",
      "filename" : "/TEAK.XML",
      "activateConflictFileGeneration" : true,
      "createWorkspace" : true,
      "importVersion": "WORKING"
      },
      "versionOption": {
      "label": "Test_Version_992",
      "date": 1607987212567",
      "description": "Test Version 992"
      },
      "notifOption":{
      "notifEmail": {
      "smtpHost": "dm.mct.com",
      "from": "test@mct.com",
      "to": ["test@gmail.com"],
      "subject": "Result Process Eximp : ${requestId}",
      "body": "Transaction ${requestId} : <br/> Started : ${startDate}, Ended : ${endDate} <br/> Status: ${status}<br/> ${errorMessage}
      }
      }
      }
      ----aROS
      Content-Disposition: form-data; name="importFile"; filename="/TEAK.XML "
      Content-Type: application/octet-stream
      ----aROS

      recvresp(): entered
      HTTP/1.1 500 Internal Server Error
      Expires: 0
      Connection: keep-alive

      Exception in debug log - {"message":"RESTEASY007500: Could find no Content-Disposition header within part","stackTrace":"java.lang.RuntimeException:

      Comment


      • #4
        No - I meant your RPG code. This is basically what you posted before.

        Scott showed an example of forming multi-part here: http://www.scottklement.com/archives.../msg00045.html

        It seems odd that you have what appear to be substitution markers in the JSON. e.g. "subject": "Result Process Eximp : ${requestId}", - Shouldn't they have been replaced by real values?

        Since d.testing.com is not accessible to me I can't really check anything.

        Comment


        • instrucrat1
          instrucrat1 commented
          Editing a comment
          Thank you JonBoy Sir. Below code I am using to post data and error is "RESTEASY007545: Unable to find a MessageBodyReader for media type"

          In my code I am creating parameters -

          l_payload =
          '{'+CRLF+'"requestId": "b2f3021d-b53b-4a75-9ff9-085e6b64d3c0",'
          +CRLF+ '"importOption": {'+CRLF+
          '"importType": "IMPORT_OV_CHG",' + CRLF +
          '"filename" : "TEAK.XML",' + CRLF +
          '"activateConflictFileGeneration" : true,' + CRLF +
          '"createWorkspace" : true,' + CRLF+
          '"importVersion": "WORKING"' + CRLF+
          '},' + CRLF+
          '"versionOption": { ' + CRLF+
          '"label": "TestAP_Version_992",'+ CRLF+
          '"date": 1607987212567",'+ CRLF+
          '"description": "Test AP Version 992"' + CRLF+
          '},' + CRLF+
          '"notifOption":{' + CRLF+
          '"notifEmail": {' + CRLF+
          '"smtpHost": "m.test.com",'+CRLF+
          '"from": "test@test.com",'+CRLF+
          '"to": ["test@gmail.com"],' + CRLF+
          '"subject": "Result Process Eximp : ${requestId}",'
          + CRLF+
          '"body": "Transaction ${requestId} : <br/> Started : ${startDate}, '+
          'Ended : ${endDate} <br/> Status: ${status}'+
          '<br/> ${errorMessage} <br/> Export slotid : ${exportSlotID}" '+ CRLF
          '},' + CRLF+
          '},' + CRLF+
          '}' + CRLF ;

          l_ContentLength = %size(%trim(l_payload));
          l_BodyPtr = %Addr(l_Payload);

          enc = http_mfd_encoder_open( tempFile : l_ContentType );
          if (enc = *NULL);
          msg = http_error();
          dsply msg;
          return;
          endif;

          http_setauth(HTTP_AUTH_BASIC :
          l_http_user :
          l_http_pass );

          tempFile = http_tempfile();
          enc = http_mfd_encoder_open( tempFile : l_ContentType );
          if (enc = *NULL);
          msg = http_error();
          dsply msg;
          return;
          endif;

          http_mfd_encoder_addvar( enc
          : 'options'
          : l_Bodyptr
          : l_ContentLength );
          http_mfd_encoder_addstmf( enc
          : 'importFile'
          : '/teak.xml'
          : 'application/octet-stream');

          http_mfd_encoder_close( enc );


          //
          // post the results to the web server
          //

          rc = http_url_post_stmf(l_URLAddress
          : tempFile
          : '/tmp/http_result.txt'
          : HTTP_TIMEOUT
          : HTTP_USERAGENT
          : l_ContentType );
          Last edited by instrucrat1; February 26, 2021, 07:30 AM.

      • #5
        This doesn't appear to be generated with HTTPAPI's MFD encoder. Are you creating the form yourself, manually?

        At the end there appears to be an extraneous part. You have the boundary string '----aROS', but no data after it. Prior to that, you have a part that has headers and no body.

        Comment


        • #6
          Thank you Sir. Yes I am creating form myself before calling API.
          I referred many online examples and created form.
          In body do I need to include file data?

          I have created webserices but never created with multiform.

          ----aROS
          Content-Disposition: form-data; name="importFile"; filename="/TEAK.XML "
          Content-Type: application/octet-stream

          Data should be file content?
          ----aROS -> Is this not required?

          Comment


          • #7
            Yes, of course. If you build it yourself, that means you have to do the work of putting your data into it.

            However, unless you have a good reason to build it yourself, I would strongly recommend using the routines that come with HTTPAPI. Why do it yourself??

            After the last part you need one last boundary, but it would look like this:
            Code:
            ----aROS--
            Notice the two trailing dashes, this indicates that it is NOT starting a new part, but rather ending the entire compound document.

            But, again... if you use the MFD encoder in HTTPAPI, you will not have to worry about any of this, it will automatically create the boundaries, the headers and insert the data. You are making it harder for yourself by doing it manually.

            Also, please consider using the newer routines in HTTPAPI instead of the old deprecated ones like http_url_post_raw()

            Comment


            • #8
              Thank you very much.
              I changed code to use MFD encoder (add variable and STMF) and using http_url_post_stmf to post data.
              Webservice is failing with another error ""RESTEASY007545: Unable to find a MessageBodyReader for media type"
              Below is debug log -
              If I add content type for form-data/options (application/json) then it fails with "PrivilegedActionException: com.fasterxml.jackson.databind.JsonMappingExceptio n: Unexpected character ('"' (code 34)):"

              POST /web/launch/ HTTP/1.1
              Host: d.test.com
              User-Agent: http-api/1.39
              Content-Type: multipart/form-data; boundary=-httpapi-2021-02-26-08.15.01.678
              Content-Length: 1527
              Authorization: Basic baiscaut
              Cookie: $Version=0; f5avraaaaaaaaaaaaaaaa_session_=CAJIIOCJGEFBBFOLLLN AJALFMCFEIPNAHOA

              sendraw(): entered
              ---httpapi-2021-02-26-07.58.29.591
              Content-Disposition: form-data; name="options"

              {
              "requestId": "b2f3021d-b53b-4a75-9ff9-085e6b64d3c0",
              "importOption": {
              "importType": "IMPORT_OVER_CHGS",
              "filename" : "TEAK.XML",
              "activateConflictFileGeneration" : true,
              "createWorkspace" : true,
              "importVersion": "WORKING"
              },
              "versionOption": {
              "label": "TestAP_Version_992",
              "date": 1607987212567",
              "description": "Test AP Version 992"
              },
              "notifOption":{
              "notifEmail": {
              "smtpHost": "m.test.com",
              "from": "test@das.com",
              "to": ["testing@gmail.com"],
              "subject": "Result Process Eximp : ${requestId}",
              "body": "Transaction ${requestId} : <br/> Started : ${startDate}, Ended : ${endDate} <br/> Status: ${status}<br/> ${errorMessage} <b
              },
              },
              }

              ---httpapi-2021-02-26-07.58.29.591
              Content-Disposition: form-data; name="importFile"; filename="/teak.xml"
              Content-Type: application/octet-stream

              <export xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
              <importExportMetadata workspaceName="wkcG">
              <exportDate>2020-12-01T15:55:34Z</exportDate>
              <exportType>FILTER</exportType>
              <version isWorking="true" versionDate="8099-12-31T23:59:59Z">
              <fixNumber>0</fixNumber>
              <versionDescr>Working version</versionDescr>
              <versionLabel>Working version</versionLabel>
              </version>
              </importExportMetadata>
              </export>

              ---httpapi-2021-02-26-07.58.29.591--

              Comment


              • #9
                I don't know your problem but I see places where you have extra or missing " marks. For example:

                "date": 1607987212567",

                this one is missing trailing " but could be a truncation of what was displayed. You haven't replaced with real values, not sure if the {} inside the body will cause issues or not.
                "body": "Transaction ${requestId} : <br/> Started : ${startDate}, Ended : ${endDate} <br/> Status: ${status}<br/> ${errorMessage} <b

                Comment


                • #10
                  Thank you very much for your help everyone. It is working now and using MFD encoder and post STMF got it working successfully

                  Comment


                  • #11
                    It sounds like the http_mfd_encoder_addvar routines would benefit from an additional parameter for content-type.

                    Comment


                    • #12
                      Yes Sir, that will help as I copied local variable to STMF and using STMF added MFD encoderSTMF to include content type

                      Comment


                      • #13
                        Okay, I have added an additional parameter to the http_mfd_encoder_addvar() and http_mfd_encoder_addvar_s() subprocedures that lets you specify the media type.

                        Please try it with the current "beta" version of HTTPAPI, found here:


                        The instructions for installing are the same as the "normal" version of HTTPAPI. Those instructions are here: http://www.scottklement.com/httpapi/

                        Please tell me how this works for you. If it works well, I will include it in future releases of HTTPAPI.

                        Comment

                        Working...
                        X