You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Mark Hauchwitz <mh...@freightgate.com> on 2002/05/14 20:19:30 UTC

object types for autom. serialization

Hi!

Where can I find a documentation of data-/obejct- types axis' serializer can
handle?

Actually I am looking for a way to pass a complete parsed XML-Document from
a client to a web service through axis. It does not matter to me whether I
have to put it in an array first or whether I can pass it as DOM-Object
(dom.Document) as long as I can use the standard axis serializer/des. .

Any solutions?
Thanks in advance!!!
Mark.


RE: object types for autom. serialization

Posted by Andrew Vardeman <an...@iastate.edu>.
Hi Mark--

>If I extract the Document in my web service like
>
>SOAPBodyElement sbe = input[0];
>Element elem = sbe;
>NodeList list = elem.getElementsByTagName ("field");
>...
>
>it should work, right?

Actually, it's odd; on the server end, Axis gives you a java.util.Vector of 
DOM Elements rather than an array of SOAPBodyElements.  So, your service 
would be a class with a method like the following:

public Element[] process(Vector elems){
   //process stuff in here and return an array of DOM Elements
}

Expose this method via your .wsdd file (again, see the "message" service in 
the Axis examples), and when you send a request to the address of this 
service, the process() method (or whatever you name it) will get called.

>By the way, I am an german intern and in the US since march this year.
>Thanks for your support!

You're welcome.  I noticed, upon re-reading the paragraph below, that I 
sent you a very confusing sentence fragment.  I should learn to proofread.

Andrew

> >Mark,
> >
> >I suggest you do the following:
> >
> >parse the XML document.  Use the DOM Document.getDocumentElement() method
> >to get the document element of the document.  Create a SOAPBodyElement from
> >this DOM Element.  Invoke the service with an array containing only this
> >SOAPBodyElement.  On the wire, you can look at this SOAP Envelope and see
> >that your entire XML document, minus the xml declaration and any comments,
> >etc. you had outside the document's root element.  Assuming you can afford
> >to lose these things, it's easy to write a service that extracts the whole
> >DOM on the other end (again, see the axis message example).  Here is some
> >client code that I'm using to do the same thing:
> >
> >      // parse document into Document object parsedDoc
> >
> >      SOAPBodyElement[] input = new SOAPBodyElement[1];
> >
> >      Element bodyElement = parsedDoc.getDocumentElement();
> >      SOAPBodyElement sbe = new SOAPBodyElement(bodyElement);
> >      sbe.setNamespaceURI("");
> >      input[0] = sbe;
> >
> >      Vector          elems = (Vector) call.invoke( input );
> >
> >
> >Andrew




RE: object types for autom. serialization

Posted by Mark Hauchwitz <mh...@freightgate.com>.
Hi Andrew,

After Lunch I wrote the client this way now:

---------------
public class WebserviceClient extends DefaultHandler
{
    EmailLog _elog;
    String _actualValue = "";
    File xmlFile = new String("d:\\java\\ws\\testfile.xml");

    public static void main(String argv[]) {
      /*Parse the source XML File                               */
      /**********************************************************/
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder        db  = dbf.newDocumentBuilder();
      Document parsedDoc = db.parse (xmlFile);

      Service service = new Service();
      Call call = (Call)service.createCall();
      opts.setDefaultURL(
"http://localhost:8080/axis/servlet/AxisServlet" );

      /* Set all of the stuff that would normally come from WSDL */
      /***********************************************************/
      call.setTargetEndpointAddress( new URL(opts.getURL()) );
      call.setUseSOAPAction( true );
      call.setSOAPActionURI( "doWrite" );
      call.setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" );
      call.setOperationName( new QName("urn:webservice", "doWrite") );
      call.addParameter( "xmlDataBody", XMLType.XSD_STRING,
ParameterMode.IN );
      call.setReturnType( XMLType.XSD_BOOLEAN );

      /* Define some service specific properties */
      /*******************************************/
      call.setUsername( opts.getUser() );
      call.setPassword( opts.getPassword() );

      /* Invoke the service */
      /*************************************/
      SOAPBodyElement[] input = new SOAPBodyElement[1];
      Element bodyElement = parsedDoc.getDocumentElement();
      SOAPBodyElement sbe = new SOAPBodyElement(bodyElement);
      sbe.setNamespaceURI("");
      input[0] = sbe;

      boolean written = call.invoke( input );

      System.exit(0);
    }
}


If I extract the Document in my web service like

