jax-rs


Wildfly Swarm Bean Validation Custom constraint calls not


I'm trying to implement a REST Web Service using JAX-RS and Widlfly Swarm (2017.4.0 version) using JAX-RS Bean Validation.
Default bean validation annotations work as expected, but the custom constraints defined annotations seem to be ignored.
My (simplified) REST endpoint looks like that
#Path("/myservice")
#Produces({ MediaType.APPLICATION_JSON })
#Consumes({ MediaType.APPLICATION_JSON })
public class MyEndPoint {
#POST
#Path("/data")
public Response data(#CheckDate String date) {
return Response.ok().build();
}
}
The annotation for the validation constratint looks like
#Retention(RUNTIME)
#Target({ FIELD, PARAMETER })
#Constraint(validatedBy = CheckDateValidator.class)
public #interface CheckDate {
String message() default "Bad date format";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
The validator class "CheckDateValidator"
public class CheckDateValidator implements ConstraintValidator<CheckDate, String> {
public static final String dateFormat = "YYYYMMDD";
#Override
public void initialize(CheckDate constraintAnnotation) {
int i = 0;
}
#Override
public boolean isValid(String value, ConstraintValidatorContext context) {
return validate(value);
}
private boolean validate(String dateString) {
boolean valid = true;
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
sdf.setLenient(false);
try {
sdf.parse(dateString.trim());
} catch (ParseException e) {
valid = false;
}
return valid;
}
}
Replacing the #CheckDate annotation by #Email default validator
#Path("/myservice")
#Produces({ MediaType.APPLICATION_JSON })
#Consumes({ MediaType.APPLICATION_JSON })
public class MyEndPoint {
#POST
#Path("/data")
public Response data(#EmailString date) {
return Response.ok().build();
}
}
The e-mail format validation is applied but with my custom constraint #CheckDate no validation is applied.
I think I've added the needed Wildfly Swarm fractions dependencies in the POM file
<dependencies>
<!-- Java EE 7 dependency -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- WildFly Swarm Fractions -->
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jaxrs-jaxb</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>datasources</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${version.h2}</version>
</dependency>
<dependency>
<groupId>ParmaAlgorithmDatamodel</groupId>
<artifactId>ParmaAlgorithmDatamodel</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.systelabsw</groupId>
<artifactId>Connectors</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>swagger</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>swagger-webapp</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jaxrs-validator</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>bean-validation</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jaxrs-cdi</artifactId>
</dependency>
</dependencies>
I don't know if there is any extra configuration to be done or if I'm defining the custom constraint in a wrong way.
Any help would be appreciated

Related Links

how to see actual body sent from restassured
“IllegalStateException: No generator was provided” when using Jersey-Client on Glassfish 3 in Java EE 7 application
Is it possible to deploy a JAX-RS web service to MobileFirst Server?
wildfly how to get link to a deployment
What is the context of this `JaxrsModule`?
Reading from a JDBC Blob after leaving the Spring transaction
JAX-RS and #Produces ability to match on regex
How can I generate a swagger API specification from a JAX-RS (Jersey 2) application at build time?
How to post raw data using JAX-RS 2.0 client API
Get the JAX-RS application a resource is attached on
How to get HttpSession in a JAX-RS service method?
How to get RESTEasy to use system web proxy?
Is there a way to specify supported submit methods in swagger jaxrs doclet?
Can I use both the JAX-RS and RAML extensions in Restlet in the same application?
Not able to run maven + servlet 3.0 + jax-rs 2.0 application sucessfully
Can I use GET request instead of PUT to create resources?

Categories

HOME
android
embedded
fabricjs
jpa
webdriver
css3
pagination
ns-3
case
swt
solaris
jsf-2.2
owl-carousel
python-multithreading
vert.x
flume
computer-science
google-schemas
ibeacon-android
redis-sentinel
shared-libraries
boost-icl
sar
qliksense
monit
dapper-extensions
expressionengine3
fable-f#
motion-detection
amazon-quicksight
quantlib
errbot
sqlpackage
linkedhashmap
dsx-desktop
gojs
keras-layer
sendbird
reverse
least-squares
servicestack-text
xdocreport
ods
diacritics
news
mcustomscrollbar
visa
attributeerror
ssrs-2014
stylecop
pom.xml
netbeans6.8
zenhub
payara-micro
aquamacs
amq
wpas
yii2-user
truezip
libjpeg
django-1.10
bootstrap-tags-input
stripe-connect
angular2-testing
dotnetnuke-7
dimension
respondcms
appscale
angular-ui-typeahead
ikiwiki
uiactionsheet
fink
httpruntime.cache
mobiledoc-kit
directdraw
extjs-grid
amiga
ansi
infosphere-spl
delayed-execution
angular-gettext
human-computer-interface
rcaller
winginx
tinyxml
android-audiorecord
scrypt
jeromq
nebula
http-status-code-410
curb
panda3d
extreme-programming
screen-size
exponentiation
dataform
inline-formset
nhprof
cruisecontrol.rb
delimited-text
rowlex
ajax-polling
asynchronous-wcf-call
sqlobject

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile