jwagenleitner / groovy-wslite

Lightweight SOAP and REST webservice clients for Groovy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass xml string as xml

danvega opened this issue · comments

It is pretty easy to pass xml using the builder syntax like this

def client = new RESTClient("http://some.service.net/")
def response = client.post(path: "/comments") {
    xml {
        Comment {
            Text("This is my comment.")
        }
    }
}

But what if you already had an xml string. I would like to be able to do something like this. I have an xml string, how can I pass that in the body content. I would rather not use the text variable because I want a Grails Controller to automatically parse this for me.

def xmlString = """
<?xml version="1.0" encoding="UTF-8"?>
<people>
  <person>
    <firstName>Dan</firstName>
    <lastName>Vega</lastName>
  </person>
</people>
"""

def client = new RESTClient("http://some.service.net/")
def response = client.post(path: "/comments") {
    type ContentType.XML
    xml xmlString
}

I might be missing something but I have been unable to figure this one out.

The following should work

def client = new RESTClient("http://some.service.net/")
def response = client.post(path: "/comments") {
    type ContentType.XML
    text xmlString
}

Since xml expects markup builder syntax it wont work for posting a string, but text should work and since your specify the content type it should be received correctly as an xml payload.

Thank you so much! That worked.