SOAPBodyElement sbe = input[0];
Element elem = sbe;
NodeList list = elem.getElementsByTagName ("field");
...

it should work, right?


By the way, I am an german intern and in the US since march this year.
Thanks for your support!

Mark.


>Mark,
>
>I suggest you do the following:
>
>parse the XML document.  Use the DOM Document.getDocumentElement() method
>to get the document element of the document.  Create a SOAPBodyElement from
>this DOM Element.  Invoke the service with an array containing only this
>SOAPBodyElement.  On the wire, you can look at this SOAP Envelope and see
>that your entire XML document, minus the xml declaration and any comments,
>etc. you had outside the document's root element.  Assuming you can afford
>to lose these things, it's easy to write a service that extracts the whole
>DOM on the other end (again, see the axis message example).  Here is some
>client code that I'm using to do the same thing:
>
>      // parse document into Document object parsedDoc
>
>      SOAPBodyElement[] input = new SOAPBodyElement[1];
>
>      Element bodyElement = parsedDoc.getDocumentElement();
>      SOAPBodyElement sbe = new SOAPBodyElement(bodyElement);
>      sbe.setNamespaceURI("");
>      input[0] = sbe;
>
>      Vector          elems = (Vector) call.invoke( input );
>
>
>Andrew



RE: object types for autom. serialization

Posted by Andrew Vardeman <an...@iastate.edu>.
I guess I have an easier time thinking about message-type services because 
I'm better with XML than with programming.  What's important to remember is 
that a SOAPEnvelope _is_ an XML document.  Everything that's being sent 
over the wire is XML.  The code I sent just lets you say explicitly what 
comes inside the SOAP:Body tags in a SOAPEnvelope.  So, the SOAPBodyElement 
is an Axis object that represents one sub-element of the SOAP:Body 
tag.  Say you invoke a call with two SOAPBodyElements, named bodyElement1 
and bodyElement2.  This is what it looks like on the wire:

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<bodyElement1>
   <thisCanBe/>
   <anyWell-Formed/>
   <XMLofYourChoosing/>
</bodyElement2>
<bodyElement1>
   <soCanThis/>
</bodyElement2>
</SOAP:Body>
</SOAP:Envelope>

by the way, your English is excellent.  Makes me embarrassed to know little 
more than how to order a lemonade in Spanish.

Andrew

At 12:26 PM 5/14/2002 -0700, you wrote:
>Andrew,
>
>So 'SOAPBodyElement' is an object type than can be passed through axis
>easily, right?
>I'll try to get it working.....
>
>Thanks a lot Andrew!
>Mark.
>
>  -----Original Message-----
>From:   Andrew Vardeman [mailto:andrewv@iastate.edu]
>Sent:   Tuesday, May 14, 2002 12:11 PM
>To:     axis-user@xml.apache.org
>Subject:        RE: object types for autom. serialization
>
>Mark,
>
>I suggest you do the following:
>
>parse the XML document.  Use the DOM Document.getDocumentElement() method
>to get the document element of the document.  Create a SOAPBodyElement from
>this DOM Element.  Invoke the service with an array containing only this
>SOAPBodyElement.  On the wire, you can look at this SOAP Envelope and see
>that your entire XML document, minus the xml declaration and any comments,
>etc. you had outside the document's root element.  Assuming you can afford
>to lose these things, it's easy to write a service that extracts the whole
>DOM on the other end (again, see the axis message example).  Here is some
>client code that I'm using to do the same thing:
>
>      // parse document into Document object parsedDoc
>
>      SOAPBodyElement[] input = new SOAPBodyElement[1];
>
>      Element bodyElement = parsedDoc.getDocumentElement();
>      SOAPBodyElement sbe = new SOAPBodyElement(bodyElement);
>      sbe.setNamespaceURI("");
>      input[0] = sbe;
>
>      Vector          elems = (Vector) call.invoke( input );
>
>
>Andrew




RE: object types for autom. serialization

Posted by Mark Hauchwitz <mh...@freightgate.com>.
Andrew,

So 'SOAPBodyElement' is an object type than can be passed through axis
easily, right?
I'll try to get it working.....

Thanks a lot Andrew!
Mark.

 -----Original Message-----
From: 	Andrew Vardeman [mailto:andrewv@iastate.edu]
Sent:	Tuesday, May 14, 2002 12:11 PM
To:	axis-user@xml.apache.org
Subject:	RE: object types for autom. serialization

Mark,

I suggest you do the following:

