dev@jax-ws.java.net

Source location information in WSDLModel

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 09 Oct 2006 21:15:24 -0700

Today, the error handling of the JAX-WS RI is pretty poor. All too often
user errors result in NPEs and/or unhelpful WebServiceExceptions.

Just the other day, one of the Tango developers had a mistake in his
WSDL file, which resulted in NPE in the JAX-WS RI. Eventually he managed
to identify the problem by using the debugger and all, but the point is
that the lack of quality error messages is wasting people's time. It not
only waste users' time, but it also wastes *our* time, because they
either abandon the JAX-WS RI or they would ask us to trouble-shoot the
problem.

We cannot afford to waste our time on such things. We really need to be
serious about putting good error messages. Even when you are in hurry,
not writing error message might save you 1 minute now, but it will waste
an hour later. Such trade-off doesn't make any sense.



So, as the first step to improve this situation, I expanded WSDLModel to
provide source location information for all WSDL model objects. The
WSDLObject interface is the base interface for all interfaces defined in
the WSDL model, and this now exposes the locator which tells you where
the object was parsed from.

> public interface WSDLObject {
> /**
> * Gets the source location information in the parsed WSDL.
> *
> * This is useful when producing error messages.
> */
> @NotNull
> Locator getLocation();
> }

I also added com.sun.xml.ws.util.exception.LocatableWebServiceException,
so that the rest of the code can easily report errors with line information.

The following code illustrates how all of these can be put together into
one code:

> void freeze(WSDLModelImpl root) {
> boundPortType = root.getBinding(bindingName);
> if(boundPortType==null) {
> throw new LocatableWebServiceException(
> ClientMessages.UNDEFINED_BINDING(bindingName), getLocation());
> }
> }


Please also spend a few minutes to learn how to write messages in
property files and use the generated constant functions to format them.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com