Author: buildbot
Date: Tue Dec 3 13:48:41 2013
New Revision: 888933
Log:
Production update by buildbot for cxf
Modified:
websites/production/cxf/content/cache/docs.pageCache
websites/production/cxf/content/docs/validationfeature.html
Modified: websites/production/cxf/content/cache/docs.pageCache
==============================================================================
Binary files - no diff available.
Modified: websites/production/cxf/content/docs/validationfeature.html
==============================================================================
--- websites/production/cxf/content/docs/validationfeature.html (original)
+++ websites/production/cxf/content/docs/validationfeature.html Tue Dec 3
13:48:41 2013
@@ -33,6 +33,7 @@
<script src='/resources/highlighter/scripts/shCore.js'></script>
<script src='/resources/highlighter/scripts/shBrushJava.js'></script>
+<script src='/resources/highlighter/scripts/shBrushXml.js'></script>
<script>
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all();
@@ -132,15 +133,15 @@ Apache CXF -- ValidationFeature
<div id="ConfluenceContent"><p><span style="font-size:2em;font-weight:bold">
Bean Validation Feature </span></p>
<div>
-<ul><li><a shape="rect"
href="#ValidationFeature-Introduction">Introduction</a></li><li><a shape="rect"
href="#ValidationFeature-Dependencies">Dependencies</a></li><ul><li><a
shape="rect"
href="#ValidationFeature-UsingHibernateValidatorasbeanvalidationprovider">Using
Hibernate Validator as bean validation provider</a></li><li><a shape="rect"
href="#ValidationFeature-UsingApacheBValasbeanvalidationprovider">Using Apache
BVal as bean validation provider</a></li></ul><li><a shape="rect"
href="#ValidationFeature-CommonBeanValidation1.1Interceptors">Common Bean
Validation 1.1 Interceptors</a></li><li><a shape="rect"
href="#ValidationFeature-BeanValidation1.1andJAXRS2.0integration">Bean
Validation 1.1 and JAX-RS 2.0 integration</a></li><ul><li><a shape="rect"
href="#ValidationFeature-ConfiguringBeanValidation1.1usingJAXRSServerFactoryBean">Configuring
Bean Validation 1.1 using JAXRSServerFactoryBean</a></li><li><a shape="rect"
href="#ValidationFeature-ConfiguringBeanValidation1.1usingSpri
ngbeandefinitionsXML">Configuring Bean Validation 1.1 using Spring bean
definitions XML</a></li><li><a shape="rect"
href="#ValidationFeature-ValidationExceptionsandHTTPstatuscodes">Validation
Exceptions and HTTP status codes</a></li><li><a shape="rect"
href="#ValidationFeature-Examples">Examples</a></li><ul><li><a shape="rect"
href="#ValidationFeature-Validatingsimpleinputparameters">Validating simple
input parameters</a></li><li><a shape="rect"
href="#ValidationFeature-Validatingcomplexinputparameters">Validating complex
input parameters</a></li><li><a shape="rect"
href="#ValidationFeature-Validatingreturnvalues%28nonResponse%29">Validating
return values (non-Response)</a></li><li><a shape="rect"
href="#ValidationFeature-Validatingreturnvalues%28Response%29">Validating
return values (Response)</a></li></ul></ul></ul></div>
+<ul><li><a shape="rect"
href="#ValidationFeature-Introduction">Introduction</a></li><li><a shape="rect"
href="#ValidationFeature-Dependencies">Dependencies</a></li><ul><li><a
shape="rect"
href="#ValidationFeature-UsingHibernateValidatorasbeanvalidationprovider">Using
Hibernate Validator as bean validation provider</a></li><li><a shape="rect"
href="#ValidationFeature-UsingApacheBValasbeanvalidationprovider">Using Apache
BVal as bean validation provider</a></li></ul><li><a shape="rect"
href="#ValidationFeature-CommonBeanValidation1.1Interceptors">Common Bean
Validation 1.1 Interceptors</a></li><ul><li><a shape="rect"
href="#ValidationFeature-Configuration">Configuration</a></li></ul><li><a
shape="rect" href="#ValidationFeature-BeanValidation1.1andJAXRS2.0">Bean
Validation 1.1 and JAX-RS 2.0</a></li><ul><li><a shape="rect"
href="#ValidationFeature-ConfiguringBeanValidation1.1usingJAXRSServerFactoryBean">Configuring
Bean Validation 1.1 using JAXRSServerFactoryBean</a></li><li><a shape="
rect"
href="#ValidationFeature-ConfiguringBeanValidation1.1usingSpringbeandefinitionsXML">Configuring
Bean Validation 1.1 using Spring bean definitions XML</a></li><li><a
shape="rect"
href="#ValidationFeature-ValidationExceptionsandHTTPstatuscodes">Validation
Exceptions and HTTP status codes</a></li></ul><li><a shape="rect"
href="#ValidationFeature-Examples">Examples</a></li><ul><li><a shape="rect"
href="#ValidationFeature-Validatingsimpleinputparameters">Validating simple
input parameters</a></li><li><a shape="rect"
href="#ValidationFeature-Validatingcomplexinputparameters">Validating complex
input parameters</a></li><li><a shape="rect"
href="#ValidationFeature-Validatingreturnvalues%28nonResponse%29">Validating
return values (non-Response)</a></li><li><a shape="rect"
href="#ValidationFeature-Validatingreturnvalues%28Response%29">Validating
return values (Response)</a></li></ul><li><a shape="rect"
href="#ValidationFeature-BeanValidationandSchemaValidation">Bean Validation and
Schem
a Validation</a></li></ul></div>
<h1><a shape="rect" name="ValidationFeature-Introduction"></a>Introduction</h1>
-<p>Bean Validation 1.1 (JSR-349), an evolution of Bean Validation 1.0
(JSR-303), introduces a very powerful concepts of declarative constraints
(based on Java annotations) to define the expectation for:</p>
-<ul class="alternate" type="square"><li>properties of JavaBeans</li><li>method
/ contructor parameters</li><li>method return values</li></ul>
+<p>Bean Validation 1.1 (JSR-349), an evolution of Bean Validation 1.0
(JSR-303), introduces declarative constraints (based on Java annotations) to
define the expectations for:</p>
+<ul class="alternate" type="square"><li>properties of Java
Beans</li><li>method and constructor parameters</li><li>method return
values</li></ul>
-<p>Here are couple of typical examples:</p>
+<p>For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
public class Person {
@@ -155,53 +156,56 @@ public class Person {
]]></script>
</div></div>
-<p>Bean Validation API has been part of JPA 2.0 (JSR-317) and has proven to be
successful and very useful, helping developers to delegate routine validation
tasks to solid, very extensible framework. It is very easy to create own
constraints, including complex cross-field ones.</p>
+<p>Bean Validation API has been part of JPA 2.0 (JSR-317) and has proven to be
successful and very useful, helping developers to delegate routine validation
tasks to the solid, very extensible framework. It is very easy to create own
constraints, including complex cross-field ones.</p>
<h1><a shape="rect" name="ValidationFeature-Dependencies"></a>Dependencies</h1>
-<p>Bean Validation support in Apache CXF is implementation-independent and is
built solely using API. As such, the only required dependency is:</p>
-<div class="preformatted panel" style="border-width: 1px;"><div
class="preformattedContent panelContent">
-<pre><dependency>
+<p>Bean Validation support in Apache CXF is implementation-independent and is
built solely using Bean Validation API. The required dependencies are:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
+<script class="theme: Default; brush: xml; gutter: false"
type="syntaxhighlighter"><![CDATA[
+<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
-</pre>
+<dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>javax.el-api</artifactId>
+ <!-- use 3.0-b02 version for Java 6 -->
+ <version>3.0.0</version>
+</dependency>
+<dependency>
+ <groupId>org.glassfish</groupId>
+ <artifactId>javax.el</artifactId>
+ <!-- use 3.0-b01 version for Java 6 -->
+ <version>3.0.0/version>
+</dependency>
+]]></script>
</div></div>
-<p>API doesn't provide implementation but there are couple of choices to pick
from. Please notice that bean validation implementation is taken from the ones
present in classpath. If no implementation is detected, bean validation is not
available for use and constraints validation won't have any effect. </p>
+<p>A couple of API implementations is available. Please note that if no
implementation is detected on the runtime class-path then the constraints
validation won't have any effect. </p>
<h2><a shape="rect"
name="ValidationFeature-UsingHibernateValidatorasbeanvalidationprovider"></a>Using
Hibernate Validator as bean validation provider</h2>
<p><a shape="rect" class="external-link"
href="http://www.hibernate.org/subprojects/validator.html"
rel="nofollow">http://www.hibernate.org/subprojects/validator.html</a></p>
-<p>Hibernate Validator is mature and feature-rich validation provider with
full support of Bean Validation 1.1 (as of version 5.x.x which is the reference
implementation for JSR 349 - Bean Validation 1.1 API). To use Hibernate
Validator in your Apache CXF projects, couple of additional dependencies should
be included:</p>
+<p>Hibernate Validator is mature and feature-rich validation provider with
full support of Bean Validation 1.1 (as of version 5.x.x which is the reference
implementation for JSR 349 - Bean Validation 1.1 API). To use Hibernate
Validator in your Apache CXF projects add the following dependency:</p>
-<div class="preformatted panel" style="border-width: 1px;"><div
class="preformattedContent panelContent">
-<pre><dependency>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
+<script class="theme: Default; brush: xml; gutter: false"
type="syntaxhighlighter"><![CDATA[
+<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version>
</dependency>
-
-<dependency>
- <groupId>javax.el</groupId>
- <artifactId>javax.el-api</artifactId>
- <version>3.0-b02</version>
-</dependency>
-
-<dependency>
- <groupId>org.glassfish</groupId>
- <artifactId>javax.el</artifactId>
- <version>3.0-b01/version>
-</dependency>
-</pre>
+]]></script>
</div></div>
-<p>Hibernate Validator uses Java Expression Language 3.0 in order to provide
better validation messages support so the respective EL 3.0 API and
implementation dependencies should be included. </p>
+<p>Hibernate Validator uses Java Expression Language 3.0 in order to provide
better validation messages support. </p>
<h2><a shape="rect"
name="ValidationFeature-UsingApacheBValasbeanvalidationprovider"></a>Using
Apache BVal as bean validation provider</h2>
+
<p><a shape="rect" class="external-link"
href="http://bval.apache.org/">http://bval.apache.org/</a></p>
-<p>Current stable version of Apache BVal (0.5) doesn't support Bean Validation
1.1 but the upcoming 1.1.0 should have it fully implemented (at the moment
1.1.0-alpha-SNAPSHOT could be used).</p>
+<p>Current stable version of Apache BVal (0.5) doesn't support Bean Validation
1.1 but the upcoming 1.1.0 will have it fully implemented (at the moment
1.1.0-alpha-SNAPSHOT could be used).</p>
<div class="preformatted panel" style="border-width: 1px;"><div
class="preformattedContent panelContent">
<pre><dependency>
<groupId>org.apache.bval</groupId>
@@ -213,25 +217,112 @@ public class Person {
<h1><a shape="rect"
name="ValidationFeature-CommonBeanValidation1.1Interceptors"></a>Common Bean
Validation 1.1 Interceptors</h1>
-<p>Generic Bean Validation 1.1 implementation is build around two interceptors
and validation provider:</p>
-<ul class="alternate"
type="square"><li>org.apache.cxf.validation.BeanValidationInInterceptor:
validates every input message (request) arguments against validation
constraints, raises org.apache.cxf.validation.ConstraintViolationException if
any violations are
encountered</li><li>org.apache.cxf.validation.BeanValidationOutInterceptor:
validates every output message (response) arguments against validation
constraints, raises
org.apache.cxf.validation.ResponseConstraintViolationException if any
violations are
encountered</li><li>org.apache.cxf.validation.BeanValidationProvider: abstracts
away Bean Validation 1.1 implementation and provides useful utility
methods</li></ul>
+<p>JAX-RS and JAX-WS frontends can rely on the following common interceptors
to get Bean Validation done:</p>
+
+<ul class="alternate" type="square"><li><a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationInInterceptor.java">org.apache.cxf.validation.BeanValidationInInterceptor</a>:
validates every input message (request) arguments against validation
constraints, raises org.apache.cxf.validation.ConstraintViolationException if
any violations are encountered</li></ul>
+
+
+<ul class="alternate" type="square"><li><a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationOutInterceptor.java">org.apache.cxf.validation.BeanValidationOutInterceptor</a>:
validates every output message (response) arguments against validation
constraints, raises
org.apache.cxf.validation.ResponseConstraintViolationException if any
violations are encountered</li></ul>
+
+
+<p>Both interceptors depend on <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationProvider.java">org.apache.cxf.validation.BeanValidationProvider</a>
which abstracts away Bean Validation 1.1 API and provides useful utility
methods. This provider can be directly injected into the interceptors as a
'provider' property. Injecting the provider is optional, the interceptors will
create a default provider instance if it has not been injected. </p>
+<p>The provider can be initialized with javax.validation.ParameterNameProvider
or <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationConfiguration.java">ValidationConfiguration</a>
in order to customize the way Bean Validation 1.1 implementation does its
work.</p>
-<p>Feature-specific implementation for JAX-RS / JAX-WS is built on top of
these common blocks.</p>
+<p>Note that interceptors will only be effective if the current service object
is a singleton. They will make a best effort of getting hold of a reference to
the current service object, which can also be injected directly as a
'serviceObject' property.</p>
-<h1><a shape="rect"
name="ValidationFeature-BeanValidation1.1andJAXRS2.0integration"></a>Bean
Validation 1.1 and JAX-RS 2.0 integration</h1>
+<p>Custom interceptors can customize the default processing (for example, see
the section on Bean Validation 1.1 in JAX-RS 2.0). Typical customization is to
have one of the input parameters or the response value unwrapped before it can
be validated.</p>
-<p>Among many other features, JAX-RS 2.0 specification introduces Bean
Validation 1.1 support as a mandatory part of implementation. In an effort to
fulfill this requirement, Apache CXF provides full-fledge validation support
for JAX-RS / JAX-WS endpoints, both for request parameters and response
values.</p>
+<p><a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/core/src/main/java/org/apache/cxf/validation/BeanValidationFeature.java">org.apache.cxf.validation.BeanValidationFeature</a>
can be used to register both in and out validation interceptors.</p>
-<p>Bean Validation 1.1 support in JAX-RS 2.0 is built on top of three main
components:</p>
-<ul class="alternate" type="square"><li>in-interceptor
(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor): validates
REST/WS endpoint parameters before invoking the method</li><li>out-interceptor
(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor): validates
REST/WS endpoint return value after the method invocation</li><li>exception
mapper (org.apache.cxf.jaxrs.validation.ValidationExceptionMapper): transforms
any ValidationException to corresponding HTTP status code</li></ul>
+<h2><a shape="rect"
name="ValidationFeature-Configuration"></a>Configuration</h2>
+<p>The following snippets show how to get Bean Validation 1.1 interceptors
activated for both JAX-RS and JAX-WS services using Spring: </p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
+// Interface implemented by both JAX-RS and JAX-WS services:
+@WebService(targetNamespace = "http://bookworld.com")
+@Path("/")
+public interface BookWorld {
+
+ @POST
+ @Produces("text/xml")
+ @Consumes("text/xml")
+ @Valid
+ BookWithValidation echoBook(@Valid BookWithValidation book);
+
+}
+
+@WebService(endpointInterface =
"org.apache.cxf.systest.jaxrs.validation.spring.BookWorld",
+ serviceName = "BookWorld")
+public class BookWorldImpl implements BookWorld {
+
+ @Override
+ public BookWithValidation echoBook(BookWithValidation book) {
+ return book;
+ }
+}
+
+{code:java}
+
+
+{code:xml}
+<!-- JAX-RS and JAX-WS endpoints -->
+<jaxrs:server address="/bwrest">
+ <jaxrs:serviceBeans>
+ <ref bean="bookWorldValidation"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <ref bean="exceptionMapper"/>
+ </jaxrs:providers>
+ <jaxrs:features>
+ <ref bean="commonValidationFeature" />
+ </jaxrs:features>
+</jaxrs:server>
+
+<jaxws:endpoint xmlns:s="http://bookworld.com"
+ serviceName="s:BookWorld"
+ endpointName="s:BookWorldPort"
+ implementor="#bookWorldValidation"
+ address="/bwsoap">
+ <jaxws:features>
+ <ref bean="commonValidationFeature" />
+ </jaxws:features>
+</jaxws:endpoint>
+
+<bean id="bookWorldValidation"
class="org.apache.cxf.systest.jaxrs.validation.spring.BookWorldImpl"/>
+<bean id="commonValidationFeature"
class="org.apache.cxf.validation.BeanValidationFeature"/>
+]]></script>
+</div></div>
+
+<p>Check the next section for more examples specific to JAX-RS.</p>
+
+<h1><a shape="rect"
name="ValidationFeature-BeanValidation1.1andJAXRS2.0"></a>Bean Validation 1.1
and JAX-RS 2.0</h1>
+
+<p>JAX-RS 2.0 specification (Chapter 7) introduces an optional requirement to
get Bean Validation 1.1 supported.</p>
+
+<p>Using the common interceptors described in the previous section can be
sufficient for JAX-RS 2.0 resource methods having their input parameters and
response values validated. </p>
+
+<p>However, if you need a response values wrapped in JAX-RS Response validated
or make sure per-request service instances get validated then JAX-RS frontend
specific interceptors and the invoker need to be used: </p>
+
+<ul class="alternate"
type="square"><li>org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor:
validates JAX-RS resource method parameters. At the moment it is nearly
identical to the common BeanValidationInInterceptor which it extends. It can
also be used as a JAX-RS 2.0 ContainerRequestFilter</li></ul>
+
+
+<ul class="alternate"
type="square"><li>org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor:
validates JAX-RS resource method return values, unwraps JAX-RS Response. It
can also be used as a JAX-RS 2.0 ContainerResponseFilter</li></ul>
+
+
+<ul class="alternate"
type="square"><li>org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInvoker:
register it as a jaxrs:invoker if you need non-singleton service objects
validated.</li></ul>
+
+
+
+<p>Note the default JAX-RS ExceptionMapper
(org.apache.cxf.jaxrs.validation.ValidationExceptionMapper) which transforms
javax.validation.ValidationException to corresponding HTTP status code has to
be registered. Users can register the custom mappers if preferred.</p>
+
+<p>org.apache.cxf.jaxrs.validation.JAXRSParameterNameProvider can be
registered directly with the common BeanValidationProvider to get the error
messages customized.</p>
-<p>All these components may share the single instance of
org.apache.cxf.validation.BeanValidationProvider which actually delegates all
validation logic to available Bean Validation 1.1 implementation.</p>
<h2><a shape="rect"
name="ValidationFeature-ConfiguringBeanValidation1.1usingJAXRSServerFactoryBean"></a>Configuring
Bean Validation 1.1 using JAXRSServerFactoryBean</h2>
-<p>It's quite easy to enable bean validation support using
JAXRSServerFactoryBean as following code snippet shows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
@@ -283,13 +374,13 @@ sf.create();
<h2><a shape="rect"
name="ValidationFeature-ValidationExceptionsandHTTPstatuscodes"></a>Validation
Exceptions and HTTP status codes</h2>
<p>As per JAX-RS 2.0 specification, any input parameter validation violation
is mapped to HTTP status code 400 Bad Request and any return value validation
violation (or internal validation violation) is mapped to HTTP status code 500
Internal Server Error. This is essentially what
org.apache.cxf.jaxrs.validation.ValidationExceptionMapper does.</p>
-<div class="panelMacro"><table class="noteMacro"><colgroup span="1"><col
span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1"
valign="top"><img align="middle"
src="https://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif"
width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">At
the moment, the details of validation exceptions are not included into the
response. The reason why is that error reporting logic is application-specific
and may vary from application to application (f.e. it could be simple
'text/html' with error message, or 'application/json', or HTTP custom headers,
...). Application developers are encouraged to provide own implementation of
this particular functionality.</td></tr></table></div>
+<div class="panelMacro"><table class="noteMacro"><colgroup span="1"><col
span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1"
valign="top"><img align="middle"
src="https://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif"
width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">The
details of validation exceptions are not currently included into the response
but only logged. Application developers are encouraged to register custom
exception mappers if reporting the validation error details is
required.</td></tr></table></div>
-<h2><a shape="rect" name="ValidationFeature-Examples"></a>Examples</h2>
+<h1><a shape="rect" name="ValidationFeature-Examples"></a>Examples</h1>
-<p>You can use any predefined validation annotation as well as define your own
as far as it follows Bean Validation 1.1 specification. This section includes
couple of typical scenarios.</p>
+<p>The following examples show JAX-RS resource methods being validated but
predefined or custom Bean Validation 1.1 constraints can be applied to JAX-WS
service methods exactly the same way.</p>
-<h3><a shape="rect"
name="ValidationFeature-Validatingsimpleinputparameters"></a>Validating simple
input parameters</h3>
+<h2><a shape="rect"
name="ValidationFeature-Validatingsimpleinputparameters"></a>Validating simple
input parameters</h2>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
@@ -298,24 +389,26 @@ sf.create();
public Response addBook(
@NotNull @Pattern(regexp = "\\d+") @FormParam("id") String id,
@NotNull @Size(min = 1, max = 50) @FormParam("name") String name) {
- // ...
+ // do some work
+ return Response.created().build();
}
]]></script>
</div></div>
-<h3><a shape="rect"
name="ValidationFeature-Validatingcomplexinputparameters"></a>Validating
complex input parameters</h3>
+<h2><a shape="rect"
name="ValidationFeature-Validatingcomplexinputparameters"></a>Validating
complex input parameters</h2>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
@POST
@Path("/books")
public Response addBook( @Valid Book book ) {
- // ...
+ // do some work
+ return Response.created().build();
}
]]></script>
</div></div>
-<p>This example assumes that class Book has validation constraints defined,
f.e.:</p>
+<p>This example assumes that class Book has validation constraints defined:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
public class Book {
@@ -327,7 +420,7 @@ public class Book {
]]></script>
</div></div>
-<h3><a shape="rect"
name="ValidationFeature-Validatingreturnvalues%28nonResponse%29"></a>Validating
return values (non-Response)</h3>
+<h2><a shape="rect"
name="ValidationFeature-Validatingreturnvalues%28nonResponse%29"></a>Validating
return values (non-Response)</h2>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
@@ -336,16 +429,14 @@ public class Book {
@Override
@NotNull @Valid
public Book getBook(@PathParam("bookId") String id) {
- // ...
+ return new Book( id );
}
]]></script>
</div></div>
<p>This example assumes that class Book has validation constraints defined (as
in example above).</p>
-<h3><a shape="rect"
name="ValidationFeature-Validatingreturnvalues%28Response%29"></a>Validating
return values (Response)</h3>
-
-<p>Returning Response object stands aside from all other usage scenarios.
Usually, Response is a holder for another object (entity) but because Response
has no validation constraints defined, the inner object (entity) is not
validatable even if it has full set of validation constraints . Unfortunately,
this particular use case is not described in JAX-RS 2.0 specification.
Nevertheless, Apache CXF team thinks that such a validation would be beneficial
and performs a simple trick: whenever Response is being returned, all defined
for it validation constraints will be applied not to Response instance itself
but to the entity it holds.</p>
+<h2><a shape="rect"
name="ValidationFeature-Validatingreturnvalues%28Response%29"></a>Validating
return values (Response)</h2>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
@@ -356,7 +447,15 @@ public Response getBookResponse(@PathPar
return Response.ok( new Book( id ) ).build();
}
]]></script>
-</div></div></div>
+</div></div>
+
+<h1><a shape="rect"
name="ValidationFeature-BeanValidationandSchemaValidation"></a>Bean Validation
and Schema Validation</h1>
+
+<p>Web service developers often rely on the schema-based validation. </p>
+
+<p>Bean validation can be used as an alternative form of validation. </p>
+
+<p>However it can also complement the schema-based validation in cases where
the current schema is not very strict.</p></div>
</div>
<!-- Content -->
</td>