Announcement Announcement Module
Collapse
No announcement yet.
Invoke remote Http Service with HttpRequestExecutingMessageHandler as form-data Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Invoke remote Http Service with HttpRequestExecutingMessageHandler as form-data

    Hi,

    I'm trying to invoke a remote Http Service with the HttpRequestExecutingMessageHandler (as an outbound-gateway and simple bean).
    This rest service will not simply required the payload to be post as the requestBody, but as a form-data among with other params. For instance I need to post something like this :

    text=The text which is the current payload (an expression value : payload)
    profile=basic (a static value)
    type=plain-text (a static value)

    Right now I'm only able to provide those value as uri variables (with uriVariableExpressions) but as the text param may be long and need to be encoded as a url, this is not the right solution.

    I guess (reading HttpRequestExecutingMessageHandler source code) I need to provide those values as a Map and setting the ContentType to multipart/form-data, but i'm not able to do this.

    What is the right way to achieve this ?

    Thanks for help,
    Stephane

  • #2
    Hello

    Maybe I missed something, but I'm doing it like this:
    HTML Code:
    <http:outbound-gateway http-method="POST"
    	url="http://..."
    	request-channel="requestChannel"
    	reply-channel="replyChannel">
    And I put into requestChannel the message with payload Map<String, String>.
    That's all!
    Please look at HttpRequestExecutingMessageHandler#resolveContentT ype

    Good luck,
    Artem Bilan

    Comment


    • #3
      Hello,

      Actually my problem is that I don't know how to pass from my current payload (a string which represents the content of a file) to a Map with the previous payload as en entry with the text key and other static entry.

      Any way, thank you for your quick answer.
      Stephane

      Comment


      • #4
        Parsing files with specific logic isn't a task of Srping Integration...
        However your sample looks like properties file.
        And you can simply load it into Properties object and that's all: voila - it's a Map<String, String>!

        Comment


        • #5
          Totally agree with the first part of you answer. But this is not what I attempt to do.

          To be more specific, say I have a file which contains text (it may be xml or plain text, it doesn't matter here) and this content is my current payload (I have other transformations and filters before this step).
          Now I need to request a service via http to perform Entities Detection (don't really matter what I'm doing here but it's to illustrate my need).

          So I need to call the service at a static uri : http://localhost:8888/my_service with post method
          And provide a 'text' and a 'profile' parameter. The 'text' value is simply my current payload, not something I need to parse with any specific logic.

          I don't now how to transform my current payload to an instance of Map<String,String> (without doing it in an obfuscated static manner as a bean service with a service activator).

          Comment


          • #6
            B-r-r.

            Sorry, I realy don't understand you...

            You have String payload and you need to transform it into Map<String, String> like this [profile, payload].
            But what's the problem to write simple transformer which applies payload as String and returns Map ?
            HTML Code:
            <transformer>
                      <groovy:script>
            		<![CDATA[
                                return [profile: payload]
                            ]]>
                      </groovy:script>
            </transformer>

            Comment


            • #7
              Yes, you've got it. It is exactly what I was looking for.
              I don't yet give a try to scripting transformer (only expression (SpEL) and XPath), but now I know how to build my needed Map.

              Many Thanks Artem

              Comment

              Working...
              X