The Source for Java Technology Collaboration
User: Password:



Doug Kohlert

Doug Kohlert's Blog

JAX-WS and type substitution

Posted by kohlert on October 02, 2006 at 09:45 AM | Comments (4)

Currently, JAX-WS does not support type substitution in cases where Java types are used at runtime that are not directly or indirectly referenced by the SEI. The reason for this is because you must specify all of the types that will be used at runtime at the time the JAXBContext is created. Since JAX-WS can only introspect the SEI there is no way to determine what other classes the developer may use at runtime. Take the following SEI for example.

@WebService
public interface MyEndpoint {
   public Shape echo(Shape);
}

abtract class Shape {}
but the following classes are also used by the application:
class Square extends Shape;
class Circle extends Shape;
In the current JAX-WS implementation only the Shape class can be used.

We have the same problem when starting from WSDL and schema; only the schema types referenced by the wsdl:Port will be visible to the JAX-WS runtime. In short, we need to solve two related problems:
  1. How can we allow the Java application developer to specify additional classes that should be used by a JAX-WS application?
  2. When importing a WSDL, how can we tell the JAX-WS and JAXB runtime that there are additional Java types available that are not referenced by the generated SEI?
JAX-WS 2.1 proposes the following solution: JAXB 2.1 has already defined the following @XmlSeeAlso annotation.
package javax.xml.bind.annotations;

@Target({ElementType.TYPE})
public @interface XmlSeeAlso {
 Class[] value();
}
This annotation will be allowed on any JAXB-bound type, and when JAXB binds that type, classes listed in @XmlSeeAlso will be also bound. So this can be used like this:
@XmlSeeAlso({Bar.class,Zot.class})
abstract class Foo {}

class Bar extends Foo {}
class Zot extends Foo {}
and "JAXBContext.newInstance(Foo.class)" will include all three classes. (Without @XmlSeeAlso annotation on Foo, JAXBContext.newInstance(Foo.class) will include only Foo.) JAX-WS 2.1 will allow developers to place this annotation on a SEI. JAX-WS will then read this annotation at runtime making sure to pass all of the classes referenced by this annotation to the JAXBContext.

When importing a WSDL that contains types that are not directly referenced by the endpoint definition, JAX-WS 2.1 will generate @XmlSeeAlso annotation on the SEI. This @XmlSeeAlso annotation will reference all of the ObjectFactories generated by JAXB. For example
@WebService
@XmlSeeAlso({package1.ObjectFactory.class, package2.ObjectFactory.class})
public interface MyEndpoint {
 ...
} 


Technorati: JSR JCP JAX JAXWS Web Services Glassfish

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • XmlSeeAlso is a pretty terrible idea if anyone were to ask me (and of course nobody has - lol). I'd rather see something more along the lines of XmlDerivedType, XmlSubstitution, XmlRootType or something that indicates what it's actually for.

    What might be better for clarity sake is to indicate which "substitution method" one is using be it choice, substition or abstract types...

    I can't post to your bug else I'd have posted this there...

    Posted by: dovholuk on October 10, 2006 at 07:56 AM

  • dovholuk: The @XmlSeeAlso annotation is not used just to solve the type substitution problem, it is also used for substitution groups. If you don't like the name of the annotation you should report it in the JAXB project or on the JAXB 2.0 and JAXWS 2.0 forum: http://forums.java.net/jive/forum.jspa?forumID=46

    Posted by: kohlert on October 10, 2006 at 12:10 PM

  • Is there any work around for this? I'm thinking a horrible hack to my XML schema might do the trick. Maybe adding some optional elements to the type to force JAXB to add the classes to it's context. I don't like the idea of messging up my schemas though, I'd rather add something to the JAXB customisations.

    Doug's Response:
    I believe JAX-WS 2.1 EA2 has the new @XmlSeeAlso implemented. You could use it. Http://jax-ws.dev.java.net.

    Posted by: paul_a_mitchell on October 30, 2006 at 09:12 AM

  • Using the 2.1 EA would be the ideal solution. Sadly we're not allowed to use EA releases in our production system. Any idea how long it will be until the EA goes FCS?

    Doug's Response:
    It will definately be FCS with Glassfish V2 scheduled for April 2007. It could possibly go FCS before that.

    Posted by: paul_a_mitchell on October 31, 2006 at 12:05 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds