Thilina,

Thanx for the reply. Attached is the modified and cleaned-up original code as well as the result of the Ant build/run. It still appears that all of the returned XML is being treated as a single string and does not break out correctly when parsed. I probably misread your instructions so feel free to correct. Ignore the Java warning since it is on an unrelated source file.

Thanx,
Garth

import org.apache.axiom.om.*;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import java.util.Iterator;
import javax.xml.stream.*;
import java.io.*;
 
public class Scenario1Client {
 
    public static void main(String[] args) throws Exception {
        ServiceClient client = new ServiceClient();
        // create option object
        Options opts = new Options();
        //setting target EPR
        opts.setTo(new EndpointReference("http://appsrv:8080/axis2/services/wsVendor"));
        //Setting action ,and which can be found from the wsdl of the service
        opts.setAction("urn:wsgetVendor");
        client.setOptions(opts);
        OMElement res = client.sendReceive(createPayLoad());
        Iterator children = res.getChildren();
        while (children.hasNext())
         {
             OMNode node = (OMNode) children.next();
            System.out.println(node.toString());
         }
 
    }
 
    public static OMElement createPayLoad() {
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace("http://ttna.com/xsd", "ns1");
        OMElement method = fac.createOMElement("wsgetVendor", omNs);
        OMElement value = fac.createOMElement("value", omNs);
        value.setText("hsv");
        method.addChild(value);
        return method;
    }
 
}

[EMAIL PROTECTED]:~/dev/MyService$ ant
Buildfile: build.xml

clean:

init:

compile:
    [javac] Compiling 6 source files to /home/garthk/dev/MyService/build/classes
    [javac] /home/garthk/dev/MyService/src/Scenario6Client.java:19: warning: unmappable character for encoding UTF8
    [javac]         //assigning message context�s option object into instance variable
    [javac]                                    ^
    [javac] 1 warning

compress:
      [jar] Building jar: /home/garthk/dev/MyService/build/bin/WSClient.jar

test1:
     [java] <ns:return xmlns:ns="http://ttna.com/xsd"><address1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" /><address2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" /><address3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" /><city1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" /><city2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" /><country xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" /><mailCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" /><region xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" /><rid xmlns="http://tier1.ttna.com/xsd">0</rid><userID xmlns="http://tier1.ttna.com/xsd">garthk</userID><vendorID xmlns="http://tier1.ttna.com/xsd">hsv             </vendorID><vendorName xmlns="http://tier1.ttna.com/xsd">Huntsville</vendorName></ns:return>

main:
     [echo]
     [echo]                     Building the project...
     [echo]

BUILD SUCCESSFUL
Total time: 2 seconds




Thilina Gunarathne wrote:
Hi Garth,
You should be able to do this with Axiom itself...
         opts.setAction("urn:wsgetVendor");
         client.setOptions(opts);
         OMElement res = client.sendReceive(createPayLoad());
You can use the "res" OMElement to access it's children...
Try adding the following to here..
         Iterator children = res.getChildren();
        while (children.hasNext())
         {
             OMNode node = (OMNode) children.next();
            System.out.println(node.toString());
         }

         XMLStreamReader reader = XMLInputFactory.newInstance()
                 .createXMLStreamReader(
                         new
ByteArrayInputStream(res.toString().getBytes()));
         StAXOMBuilder builder = new StAXOMBuilder(reader); // get the root
No need to do the above, since you already have a Axiom in place with
the web service response....

You can find some articles & tutorials about Axiom from here [1].

Thanks,
Thilina
[1] http://www.wso2.org/projects/axiom/java

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to