title: How best to validate JAX-WS inputs?
body: <p>I'm currently writing a new set of web services using JAX-WS but I'm having difficulties deciding on the best way to validate the inputs. I can do some validation in my implementation classes but some input errors fail silently. For example character data in a numeric element will result in a null Integer in the JAXB object. </p>
  
  <p>These are the designs I've come across.</p>
  
  <ol>
  <li><p>@SchemaValidation<br>
  I could add this annotation to the endpoint class and JAX-WS will take care of the validation. This worked locally in tomcat but there are concerns that it won't work on some servers. My main gripe is that I have to surrender control of how the errors are output in the response.  </p></li>
  <li><p>All inputs as strings<br>
  I hate this approach but I've seen other web services where all inputs are defined as strings. This would catch the case of character data in a numeric element as I could check it where I call our API although you'd still miss any incorrectly named xml elements.</p></li>
  </ol>
  
  <p>I really want the errors to come back in the same manner as the API errors rather than as a soap fault. Any ideas? I've seen a few sites talking about intercepting the request with a kind of filter. Not sure how this would work with different responses for different operations though.</p>
  
  <p>E.G.</p>
  
  <pre><code>&lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;S:Body&gt;
        &lt;myOperationResponse&gt;
           &lt;return&gt;
              &lt;success&gt;false&lt;/success&gt;
              &lt;errors&gt;
                 &lt;error&gt;
                    &lt;code&gt;UNIQUECODE&lt;/code&gt;
                    &lt;message&gt;Message text&lt;/message&gt;
                 &lt;/error&gt;
              &lt;/errors&gt;
           &lt;/return&gt;
        &lt;/myOperationResponse&gt;
     &lt;/S:Body&gt;
  &lt;/S:Envelope&gt;
  </code></pre>
  
  <p>Maybe I'm asking too much but thought I'd see if I'd missed anything. TIA.</p>