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 Peter <pe...@gmail.com> on 2005/07/28 20:16:25 UTC

New to webservices, code generation and work flow? (long)

Hi,

I am completely new to web services and have a few questions to get me
started on the right track. To give a little background, the project
involves integration between two enterprise systems (J2EE and .NET)
and corresponding databases. So both parties involved will be acting
in both a server & client role.

1. After playing around a bit it seems to me most logical to start
with a XSD to define my types and also define a schema for my messages
(is this common practice? I am not even sure messages themselves can
get validated or if it's a good idea). So for simplicity's sake I have
two XSDs: CommonTypes.xsd and Messages.xsd. Former contains various
complex and simple types (and possible elemens? see comments below)
such as AccountType and PersonType. The Messages.xsd imports
CommonTypes.xsd and contains elements for each message, for example
UpdateUserInformation element with elements Person and Account of
PersonType and AccountType respectively. I did this primarily to
generate sample messages to establish required and optional fields and
have a clearer picture of what is (not) exchanged.

2. Next I wrote a simple interface using mock/empty domain objects
(such as Account and Person) with a method
UpdateUserInformation(Account account, Person person). I did this to
generate a starting point WSDL. Next I started editing the generated
WSDL, my first goal is to remove the schema definition inside the WSDL
and import my external schemas directly to allow for a more modular
(and hopefully more maintainable) approach. I am trying to avoid each
side of the integration generating WSDL from domain objects and we end
up having to do domain object translation between each side's version
as apposed to starting from a common schema & WSDL and generating
domain objects.

3. ** Here my trouble started, I was able to easily enough include the
CommonTypes.xsd but how do I reference the nested elements inside my
Message schema (such as Person & Account above)? ** For now I had to
define them again in my WSDL, which I am trying to avoid, I want my
entire schema externalized.
My understanding is I need to reference these _elements_ (not types,
right?) in the <wsdl:message> section, specifcally in the <wsdl:part>
element.

4. So from here on, once I get the WSDL fixed, I aim to use WSDL2Java
to generate my domain objects, this will replace my interface and mock
domain objects. Is this correct? The other team can hopefully use
their .NET infrastructure and achieve the same thing using the common
schema & WSDL?

5. For additional benefit, is it possible and/or practical to validate
and message with some of the schemas above? Is this done implcitely?

In addition to the questions I am trying to solicit some comments
regarding my overall approach, obviously one needs to do this a few
times to get a firm grip on the best practices/best approach etc and I
hope to draw from the wide experience base here on the mailing list. I
have found very little information out there on the bigger picture
such as these questions.

Thank you,
Peter

Re: New to webservices, code generation and work flow? (long)

Posted by Anne Thomas Manes <at...@gmail.com>.
Peter,

Your approach is great. To answer your questions:

#3: Assuming that your Messages.xsd imports your CommonTypes.xsd, then
all you [should] need to do is import the Message.xsd schema into your
<wsdl:types> section. As long as you declare the namespace in the
<wsdl:definitions> root, and you import the Messgae.xsd namespace into
a schema in the <wsdl:types>, you can reference elements in the
Messages.xsd schema from the <wsdl:part> definitions.  e.g.,

<wsdl:definitions 
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
   xmlns:xs="http://www.w3.org/2001/XMLSchema" 
   xmlns:tns="this-namespace"
   xmlns:mns="messages-namespace"
   targetNamespace="this-namespace">
<wsdl:types>
   <xs:schema targetNamespace="this-namespace" >
      <xs:import namespace="messages-namespace 
            schemaLocation="messages.xsd"/>
   </xs:schema>
</wsdl:types>
<wsdl:message name="updateUserInformationRequest">
  <wsdl:part name="parameters" element="mns:updateUserInformation"/>
</wsdl:message>
...

Unfortunately, .NET has a little trouble dealing with imports, so you
may need to include your schemas inline in the WSDL <types> section.

#4: Correct (except that .NET has this schema import problem)

#5: True schema validation does not happen automatically -- for
example, if you have a string restriction defining a required
patttern, Axis won't automatically validate the string -- but Axis
does a certain amount of implicit validation as it converts XML into
Java. It will generate an error if it encounters unexpected data.

You can also configure the system to perform schema validation of
incoming and outgoing messages. You request validation using a handler
in the input and/or output messaging pipeline.

Schema validation can be a pretty expensive process, so you might want
to use it sparingly. You need to make the call whether your
application requires method validation.

Anne

On 7/28/05, Peter <pe...@gmail.com> wrote:
> Hi,
> 
> I am completely new to web services and have a few questions to get me
> started on the right track. To give a little background, the project
> involves integration between two enterprise systems (J2EE and .NET)
> and corresponding databases. So both parties involved will be acting
> in both a server & client role.
> 
> 1. After playing around a bit it seems to me most logical to start
> with a XSD to define my types and also define a schema for my messages
> (is this common practice? I am not even sure messages themselves can
> get validated or if it's a good idea). So for simplicity's sake I have
> two XSDs: CommonTypes.xsd and Messages.xsd. Former contains various
> complex and simple types (and possible elemens? see comments below)
> such as AccountType and PersonType. The Messages.xsd imports
> CommonTypes.xsd and contains elements for each message, for example
> UpdateUserInformation element with elements Person and Account of
> PersonType and AccountType respectively. I did this primarily to
> generate sample messages to establish required and optional fields and
> have a clearer picture of what is (not) exchanged.
> 
> 2. Next I wrote a simple interface using mock/empty domain objects
> (such as Account and Person) with a method
> UpdateUserInformation(Account account, Person person). I did this to
> generate a starting point WSDL. Next I started editing the generated
> WSDL, my first goal is to remove the schema definition inside the WSDL
> and import my external schemas directly to allow for a more modular
> (and hopefully more maintainable) approach. I am trying to avoid each
> side of the integration generating WSDL from domain objects and we end
> up having to do domain object translation between each side's version
> as apposed to starting from a common schema & WSDL and generating
> domain objects.
> 
> 3. ** Here my trouble started, I was able to easily enough include the
> CommonTypes.xsd but how do I reference the nested elements inside my
> Message schema (such as Person & Account above)? ** For now I had to
> define them again in my WSDL, which I am trying to avoid, I want my
> entire schema externalized.
> My understanding is I need to reference these _elements_ (not types,
> right?) in the <wsdl:message> section, specifcally in the <wsdl:part>
> element.
> 
> 4. So from here on, once I get the WSDL fixed, I aim to use WSDL2Java
> to generate my domain objects, this will replace my interface and mock
> domain objects. Is this correct? The other team can hopefully use
> their .NET infrastructure and achieve the same thing using the common
> schema & WSDL?
> 
> 5. For additional benefit, is it possible and/or practical to validate
> and message with some of the schemas above? Is this done implcitely?
> 
> In addition to the questions I am trying to solicit some comments
> regarding my overall approach, obviously one needs to do this a few
> times to get a firm grip on the best practices/best approach etc and I
> hope to draw from the wide experience base here on the mailing list. I
> have found very little information out there on the bigger picture
> such as these questions.
> 
> Thank you,
> Peter
>

Re: New to webservices, code generation and work flow? (long)

Posted by Peter <pe...@gmail.com>.
Jim,

You raise some excellent points here that I've thinking about:

> Yup - the thing to avoid is letting the generated WS object model leak into
> your server implementation.  You definitly want to put a conceptual boundary
> between your web services data marshaling layer and your internal
> implementation.  Imagine the problems you would have when you go to
> version/tweak the WSDL and generate a possibly breaking change or a
> namespace change that creates a new parallel set of objects.  After a few
> tweaks those generated objects can become a real pain.  If you are keeping
> your internal object model clean and separate and what you have is an object
> model to object model translation.  It very "easy" to do but it ain't that
> fun and you may weant to consider thunking to the XML request stream and
> parsing, mapping directly into your internal object model.  I'm one of the
> crazy people that think this is actually easier - especially with the latest
> XML pull parsers.  There is some interesting thinking popping up about handy
> tooling that layers ontop of XML that is not a statically mapped object
> model.

The generated domain objects from WSDL2Java are certainly not very
pretty, I think it's a bit of a shame, this polluting of the domain
objects, contrasting something like Hibernate that almost
transparently takes care of persisting beans. (This is another concern
down the road, persisting these generated domain objects with
something like Hibernate).

It seems at this stage going with an internal domain object to web
services domain object translation layer/bridge is the way to go. It
seems I will have to do this in anyways since the  .NET team insists
on generating wsdl/xsd from their domain objects (which results in all
kinds of funky names which I'll have to use as a result of the reverse
process with wsdl2java).

I am curious what others do....