0

So I have this project where I consume an endpoint that creates a resource, and an access key for that resource is returned. The response xml I get on Soap UI looks like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <InsertOrderResponse
            xmlns="service URL">
            <InsertOrderResult>
                <MessageId>0</MessageId>
                <TimeStamp>123456789</TimeStamp>
                <Result>
                    <orderId
                        xmlns="">12345-access-code-67890
                    </orderId>
                </Result>
            </InsertOrderResult>
        </InsertOrderResponse>
    </soap:Body>
</soap:Envelope>

I want to get that order ID, but that field doesn't appear in any of the cxf-generated classes, the lowest level defined in the classes is the Result class which contains a list of objects 'content'. In the debugger, I can see the field and value is present in the return (inside field 'firstChild')

However, there is no implemented method to extract that field.

I feel like this should be very easy, but I'm very noob and I can't see to find a way of doing this.

andrewJames
  • 19,570
  • 8
  • 19
  • 51
  • How are you generating the classes? maven plugin? soap-ui? – Pp88 Aug 22 '22 at 18:21
  • Please, take some time to read [how to ask](/help/how-to-ask) and [How to create a Minimal, Reproducible Example](/help/minimal-reproducible-example) – LMC Aug 22 '22 at 22:26
  • The field might be annotated as `@XmlElement(name="orderId") public String accessCode;` or similar – LMC Aug 22 '22 at 22:33
  • @Pp88 the classes were generated with cfx-codegen plugin for maven. – Mauricio Landos Aug 24 '22 at 15:11
  • @LMC I've tried searching for orderId in Intellij without success. the response i see defined in the operation definition only defines up to Result though, with the result being an xml type. ` int long xml ` – Mauricio Landos Aug 24 '22 at 15:15
  • If the element appears in xml instance it must be defined somewhere, may the problem is in the [code generation](https://cxf.apache.org/docs/wsdl-to-java.html) – LMC Aug 24 '22 at 15:19
  • Post the wsdl and the plug-in configuration if you can – Pp88 Aug 24 '22 at 15:28
  • I managed to solve my issue, the problem was that the lowest level field was of type XML, but I could not seem to find a way of parsing it since I couldn't serialize it, or cast it to another object. The type of Result for me was com.sun.org.apache.xerces.internal.dom.elementnsimpl, but somehow it was impossible to cast it to that object, and from what I understood is a bug in recent java versions. The solution was simply casting it to `org.w3c.dom.Element` like said in [here](https://stackoverflow.com/a/56203831/19816674) and then I could navigate to the data. Thanks for your time – Mauricio Landos Aug 25 '22 at 02:20

0 Answers0