parse the XML document.  Use the DOM Document.getDocumentElement() method
to get the document element of the document.  Create a SOAPBodyElement from
this DOM Element.  Invoke the service with an array containing only this
SOAPBodyElement.  On the wire, you can look at this SOAP Envelope and see
that your entire XML document, minus the xml declaration and any comments,
etc. you had outside the document's root element.  Assuming you can afford
to lose these things, it's easy to write a service that extracts the whole
DOM on the other end (again, see the axis message example).  Here is some
client code that I'm using to do the same thing:

     // parse document into Document object parsedDoc

     SOAPBodyElement[] input = new SOAPBodyElement[1];

     Element bodyElement = parsedDoc.getDocumentElement();
     SOAPBodyElement sbe = new SOAPBodyElement(bodyElement);
     sbe.setNamespaceURI("");
     input[0] = sbe;

     Vector          elems = (Vector) call.invoke( input );


Andrew

At 11:57 AM 5/14/2002 -0700, you wrote:
>Andrew,
>
>I'd like to write a webservice that receives a complete XML File in a SOAP
>Body and writes it into a database.
>What possibilities do I have to do this?
>I thought about parsing the XML Document into a DOM-Object and give it to
>the axis serializer in the client....on the web service side I would get a
>DOM-Object from the axis deserializer, which I can use for databases'
>writing operations.
>
>My problem now is, that I only know how to use axis'
serializer/deserializer
>with String-objects, not with DOM-Objects (from class dom.Document).
>I don't want to create mappings or any additional stuff, I'd just like to
>use the standard object types from axis.
>
>Do you think that the only possibility is to pass the xml document as a
huge
>String?
>
>Thanks!!
>Mark.
>
>Ps sorry about my bad English....still learning :)
>
>
>
>  -----Original Message-----
>From:   Andrew Vardeman [mailto:andrewv@iastate.edu]
>Sent:   Tuesday, May 14, 2002 11:45 AM
>To:     axis-user@xml.apache.org
>Subject:        Re: object types for autom. serialization
>
>Mark,
>
>Do you have control of the client and the service?  It seems like the only
>part of a dom.Document you might want to pass that you couldn't pass
>literally is the <?xml version = "1.0"?> declaration, which would make the
>SOAP message invalid.  If this isn't a concern, why not just write a
>messaging client that sends the text representation of the whole DOM as the
>SOAPBody and extract the whole thing on the other end with a messaging
>service?
>
>Andrew
>
>At 11:19 AM 5/14/2002 -0700, you wrote:
> >Hi!
> >
> >Where can I find a documentation of data-/obejct- types axis' serializer
>can
> >handle?
> >
> >Actually I am looking for a way to pass a complete parsed XML-Document
from
> >a client to a web service through axis. It does not matter to me whether
I
> >have to put it in an array first or whether I can pass it as DOM-Object
> >(dom.Document) as long as I can use the standard axis serializer/des. .
> >
> >Any solutions?
> >Thanks in advance!!!
> >Mark.



RE: object types for autom. serialization

Posted by Andrew Vardeman <an...@iastate.edu>.
Mark,

I suggest you do the following:

parse the XML document.  Use the DOM Document.getDocumentElement() method 
to get the document element of the document.  Create a SOAPBodyElement from 
this DOM Element.  Invoke the service with an array containing only this 
SOAPBodyElement.  On the wire, you can look at this SOAP Envelope and see 
that your entire XML document, minus the xml declaration and any comments, 
etc. you had outside the document's root element.  Assuming you can afford 
to lose these things, it's easy to write a service that extracts the whole 
DOM on the other end (again, see the axis message example).  Here is some 
client code that I'm using to do the same thing:

     // parse document into Document object parsedDoc

     SOAPBodyElement[] input = new SOAPBodyElement[1];

     Element bodyElement = parsedDoc.getDocumentElement();
     SOAPBodyElement sbe = new SOAPBodyElement(bodyElement);
     sbe.setNamespaceURI("");
     input[0] = sbe;

     Vector          elems = (Vector) call.invoke( input );


Andrew

