You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Scott Nichol <sn...@scottnichol.com> on 2002/12/01 15:02:10 UTC

Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

To use the Apache SOAP serializers, you just need to set up the
parameters for marshall/unmarshall.  Some of these are simple, such as
the Java class and XML element QName.  Some are less trivial, such as
the SOAPContext, but these still are not so hard to put together.
Frankly, I think the BeanSerializer code is simple enough to figure most
of it out for yourself.

My question for you is, do you really need to use SOAP serialization?
If you just want to serialize Java object instances over your own
protocol, you should also consider something like Castor
(http://www.exolab.org/) or the JAXB beta
(http://java.sun.com/xml/downloads/jaxb.html).

Scott Nichol

----- Original Message -----
From: "Marco Schulze" <Ma...@NightLabs.com>
To: <so...@xml.apache.org>
Sent: Saturday, November 30, 2002 10:29 AM
Subject: Using the BeanSerializer directly to serialize & deserialize
over another protocol


> Hello!
>
> I just subscribed to the list, because I didn't find anything in the
web
> & archives. In case, I didn't search well enough, please don't flame
me,
> but send me a link where I can find more help.
>
>
> Here's my question:
>
> How can I directly use the Bean-Serializer to give him a java object
and
> receive an XML-String or better -Stream (and the other way around,
too)?
>
>
> Details:
>
> We're working on a system which should transfer java-objects via XML
> over our own protocol. We have to use our own protocol for several
> reasons. One of them is that http disconnects after each request and
we
> need a permanent connection. We want to use the Apache BeanSerializer
to
> automatically create XML out of java objects (and the other way
around)
> and transfer the xml over our protocol. Unfortunately, I didn't find
any
> detailed documentation or better helpful examples on how to directly
use
> the BeanSerializer without doing a soap-invoke over http.
>
>
> Please help!!!
>
> Thousand thanks in advance!
>
> Marco ;-)
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@xml.apache.org>
> For additional commands, e-mail:
<ma...@xml.apache.org>
>
>


Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

Posted by Marco Schulze <Ma...@NightLabs.com>.
Marco Schulze wrote:

>      xmlJavaMapReg.mapTypes(Constants.NS_URI_SOAP_ENC,
>        new QName("urn:xml-soap-testsoap", "transobj"),
>        config.getClass(), beanSerializer, beanSerializer
>      );
>
> //****** Do I really have to register each member object that I want to
> //****** transfer here??? Is there no way to use the beanSerializer for
> //****** ALL objects per default?
> //****** Otherwise I would have to recursively go through all the members
> //****** of my object. I really don't want to do this, because it takes
> //****** time to analyze the objects recursively, each time before I 
> send it.


Hi again,

I just saw that I made a mistake with cut'n'paste and I got a new 
question: What do I have to put in that QName? I copied it from a little 
test-project, that I made with real Apache-SOAP+TomCat. Is this just the 
name of the object?

I'm not yet a java-god, thus please excuse this question: How can I get 
the name of the object in java to put this automatically here (in case 
there is no way to avoid it)?

Thousand thanks for all your help!!!

Marco ;-)



Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

Posted by Marco Schulze <Ma...@NightLabs.com>.
Marco Schulze wrote:

>      xmlJavaMapReg.mapTypes(Constants.NS_URI_SOAP_ENC,
>        new QName("urn:xml-soap-testsoap", "transobj"),
>        config.getClass(), beanSerializer, beanSerializer
>      );
>
> //****** Do I really have to register each member object that I want to
> //****** transfer here??? Is there no way to use the beanSerializer for
> //****** ALL objects per default?
> //****** Otherwise I would have to recursively go through all the members
> //****** of my object. I really don't want to do this, because it takes
> //****** time to analyze the objects recursively, each time before I 
> send it.


Hi again,

I just saw that I made a mistake with cut'n'paste and I got a new 
question: What do I have to put in that QName? I copied it from a little 
test-project, that I made with real Apache-SOAP+TomCat. Is this just the 
name of the object?

