java - Validate Pojo's in OSGi -
i validate anootated pojos (jsr 303) hibernatevalidator in osgi. unit tests works fine on osgi doesn't work.
here's validator method:
public static void validate(object o) throws validationexception { validatorfactory mill = validation.bydefaultprovider().providerresolver(new osgiservicediscoverer()).configure() .buildvalidatorfactory(); validator validator = factory.getvalidator(); set<constraintviolation<object>> validatorresult = null; if (o instanceof messagecontentslist) { messagecontentslist messagelist = (messagecontentslist) o; validatorresult = validator.validate(messagelist.get(0)); } else { validatorresult = validator.validate(o); } if (!validatorresult.isempty()) { stringbuffer sb = new stringbuffer(); (constraintviolation<object> v : validatorresult) { sb.append(v.getpropertypath() + " " + v.getmessage() + ", "); } string msg = sb.tostring().substring(0, sb.tostring().length() - 1); throw new validationexception(msg); } }
and here discoverer:
public class osgiservicediscoverer implements validationproviderresolver { @override public list<validationprovider<?>> getvalidationproviders() { list<validationprovider<?>> providers = new arraylist<validationprovider<?>>(1); providers.add(new hibernatevalidator()); homecoming providers; } }
in pom i've added next imports osgi:
javax.validation, javax.validation.bootstrap, javax.validation.constraints, javax.validation.spi, org.hibernate.validator,
has thought i'm doing wrong?
thx
i've found solution myself. reason was, annotated classes in seperate bundle validation , there haven't add together javax.validation dependencies. annotations ignored , validation has no functionality
java maven osgi
No comments:
Post a Comment