At 11:57 AM 5/14/2002 -0700, you wrote:
>Andrew,
>
>I'd like to write a webservice that receives a complete XML File in a SOAP
>Body and writes it into a database.
>What possibilities do I have to do this?
>I thought about parsing the XML Document into a DOM-Object and give it to
>the axis serializer in the client....on the web service side I would get a
>DOM-Object from the axis deserializer, which I can use for databases'
>writing operations.
>
>My problem now is, that I only know how to use axis' serializer/deserializer
>with String-objects, not with DOM-Objects (from class dom.Document).
>I don't want to create mappings or any additional stuff, I'd just like to
>use the standard object types from axis.
>
>Do you think that the only possibility is to pass the xml document as a huge
>String?
>
>Thanks!!
>Mark.
>
>Ps sorry about my bad English....still learning :)
>
>
>
>  -----Original Message-----
>From:   Andrew Vardeman [mailto:andrewv@iastate.edu]
>Sent:   Tuesday, May 14, 2002 11:45 AM
>To:     axis-user@xml.apache.org
>Subject:        Re: object types for autom. serialization
>
>Mark,
>
>Do you have control of the client and the service?  It seems like the only
>part of a dom.Document you might want to pass that you couldn't pass
>literally is the <?xml version = "1.0"?> declaration, which would make the
>SOAP message invalid.  If this isn't a concern, why not just write a
>messaging client that sends the text representation of the whole DOM as the
>SOAPBody and extract the whole thing on the other end with a messaging
>service?
>
>Andrew
>
>At 11:19 AM 5/14/2002 -0700, you wrote:
> >Hi!
> >
> >Where can I find a documentation of data-/obejct- types axis' serializer
>can
> >handle?
> >
> >Actually I am looking for a way to pass a complete parsed XML-Document from
> >a client to a web service through axis. It does not matter to me whether I
> >have to put it in an array first or whether I can pass it as DOM-Object
> >(dom.Document) as long as I can use the standard axis serializer/des. .
> >
> >Any solutions?
> >Thanks in advance!!!
> >Mark.




RE: object types for autom. serialization

Posted by Mark Hauchwitz <mh...@freightgate.com>.
Andrew,

I'd like to write a webservice that receives a complete XML File in a SOAP
Body and writes it into a database.
What possibilities do I have to do this?
I thought about parsing the XML Document into a DOM-Object and give it to
the axis serializer in the client....on the web service side I would get a
DOM-Object from the axis deserializer, which I can use for databases'
writing operations.

My problem now is, that I only know how to use axis' serializer/deserializer
with String-objects, not with DOM-Objects (from class dom.Document).
I don't want to create mappings or any additional stuff, I'd just like to
use the standard object types from axis.

Do you think that the only possibility is to pass the xml document as a huge
String?

Thanks!!
Mark.

Ps sorry about my bad English....still learning :)



 -----Original Message-----
From: 	Andrew Vardeman [mailto:andrewv@iastate.edu]
Sent:	Tuesday, May 14, 2002 11:45 AM
To:	axis-user@xml.apache.org
Subject:	Re: object types for autom. serialization

Mark,

Do you have control of the client and the service?  It seems like the only
part of a dom.Document you might want to pass that you couldn't pass
literally is the <?xml version = "1.0"?> declaration, which would make the
SOAP message invalid.  If this isn't a concern, why not just write a
messaging client that sends the text representation of the whole DOM as the
SOAPBody and extract the whole thing on the other end with a messaging
service?

Andrew

At 11:19 AM 5/14/2002 -0700, you wrote:
>Hi!
>
>Where can I find a documentation of data-/obejct- types axis' serializer
can
>handle?
>
>Actually I am looking for a way to pass a complete parsed XML-Document from
>a client to a web service through axis. It does not matter to me whether I
>have to put it in an array first or whether I can pass it as DOM-Object
>(dom.Document) as long as I can use the standard axis serializer/des. .
>
>Any solutions?
>Thanks in advance!!!
>Mark.



Re: object types for autom. serialization

Posted by Andrew Vardeman <an...@iastate.edu>.
Mark,

Do you have control of the client and the service?  It seems like the only 
part of a dom.Document you might want to pass that you couldn't pass 
literally is the <?xml version = "1.0"?> declaration, which would make the 
SOAP message invalid.  If this isn't a concern, why not just write a 
messaging client that sends the text representation of the whole DOM as the 
SOAPBody and extract the whole thing on the other end with a messaging service?

Andrew

At 11:19 AM 5/14/2002 -0700, you wrote:
>Hi!
>
>Where can I find a documentation of data-/obejct- types axis' serializer can
>handle?
>
>Actually I am looking for a way to pass a complete parsed XML-Document from
>a client to a web service through axis. It does not matter to me whether I
>have to put it in an array first or whether I can pass it as DOM-Object
>(dom.Document) as long as I can use the standard axis serializer/des. .
>
>Any solutions?
>Thanks in advance!!!
>Mark.