This week's giveaway is in the Cloud/Virtualization forum. We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line! See this thread for details.
Hi, my problem is as follows (I'll try to word the question as best i can but im new to webservices so be gentle):
I'm working with a webservice test tool that has already been implemented in .net and i've been asked to do the same in java. So, I used the existing wsdl files for the .net implementation and apache axis to generate the stubs / complex types needed. Now, the way this is supposed to work is that the user will load an xml file containing the information to be passed by the soap request, and then have it consumed and return the soap response. However, I have no idea how to send the request with the information stored in the xml. A sample call looks something like:
where each field is a class generated by axis from the wsdl. Now, when the values contained within these complex types are set explicitly using their respective 'set' functions, the service works fine. Is there a way I could use the xml to set those values before the service is invoked? Any help with this would be appreciated. I'm using IBM RAD and Axis 1.1(unfortunately)
Sorry if this explanation seems vague, but im new to this stuff and im a bit reluctant to post code because of company privacy etc.
Originally posted by Michael Hul: Now, when the values contained within these complex types are set explicitly using their respective 'set' functions, the service works fine.
What's the problem with that Michael?
Is there a way I could use the xml to set those values before the service is invoked?
Which xml? There is none the way you just described it, not until the service is called anyway.
That call you make, will do all the dirty work and the values in the xml payload will be set based on the values in the objects, not the other way around. I'm sure I misunderstand the question, so please try again.
ok let me try again. The idea is the user will be presented with an interface (JSP page) where they will choose the service they want to invoke from a list. Once they have chosen the service they will click a button that loads, for example, the following xml into a text area from a file:
They can then change the values as they wish before the service is to be consumed. I'm looking for a way that i can invoke the service with the java values set to the ones above(or any ones the user decides to change) because the request being sent currently looks like this:
I then get the following exception :
System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (8, 40). ---> System.InvalidOperationException: Instance validation error: '' is not a valid value for PaymentFrequencyType.
Through the help of breakpoints I noticed that when getPaymentFrequency() is called, it returns a value of 'null'. Is there something I'm missing? Is using explicit 'set' commands like:
the only way to set values for the request soap message?
Its very unusual for a user to edit xml on a jsp, as a user I would prefer to edit text fields which populate objects which in turn are marshalled to xml, as is the case with that web service call.
To answer your question, the values in a soap request can be set in a number of ways. Yes you can send xml, by way of the xsd type 'any' for example. Of course you can do something even crazier, and shove the entire xml into a string
Axis again has a few different binding options, default being ABD which the docs say doesn't support restrictions very well. I dunno if ADB has some generated code that creates an instance of your object using XML, it might but don't hold me to it. If not, you can use something like JIBX or whatever to go from the XML on your JSP, to the java object you're sending off to the service.
I obviously don't know your business requirements and why humans are editing xml files, but if possible I'd look at changing that first and working with objects and XSDs as far as possible.
You might also take a look at the XSD you generated that service from, it could be that PaymentFrequency is required with the use of minoccurs. [ October 24, 2008: Message edited by: Taariq San ]
ok so i decided to try a different route. I use the axis generated locator function and create an axis Call object. At this point i get the xml from the jsp textarea as a string and do this
The problem now is that for some services it works fine and when I invoke the call using the envelope I can get the same response as the existing .net implementation, But for some it doesn't work and it falls into that 'catch' block and throws a NullPointerException. I don't understand why the getSOAPEnvelope works for some of the XMLs but not for others. Any ideas?? Could it be something to do with the ByteArrayInputStream and the buffer size?
Nevermind. Problem solved. The services that didn't work had null values in the request xml files. I just wrote a few lines of code to remove lines from the xml containing the string "xsi:nil" and that appears to have fixed the problem.
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
SKIP - a book about connecting industrious people with elderly land owners