Announcement Announcement Module
Collapse
No announcement yet.
Spring integration with Query string Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring integration with Query string

    Hi,

    I want to develop a spring integration "GET" method which accept my user id as a query string like:
    http://localhost:8080/test/services/...vice?userId=12

    Can you let me know, how to proceed?

    I have done a POC on acception XML payload as input using JIBX marshaller / unmarshaller.

    Thanks

  • #2
    Hello

    Please, look into: https://github.com/SpringSource/spri...ter/basic/http

    Hope, this helps,
    Artem Bilan

    Comment


    • #3
      Thanks for the reply.

      I am able to pass the value as parameter to my service activator method. However, the payload that I received is of the type Map<String, List<String>>.
      Can it be possible to receive my payload as Map<String, String>, as for my requirement I will be having a particular string value for a key?
      Can you apply some kind of message-converter in my http:inbound-gateway which will perform the necessary transformation?

      Thanks

      Comment


      • #4
        As you see your payload after applying request is instance of org.springframework.util.MultiValueMap
        you can simply convert it to Map<String, String> as well as you want:
        HTML Code:
        <transformer expression="payload.toSingleValueMap()"/>
        But you said you have userId request parameter. So, you can convert it to the message's payload:
        HTML Code:
        <http:inbound-gateway payload-expression="T(Long).valueOf(#requestParams.userId)">
        Is it enough?

        Comment


        • #5
          Thanks. It solved my problem.

          Comment


          • #6
            I have a small problem, when I used
            payload-expression="T(String).valueOf(#requestParams.userI d)", it convert the LinkedList to a String. However the string contain this character [].

            Suppose if my user id is passed a 12. It will be converted to a payload and it value will be [12]. How can I get a simple string value?

            Comment


            • #7
              How can I get a simple string value?
              requestParams is also LinkedMultiValueMap<String, String>, so you can do this one:
              HTML Code:
              payload-expression="#requestParams.getFirst(userId)"
              Please, read JavaDoc of LinkedMultiValueMap.

              Comment

              Working...
              X