vendredi 27 février 2015

Validating SOAP messages at endpoints

I am trying to validate incoming SOAP messages annotated with XJsr303Annotations. Validation works when i apply this technique on Spring controllers, however i cannot make it work for endpoints. Here is my setup. There is a number of questions regarding this issue, but i haven't seen any with this approach.



@PayloadRoot(namespace = NAMESPACE_URI, localPart = SERVICE_NAME)
@ResponsePayload
public Response doStuff(@Valid @RequestPayload Request request) {

// doing something


Request is annotated with not null for mandatory parameters, and so on.


Exception handler for invalid requests:



@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public Response handleInvalidRequest(MethodArgumentNotValidException e) {
// return Respone


I have added following dependencies in pom file:



<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>

</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.1.Final</version>
</dependency>


plugin setup:



<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<id>generate-wsdl</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
<!-- <include>*.xsd</include> -->
</schemaIncludes>
<!-- <forceRegenerate>true</forceRegenerate> -->
<!-- <removeOldOutput>true</removeOldOutput> -->
<!-- <cleanPackageDirectories>true</cleanPackageDirectories> -->
<strict>true</strict>
<extension>true</extension>
<args>
<arg>-XJsr303Annotations</arg>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.3</version>
</plugin>
<plugin>
<groupId>com.github.krasa</groupId>
<artifactId>krasa-jaxb-tools</artifactId>
<version>1.1</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>


Shouldn't this also work for the SOAP messages, like it does for REST requests on the Controllers? When i send request with all mandatory parameters missing it isn't picked up by this exception handler.


Aucun commentaire:

Enregistrer un commentaire