Title: RE: message-style frustrations (this time in plain text)

Hi Volkmann,

 I can answer one question..  As I mentioned earlier you cannot embed an XML document within another XML document
 Since your SOAPMessage itself is a XML document, you cannot embed your document inside another XML document SOAPMessage (above mentioned reason).

 

  Again I am wondering why you need to call SetOperationName(""), because that doesn't make sense to me..

  Glad to hear that things are working fine now...

 

Cheers,

Ranjith

-----Original Message-----
From: Volkmann, Mark [mailto:[EMAIL PROTECTED]
Sent:
Monday, September 08, 2003 2:14 PM
To: '[EMAIL PROTECTED]'
Subject: RE: message-style frustrations (this time in plain text)

 

Based on the suggestions I've received, I now have a working example of passing a DOM Document to a service and getting one back in return.  I've included the code below (with comments and some whitespace removed) for those interested in the details.  I'm still wondering if this is the simplest possible way to do it.  See the comments in the code below for my remaining questions.  If this is the simplest approach then we certainly need documentation on some of the steps that I would have never guessed without help from this mailing list.

deploy.wsdd
-----------
<deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/"
  xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
  xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">

  <!-- either style="message" OR provider="java:MSG" will work -->
  <service name="MessageService" style="message">
    <parameter name="className" value="com.ociweb.axis.MessageService"/>
    <parameter name="allowedMethods" value="*"/>
  </service>
</deployment>

MessageService.java
-------------------

package com.ociweb.axis;
import org.w3c.dom.Document;
public class MessageService {
    public Document echoDocument(Document doc) throws Exception {
        return doc;
    }
}

MessageClient.java (This is the part that seems overly complicated!)
------------------

package com.ociweb.axis;

import java.net.URL;
import java.util.Vector;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class MessageClient {
    private String port;

    public static void main(String[] args) throws Exception {
        if (args.length != 1) {
            System.err.println("Usage: java MessageClient {port}");
            System.exit(1);
        }
        new MessageClient(args[0]);
    }

    private MessageClient(String port) throws Exception {
        this.port = port;
        Document doc = getDocument();
        System.out.println("sending " + XMLUtils.DocumentToString(doc));
        doc = passDocument(doc);
        System.out.println("received " + XMLUtils.DocumentToString(doc));
    }

    private Call getCall() throws Exception {
        Service  service = new Service();
        Call call = (Call) service.createCall();
        String endpoint =
            "http://localhost:" + port + "/axis/services/MessageService";
        call.setTargetEndpointAddress(new URL(endpoint));
        String operation = "echoDocument";
        // WHY IS THE NEXT LINE NECESSARY?
        call.setOperation(new QName(endpoint, operation), operation);
        return call;
    }

    private Document getDocument() throws ParserConfigurationException {
        DocumentBuilder builder =
            DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.newDocument();
        Element root = doc.createElement("family");
        doc.appendChild(root);
        Element child = doc.createElement("father");
        root.appendChild(child);
        child.appendChild(doc.createTextNode("Mark"));
        child = doc.createElement("mother");
        root.appendChild(child);
        child.appendChild(doc.createTextNode("Tami"));
        return doc;
    }

    private Document passDocument(Document doc) throws Exception {
        Call call = getCall();
        // WHY DO I HAVE TO PASS THE ROOT ELEMENT IN A SOAPBodyElement
        // INSTEAD OF JUST PASSING THE Document?
        // WHY DOES THE RESPONSE COME BACK AS A Vector?
        Vector result = (Vector) call.invoke
            (new Object[] {new SOAPBodyElement(doc.getDocumentElement())});
        // WHY IS THE OBJECT IN THE Vector A SOAPBodyElement INSTEAD OF A Document object?
        SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
        return sbe.getAsDocument();
    }
}



------------------------------------------------------------------------------------------
A.G. Edwards & Sons' outgoing and incoming e-mails are electronically
archived and subject to review and/or disclosure to someone other
than the recipient.

------------------------------------------------------------------------------------------

Reply via email to