I'm trying to make some basic requests to some web services for the sake of learning how to manipulate data with XML and make requests to web services.
I've been able to get a few of them to work using the simplest protocols I could use, but there's still a lot that's tripping me up. I'm trying to use the Flickr API because it appears to be better documented than most of the other free webservices I found, and more importantly, it allows you to make requests via REST, xml-rpc, or
SOAP. So first I made a thing that called the "get related tags" method, just to verify that I was actually giving it the right parameters for tag, API Key, method name, etc...
And after some finagling it worked! That one was pretty simple to do, but I couldn't get it to do anything that required going through OAuth because I couldn't figure out how they wanted the queryString formatted. Like; you get a "base URL" which is described in different ways in multiple places, then you hash it to an MD5
String, and append it... Somewhere. In some format. I don't really know how you're supposed to append it. Trying to get it to do that was confusing as Hell because every time it failed (which was every time), I could never be sure what part I'd gotten wrong because there was no way to incrementally
test it. Did I generate the base URL wrong? Did I hash it to an MD5 String wrong? Was the way I appended it to the queryString wrong? When it said "all the attributes in alphabetical order by value in name-value pairs", are the 'names' in the name-value pairs exactly what they're supposed to be? I never did get it to work, but I did verify that I could call at least one method correctly with a RESTful request.
What I really need to learn how to do in the near future though, is learn how to send data as XML validated by a schema provided by a given web service. Specifically I need to be more familiar with marshalling and unmarshalling stuff and using JAXB bindings. So I'm trying to make the exact same request I made with REST now, but by sending an XML payload. I built a schema, handed it to a new JAXB binding in my project, and told it to generate the classes, and it worked! The classes look exactly like I wanted them to, and when I make an object and marshal it into a file, the file looks exactly like I'd expect, and the values are all the same values I put into the REST request that worked, but when it tries to marshal it into the outputStream pointing at the web service endpoint, I get this as a response:
I know the API key is right, so somehow I must be sending them XML formatted in a way which is unexpected. Also, interestingly, if I take out the API Key element entirely, it just moves on to the next element in the list and gives me the same message.
This is what the WADL looks like at the part where it describes the method I'm trying to call:
This is the XSD I made for the JAXB binding:
For what it's worth I realize the "Response" element is totally wrong, and I'm kind of ok with that for the moment because until I'm actually able to *get* a valid response, I can't really tell how exactly to build the object, and it isn't particularly important either. Right now I'm just writing the inputStream to the console so I can see if it's returning anything at all, or if so, what error it's returning. Here's the code I'm using to actually send the request:
I'm pretty sure the code here is right, but I can't really be 100% sure. I think there's something wrong with my XML, but I can't figure out how it should be structured in detail. The WADL tells you what parameters you need, what their names should be, and what types they should be, but I feel like I'm still missing something. And I'm actually not 100% certain I should even be using the WADL the way I am.
So I looked for something that would help me figure out how you're supposed to format XML requests to that particular web service, and I found this:
https://www.flickr.com/services/api/request.xmlrpc.html
But I'm not really sure how to use this information. Also I'm confused because that request format appears to conflict with what I'm seeing in the WADL, but since there doesn't appear to be a schema or WADL or WSDL or anything specifically describing *why* the sample request looks that way, I'm not sure how to put a request for the related tags method into the same format. I feel like I'm missing something pretty major here, but I really have no idea where to start looking.