reficio / soap-ws

Java library, based on Spring-WS, that enables handling SOAP on a purely XML level
297 stars 145 forks source link

Generate SOAP message example #14

Open briandignan opened 11 years ago

briandignan commented 11 years ago

If you have time, would you be able to add a little more explanation to the "Generate and post a SOAP message" portion of the manual? Here's the request that I generated from the example code:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:web="http://www.webserviceX.NET/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:ConversionRate>
         <web:FromCurrency>KHR</web:FromCurrency>
         <web:ToCurrency>MDL</web:ToCurrency>
      </web:ConversionRate>
   </soapenv:Body>
</soapenv:Envelope>
</code>

I have almost no experience with SOAP, so maybe this is obvious, but in this situation how do you specify the FromCurrency and ToCurrency values? It seems like KHR and MDL are picked every time, but I couldn't figure out why or how to change them.

Also, when running the example against http://www.webserviceX.NET/ConversionRate, TransmissionException was being thrown with a message "HTTP response=[Internal Server Error] code=[500]". Maybe there's something wrong with their site?

tombujok commented 11 years ago

Please, have a look at the examples: https://github.com/reficio/soap-ws/tree/master/soap-examples

Especially at this one: https://github.com/reficio/soap-ws/blob/master/soap-examples/quickstart/src/test/groovy/org/reficio/ws/quickstart/QuickStart.groovy

In order to tweak the message I use Groovy and XmlSlurper. In Java you would have to use XSLT or sth similar.

ghost commented 10 years ago

Actually, the examples in Java aren't really useful, because they don't show how to set the parameters of the various calls. I'm tempted to go direct and just post XML, but I'd rather use the builder if possible. Are you saying that in the end we have to manipulate the XML in the message directly, before posting the request?

tombujok commented 10 years ago

Yep, that's the case. You have to handle the string - thus I use XmlSlurper.

Tom

Tom Bujok Reficio™ - Reestablish your software! http://www.reficio.org

On Thursday, August 1, 2013 at 11:21 PM, mannyveloso wrote:

Actually, the examples in Java aren't really useful, because they don't show how to set the parameters of the various calls. I'm tempted to go direct and just post XML, but I'd rather use the builder if possible. Are you saying that in the end we have to manipulate the XML in the message directly, before posting the request?

— Reply to this email directly or view it on GitHub (https://github.com/reficio/soap-ws/issues/14#issuecomment-21970709).

pwilla commented 10 years ago

Sorry to ressurrect this, but I am also trying to get the example to work, and it generates the XML nicely, but I get the same 500 Internal Server Error. If I copy and paste the XML in SoapUI it gets a valid response.

pwilla commented 10 years ago

Just tested with the same service (CurrencyConverter), with the Soap12 binding and it worked from the project. Still doesn't work on Soap(11?) binding though.

chryschabs commented 9 years ago

Hi there, this project is really great, been using it for a little while especially for the SoapBuilder. I've got around modifying the contents of the XML using another library I favor for XML manipualtion (jdom). Small question/favor. Would it be possible to include the error message/failure reason when throwing back a TransmissionException (internal error 500) ? The additional details would prevent me from having to parse my log files for the actual cause of the error message. Thank you.

tmarly commented 9 years ago

(this issue is also related to issue #24)

In order to avoid XML manipulations (with java it's rather a pain in the a..) to change the message, a good solution would be to have tokens in the message (":var1:", ...) instead of fake content (or '?'), that we could replace later with a simple string seach / replace ...

I see that SoapContext has methods to change the content of the input parameters (SoapContext.exampleContent(boolean)), so that would be a good entry point.

cfalzone commented 9 years ago

+1 Having the ability to set the parameters in the request builder would be great.

I did for now something like:

            String request = builder.buildInputMessage(operation);

            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
                new InputSource(new ByteArrayInputStream(request.getBytes("utf-8"))));
            XPath xpath = XPathFactory.newInstance().newXPath();
            NodeList nodes = (NodeList)xpath.evaluate(
                "//Body/getAllPostedJobs/modifiedSinceDate", doc, XPathConstants.NODESET);
            for (int idx = 0; idx < nodes.getLength(); idx++) {
                nodes.item(idx).setTextContent(modifiedSinceDate.toString());
            }
            Transformer xformer = TransformerFactory.newInstance().newTransformer();
            StringWriter writer = new StringWriter();
            xformer.transform(new DOMSource(doc), new StreamResult(writer));
            request = writer.getBuffer().toString();

A lot to do to set one property on the call.