jaxb2, cxf: comment about how to implement custom SOAP Fault messages for validations
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 20 Dec 2015 21:24:14 +0000 (22:24 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 20 Dec 2015 21:24:14 +0000 (22:24 +0100)
Requires implementing our custom PayloadValidatingInterceptor class :(

cxf/web-services-spring-cxf-server/src/main/resources/spring-configuration/ws/soap-ws.xml
jaxb2/web-services-spring-jaxb2-server/src/main/resources/spring-configuration/ws/soap-ws.xml

index dba53c4..4fb7ccd 100644 (file)
         <property name="defaultFault" value="SERVER"/>
         <property name="exceptionMappings">
             <props>
+                               <!-- 
+                                       Los errores de validacion se devuelven así:
+                                       
+                                       <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
+                                          <env:Header/>
+                                          <env:Body>
+                                             <env:Fault>
+                                                <env:Code>
+                                                   <env:Value>env:Sender</env:Value>
+                                                </env:Code>
+                                                <env:Reason>
+                                                   <env:Text xml:lang="en">Validation error</env:Text>
+                                                </env:Reason>
+                                                <env:Detail>
+                                                   <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-maxLength-valid: El valor 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' con la longitud = '91' no es de faceta válida con respecto a maxLength '30' para el tipo 'limitedString'.</spring-ws:ValidationError>
+                                                   <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-type.3.1.3: El valor 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' del elemento 'exam:data' no es válido.</spring-ws:ValidationError>
+                                                </env:Detail>
+                                             </env:Fault>
+                                          </env:Body>
+                                       </env:Envelope>
+                                       
+                                       El manejador de errores de validación es implementado por AbstractFaultCreatingValidatingInterceptor (PayloadValidatingInterceptor)
+                                       luego si quisiéramos devolver un mensaje de error distinto al implementado por AbstractFaultCreatingValidatingInterceptor
+                                       tendríamos que crear nuestro propio PayloadValidatingInterceptor :(            
+                                -->
                        <prop key="de.spring.webservices.exceptions.CustomBusinessException">SERVER</prop>
                </props>
         </property>
index 601b57b..f1099f2 100644 (file)
         <property name="defaultFault" value="SERVER"/>
         <property name="exceptionMappings">
             <props>
-
+                               <!-- 
+                                       Los errores de validacion se devuelven así:
+                                       
+                                       <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
+                                          <env:Header/>
+                                          <env:Body>
+                                             <env:Fault>
+                                                <env:Code>
+                                                   <env:Value>env:Sender</env:Value>
+                                                </env:Code>
+                                                <env:Reason>
+                                                   <env:Text xml:lang="en">Validation error</env:Text>
+                                                </env:Reason>
+                                                <env:Detail>
+                                                   <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-maxLength-valid: El valor 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' con la longitud = '91' no es de faceta válida con respecto a maxLength '30' para el tipo 'limitedString'.</spring-ws:ValidationError>
+                                                   <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-type.3.1.3: El valor 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' del elemento 'exam:data' no es válido.</spring-ws:ValidationError>
+                                                </env:Detail>
+                                             </env:Fault>
+                                          </env:Body>
+                                       </env:Envelope>
+                                       
+                                       El manejador de errores de validación es implementado por AbstractFaultCreatingValidatingInterceptor (PayloadValidatingInterceptor)
+                                       luego si quisiéramos devolver un mensaje de error distinto al implementado por AbstractFaultCreatingValidatingInterceptor
+                                       tendríamos que crear nuestro propio PayloadValidatingInterceptor :(            
+                                -->
                        <prop key="de.spring.webservices.exceptions.CustomBusinessException">SERVER</prop>
                </props>
         </property>