Skip to main content

JAX-WS and type substitution

Posted by kohlert on October 2, 2006 at 9:45 AM PDT

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.

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;

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:

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

@XmlSeeAlso({package1.ObjectFactory.class, package2.ObjectFactory.class})
public interface MyEndpoint {

Technorati: JSR JCP JAX JAXWS Web Services Glassfish

Related Topics >>


<p>Hey, thanks a lot for the tip, seems that i had a ...

Hey, thanks a lot for the tip, seems that i had a portable EAR running on this ploblem. In Glassfish 3.1 the app works perfectly but on WebSphere 7.0 only after that modification the app ran without problems.