Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-5516

RestTemplate should encode the url variables

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 3.0 M2
    • Fix Version/s: 3.0 M2
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      The RestTemplate does not encode the url variables. The following line:

      template.postForLocation("http://twitter.com/statuses/update.xml?status={status}", "", "Ho Ho");
      

      Results in an exception:

      Exception in thread "main" java.lang.IllegalArgumentException
      	at java.net.URI.create(URI.java:842)
      	at org.springframework.web.util.UriTemplate.expand(UriTemplate.java:140)
      	at org.springframework.web.client.core.RestTemplate.execute(RestTemplate.java:266)
      	at org.springframework.web.client.core.RestTemplate.postForLocation(RestTemplate.java:203)
      	at test.RestClientTest.main(RestClientTest.java:30)
      Caused by: java.net.URISyntaxException: Illegal character in query at index 48: http://twitter.com/statuses/update.xml?status=Ho Ho
      	at java.net.URI$Parser.fail(URI.java:2809)
      	at java.net.URI$Parser.checkChars(URI.java:2982)
      	at java.net.URI$Parser.parseHierarchical(URI.java:3072)
      	at java.net.URI$Parser.parse(URI.java:3014)
      	at java.net.URI.<init>(URI.java:578)
      	at java.net.URI.create(URI.java:840)
      	... 4 more
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                arjen.poutsma Arjen Poutsma
                Reporter:
                tareq Tareq Abedrabbo
                Last updater:
                Rossen Stoyanchev
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  7 years, 31 weeks, 3 days ago