I am trying to send a POST request to a Restful WS with the request originally being xml and so is the response.
I need to have basic authentication sent as well. At first I was having issues with Classes not being defined and thankfully it took 6 jars to resolve that.
Now I keep getting the following: Caught: groovyx.net.http.HttpResponseException: Bad Request
Sounds like it doesn't like the POST request. I have tried different ways including RESTClient, I have tried to delegate the request in its raw xml format by passing a file or as a string var. I don't fully understand the difference between post or request methods in httpBuilder.
If anyone can help point me in what I did wrong would be very thankful
def http = new HTTPBuilder('http://some_IP:some_Port/')
http.auth.basic('userName','password')
http.post(path:'/path/ToServlet')
http.post(POST,XML)
{
delegate.contentType="text/xml"
delegate.headers['Content-Type']="text/xml"
//delegate.post(getClass().getResource("/query.xml"))
// body = getClass().getResource("/query.xml")
body =
{
mkp.xmlDeclaration()
Request{
Header{
Command('Retrieve')
EntityIdentifiers
{
Identifier(Value:'PhoneNumber', Type:'TelephoneNumber')
}
EntityName('Subscriber')
}
}
}
}
Now in case I translated the XML wrong in my request here is the XML version of it:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Provisioning xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Request> <Header> <Command>Retrieve</Command> <EntityIdentifiers> <Identifier Value="phoneNumber" Type="TelephoneNumber" /> </EntityIdentifiers> <EntityName>Subscriber</EntityName> </Header> </Request> </Provisioning>