grails-plugins / grails-rest-client-builder

REST client plugin that uses Spring's RestTemplate
http://grails.org/plugin/rest-client-builder
Apache License 2.0
65 stars 32 forks source link

accept('application/xml' not used by resttemplate #17

Closed gpinkham closed 11 years ago

gpinkham commented 11 years ago

using the restbuilder like this:

def rest = new grails.plugins.rest.client.RestBuilder(connectTimeout:10000, readTimeout:20000)
def resp = rest.post("${baseUrl}/rest/v1/fooxml") {
  accept(MediaType.APPLICATION_XML.toString())
  header("u",'foo')
  header("p",'bar')
  body XMLDATA
 }

results in the following debug line:

DEBUG client.RestTemplate  - Setting request Accept header to [text/plain, application/json, */*]

so in turn I get a 406 from the Rest Service..

gpinkham commented 11 years ago

for the record I converted my code to use the RestTemplate directly.. even using that produces a request with the wrong accepts header and results in a 406..

    def accepts = new ArrayList()
    accepts.add(MediaType.APPLICATION_XML)
    headers.setAccept(accepts)
    headers.setContentType(MediaType.APPLICATION_XML)
    def rest = new RestTemplate()
    rest.setRequestFactory(new SimpleClientHttpRequestFactory(connectTimeout:10000, readTimeout:20000))
    def responseEntity = rest.exchange("${baseUrl}/rest/v1/fooxml",
        HttpMethod.POST,
        new HttpEntity(XMLDATA, headers),
        String, [:])
    def resp = new RestResponse(responseEntity: responseEntity)

debug message:

DEBUG client.RestTemplate  - Setting request Accept header to [text/plain, application/json, */*]

looks like I'll have to go old school.. wish I could sneak some ruby into this project. ha!

gpinkham commented 11 years ago

adding in an accept all (/) fixed the issue.. apparently the debug message must be wrong.. as it still says the same thing despite the request now working.. I will close this as it looks like an issue in the RestTemplate and not the plugin.. thanks

gourab-rout commented 7 years ago

Thanks for the solution, it really helped