I'm not yet a java-god, thus please excuse this question: How can I get 
the name of the object in java to put this automatically here (in case 
there is no way to avoid it)?

Thousand thanks for all your help!!!

Marco ;-)



Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

Posted by Marco Schulze <Ma...@NightLabs.com>.
Scott Nichol wrote:

>Your objective, as I understood it, was to serialize Java objects as XML
>over a proprietary protocol.  You have written the protocol already
>(right?), so all you want to do is serialize Java objects as XML.  Given
>technologies such as JAXB and Castor that were created to do exactly
>that, they seem like a better place to start and are likely to be more
>efficient and (hopefully) easier to use.
>
>Scott Nichol
>

Hello Scott and all others who may help me,

I took a look at Castor and it seams much more complex and harder to 
use. I think as we plan maybe to later offer web-service-functionality, 
we'll probably prefer SOAP (actually our protocol is flexible and we can 
add different serializing forms later).

Now, I really would like to get the Apache SOAP BeanSerializer running. 
You said, I would get the parameters together myself. Well, I think that 
I have to admit that I need a bit help:

I think, I start this way:

---------
      Config config = Config.getConfig();

      BeanSerializer beanSerializer = new BeanSerializer();
      XMLJavaMappingRegistry xmlJavaMapReg = new XMLJavaMappingRegistry();
      xmlJavaMapReg.setDefaultEncodingStyle(Constants.NS_URI_SOAP_ENC);

      xmlJavaMapReg.mapTypes(Constants.NS_URI_SOAP_ENC,
        new QName("urn:xml-soap-testsoap", "transobj"),
        config.getClass(), beanSerializer, beanSerializer
      );

//****** Do I really have to register each member object that I want to
//****** transfer here??? Is there no way to use the beanSerializer for
//****** ALL objects per default?
//****** Otherwise I would have to recursively go through all the members
//****** of my object. I really don't want to do this, because it takes
//****** time to analyze the objects recursively, each time before I 
send it.

      NSStack  nsStack = new NSStack();
//****** Can I use this object this way or do I have to prepare anything?

      SOAPContext soapContext = new SOAPContext();
//****** Can I use this object this way or do I have to prepare anything?

      FileWriter fileWriter = new FileWriter("testFile.xml");

      beanSerializer.marshall(
        Constants.NS_URI_SOAP_ENC,
        config.getClass(),
        config,
        context, //*** What is this???
        fileWriter,
        nsStack,
        xmlJavaMapReg,
        soapContext
      );

---------

I tried it once with context=config, but this created an empty XML file.

Help would be very appreciated!

Best regards, Marco ;-)




Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

Posted by Marco Schulze <Ma...@NightLabs.com>.
Scott Nichol wrote:

>Your objective, as I understood it, was to serialize Java objects as XML
>over a proprietary protocol.  You have written the protocol already
>(right?), so all you want to do is serialize Java objects as XML.  Given
>technologies such as JAXB and Castor that were created to do exactly
>that, they seem like a better place to start and are likely to be more
>efficient and (hopefully) easier to use.
>
>Scott Nichol
>

Hello Scott and all others who may help me,

I took a look at Castor and it seams much more complex and harder to 
use. I think as we plan maybe to later offer web-service-functionality, 
we'll probably prefer SOAP (actually our protocol is flexible and we can 
add different serializing forms later).

Now, I really would like to get the Apache SOAP BeanSerializer running. 
You said, I would get the parameters together myself. Well, I think that 
I have to admit that I need a bit help:

I think, I start this way:

---------
      Config config = Config.getConfig();

      BeanSerializer beanSerializer = new BeanSerializer();
      XMLJavaMappingRegistry xmlJavaMapReg = new XMLJavaMappingRegistry();
      xmlJavaMapReg.setDefaultEncodingStyle(Constants.NS_URI_SOAP_ENC);

      xmlJavaMapReg.mapTypes(Constants.NS_URI_SOAP_ENC,
        new QName("urn:xml-soap-testsoap", "transobj"),
        config.getClass(), beanSerializer, beanSerializer
      );

