Sagarmichael
Sagarmichael

Reputation: 1624

Not allowed in prolog grails XML error

I have the following on a Curl command:

curl -i -H "Content-Type: text/xml" -d '<sample:WIB xmlns:sample="www.sample.com"><sample:Customer><sample:Catalog_ID>01</sample:Catalog_ID><sample:Shop_ID>01</sample:Shop_ID></sample:Customer></sample:WIB>' http://localhost:8080/app/API/

My Grails controller is:

def index() {
    String xml = request.XML.toString();
    def workXml = new XmlSlurper().parseText(xml)
}

I get the error when parsing I have also tried this:

def workXml = new XmlSlurper().parseText(xml).declareNamespace(sample: 'sample')

I get the same error:

This is the stack trace:

Message: Content is not allowed in prolog.
Line | Method
->>   10 | index     in app.APIController$$EP3387M0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
|    198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|     53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread

Upvotes: 1

Views: 201

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122394

You're using the wrong option to curl - the -d option expects name=value pairs and treats them like a form post from a browser. If you want to send exactly the data given on the command line as-is you should use --data-binary instead.

As an aside, request.XML is already parsed - it's a GPathResult the same as you would get from XmlSlurper so there's no need to try converting it back to a string and slurping it again.

Upvotes: 3

Related Questions