[jdom-interest] Passing Element parameter in Jax-ws web method

Oliver Ruebenacker curoli at gmail.com
Sun Mar 18 04:19:16 PDT 2012


  Technically, you can work around by putting an Element into a
container (or extend it, as Rolf said), but you may want to consider
not passing an Element, but something simpler instead.

  De-serialization re-creates all fields, including non-public ones,
so the de-serialized Element should have a name if the original one

  A major problem with object serialization is class compatibility.
Compatibility requires that class definitions during serialization
agree with class definitions during de-serialization, including all
non-public members (except transient ones) and including all
dependencies (i.e. all classes needed to compile).

  This means if you have two Java processes communicate via
serialization, and one of them had a code change (e.g. an updated
library), this may break serialization, even if neither the classes
directly involved, nor any API, nor any specifications have changed.

  If you run a server and deploy a client on the web, users may have
cached versions of the client, and changes to the code may not
immediately propagate to the client, which may break server-client

  It is therefore advisable, that objects you want to serialize are as
simple and stable as possible and that dependencies are few and under
your control (i.e. you want to think twice before using some one
else's library).

  Element has a lot of dependencies (e.g. it depends on Document).

  If you want to transmit XML, it is probably best to simply write it
to a String and pass the String. After all, that's exactly what XML is
for. In fact, serialization in Java internally uses XML.

     Take care

On Sat, Mar 17, 2012 at 11:47 AM, Rolf Lear <jdom at tuis.net> wrote:
> Hi Dehaene
> Technically, the Element instance does have a no-arg constructor, only it is
> 'protected', not public.
> For you to solve your problem in the short term, you may want to do:
> class MyElement extends Element {
>  public MyElement() {
>    super();
>  }
> }
> Then you can make the method:
> public void hello(@WebParam(name = "xmlElement") MyElement element){
> I am not familiar enough with the  jax-ws to know whether this will help
> enough.... It will make the implementation a little messier, but, by
> default, JDOM doe s not let you create invalid Elements (which an Element
> without a name would be...).
> It is not likely possible to make the no-arg constructor public.
> Anothe roption is to create a serialized Element? Element serialization (at
> least in JDOM2) is reliable....
> Rolf
> On 17/03/2012 11:14 AM, Dehaene Thomas wrote:
>> Hello,
>> I have a problem when accepting a web parameter of the type Element. My
>> code is as follows:
>>     @WebMethod(operationName = "hello")
>>     public void hello(@WebParam(name = "xmlElement") Element element){
>>         String name = new String();
>>         name = element.getChild("FirstName").getValue();
>>     }
>> Which generates an error when I try to deploy the web service. Namely that
>> the Element class
>> does not have a no-arg constructor.
>> If this where a normal method, I would simply make it a 'public static
>> void' method,
>> but since WebMethods in Jax-ws can't be of the 'final' or 'static' type, I
>> can't seem to
>> accept an Element parameter.
>> Any suggestions how to solve this?
>> Many thanks and greetings
>> Thomas Dehaene
>> _______________________________________________
>> To control your jdom-interest membership:
>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com

Oliver Ruebenacker, Computational Cell Biologist
Virtual Cell (http://vcell.org)
SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)

More information about the jdom-interest mailing list