I'm a newbie at this. I have an existing service and am trying to write a Java client to call my service. My service request is sent in the following format:
 
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<SOAP-ENV:Header>
<User>userid</User>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:updateComponent xmlns:ns1="urn:cca:ClientComponentManager"
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"        
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Transaction>
        <WorkstationID type="xsd:string">abcdefg123</WorkstationID>
        <OS version="4.0.950A">Windows 2000</OS>
        <Browser version="5.5.00">MSIE .5</Browser>
        <Contact>
            <EmailAddr>[EMAIL PROTECTED]</EmailAddr>
            <Telephone>(205) 555-1212</Telephone>
        </Contact>
        <Component id="ABCComponent" version="1.0.00">myComponent Name</Component>
    </Transaction>
</ns1:updateComponent>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
 
When I try to write a call to do this as a test I loaded my XML starting with the "Transaction" element into a w3c.dom.Document(). I then load the root element (Transaction) and use addElement(new Parameter()) to load my element into the Call. However, when I send my request my request has two Transaction Elements:

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<User>userid</User>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:updateComponent xmlns:ns1="urn:cca:ClientComponentManager" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Transaction SOAP-ENV:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
 <Transaction>

     <WorkstationID type="xsd:string">abcdefg123</WorkstationID>

    <OS version="4.0.950A">Windows 2000</OS>

    <Browser version="5.5.00">MSIE 5.5</Browser>

<Contact>

    <EmailAddr>[EMAIL PROTECTED]</EmailAddr>

    <Telephone>(334) 555-1212</Telephone>

</Contact>

<Component id="ABCComponent" version="1.0.00">myComponent Name</Component>

</Transaction>
</Transaction>
</ns1:updateComponent>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I also tried simply using the addElement(new Parameter()) command for each of the subelements under Transaction, but then the Transaction element gets duplicated like this:
    <Transaction>
        <WorkstationID type="xsd:string">abcdefg123</WorkstationID>
    </Transaction>
    <Transaction>
        <OS version="4.0.950A">Windows 2000</OS>
    </Transaction>
    <Transaction>
        <Browser version="5.5.00">MSIE .5</Browser>
    </Transaction>
    <Transaction>
        <Contact>
            <EmailAddr>[EMAIL PROTECTED]</EmailAddr>
            <Telephone>(205) 555-1212</Telephone>
        </Contact>
    </Transaction>
    <Transaction>
        <Component id="ABCComponent" version="1.0.00">myComponent Name</Component>
    </Transaction>
 
Here's how I call the service:
 
String myTrans = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Transaction><WorkstationID type=\"xsd:string\">abcdefg123</WorkstationID> <OS version=\"4.0.950A\">Windows 2000</OS><Browser version=\"5.5.00\">MSIE 5.5</Browser><Contact><EmailAddr>[EMAIL PROTECTED]</EmailAddr><Telephone>(205) 555-1212</Telephone></Contact><Component id=\"ABCComponent\" version=\"1.0.00\">myComponent Name</Component></Transaction>";

DocumentBuilder docBuilder = XMLParserUtils.getXMLDocBuilder();

myDocument = docBuilder.newDocument();

try {

 myDocument = XMLParserUtils.getXMLDocBuilder().parse(new java.io.ByteArrayInputStream(myTrans.toString().getBytes()));

} catch (java.io.IOException ex) {

    ccaLog.log("IO Exception caught" + ex.getMessage());

} catch (org.xml.sax.SAXException ex) {

    ccaLog.log("SAX Exception caught" + ex.getMessage());

}

String endpoint = "http://localhost:8080/cca/servlet/abcRouter";

URL url = "" color=#7f0055>null;

try {

url = "" color=#7f0055>new URL(endpoint);

} catch (java.net.MalformedURLException ex) {

sResponse = "MalformedURLException caught!";

return sResponse;

}

Call call = new Call();

call.setTargetObjectURI("urn:cca:ClientComponentManager");

call.setMethodName("updateComponent");

call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

Vector body = new Vector();

body.addElement (new Parameter("Transaction",Element.class,el, Constants.NS_URI_LITERAL_XML));

call.setParams(body);

try {

ccaLog.log("Sending call... ");

resp = call.invoke(url, "");

ccaLog.log("call complete!");

} catch (SOAPException e) {

sResponse = "Caught SOAPException (" +

e.getFaultCode() + "): " +

e.getMessage();

ccaLog.log(sResponse);

return sResponse;

}

// Check the response.

if (!resp.generatedFault()) {

Parameter ret = resp.getReturnValue();

Object value = ret.getValue();

if (value != null) {

if (value instanceof String) {

sResponse = value.toString();

}else {

sResponse = "I don't understand the type";

}

}else {

sResponse = "It's null";

}

} else {

Fault fault = resp.getFault();

sResponse = "Generated fault: " + fault;

}

 

How can I load a single Transaction element in my request with all the subelements?

 

Thanks,

 

Dave

Reply via email to