//****** Do I really have to register each member object that I want to
//****** transfer here??? Is there no way to use the beanSerializer for
//****** ALL objects per default?
//****** Otherwise I would have to recursively go through all the members
//****** of my object. I really don't want to do this, because it takes
//****** time to analyze the objects recursively, each time before I 
send it.

      NSStack  nsStack = new NSStack();
//****** Can I use this object this way or do I have to prepare anything?

      SOAPContext soapContext = new SOAPContext();
//****** Can I use this object this way or do I have to prepare anything?

      FileWriter fileWriter = new FileWriter("testFile.xml");

      beanSerializer.marshall(
        Constants.NS_URI_SOAP_ENC,
        config.getClass(),
        config,
        context, //*** What is this???
        fileWriter,
        nsStack,
        xmlJavaMapReg,
        soapContext
      );

---------

I tried it once with context=config, but this created an empty XML file.

Help would be very appreciated!

Best regards, Marco ;-)




Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

Posted by Scott Nichol <sn...@scottnichol.com>.
Your objective, as I understood it, was to serialize Java objects as XML
over a proprietary protocol.  You have written the protocol already
(right?), so all you want to do is serialize Java objects as XML.  Given
technologies such as JAXB and Castor that were created to do exactly
that, they seem like a better place to start and are likely to be more
efficient and (hopefully) easier to use.

Scott Nichol

----- Original Message -----
From: "Marco Schulze" <Ma...@NightLabs.com>
To: <so...@xml.apache.org>
Sent: Monday, December 02, 2002 10:33 PM
Subject: Re: Using the BeanSerializer directly to serialize &
deserialize over another protocol


> Dear Scott,
>
> thank you very much for your quick response! I will take a look at
> Castor and JAXB tomorrow or later this week (I'm very busy). Do you
have
> any special reason why you recommend to use another solution instead
of
> SOAP? Is it easier to use? Or is it more efficient?
>
> Best regards, Marco ;-)
>
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@xml.apache.org>
> For additional commands, e-mail:
<ma...@xml.apache.org>
>
>


Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

Posted by Scott Nichol <sn...@scottnichol.com>.
Your objective, as I understood it, was to serialize Java objects as XML
over a proprietary protocol.  You have written the protocol already
(right?), so all you want to do is serialize Java objects as XML.  Given
technologies such as JAXB and Castor that were created to do exactly
that, they seem like a better place to start and are likely to be more
efficient and (hopefully) easier to use.

Scott Nichol

----- Original Message -----
From: "Marco Schulze" <Ma...@NightLabs.com>
To: <so...@xml.apache.org>
Sent: Monday, December 02, 2002 10:33 PM
Subject: Re: Using the BeanSerializer directly to serialize &
deserialize over another protocol


> Dear Scott,
>
> thank you very much for your quick response! I will take a look at
> Castor and JAXB tomorrow or later this week (I'm very busy). Do you
have
> any special reason why you recommend to use another solution instead
of
> SOAP? Is it easier to use? Or is it more efficient?
>
> Best regards, Marco ;-)
>
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@xml.apache.org>
> For additional commands, e-mail:
<ma...@xml.apache.org>
>
>


Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

Posted by Marco Schulze <Ma...@NightLabs.com>.
Dear Scott,

thank you very much for your quick response! I will take a look at 
Castor and JAXB tomorrow or later this week (I'm very busy). Do you have 
any special reason why you recommend to use another solution instead of 
SOAP? Is it easier to use? Or is it more efficient?

Best regards, Marco ;-)





Re: Using the BeanSerializer directly to serialize & deserialize over another protocol

Posted by Marco Schulze <Ma...@NightLabs.com>.
Dear Scott,

thank you very much for your quick response! I will take a look at 
Castor and JAXB tomorrow or later this week (I'm very busy). Do you have 
any special reason why you recommend to use another solution instead of 
SOAP? Is it easier to use? Or is it more efficient?

Best regards, Marco ;-)