Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

Wednesday, April 11, 2018

Hibernate validator dependencies for unit testing

http://hibernate.org/validator/ home page of validation


at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath


I have this in my pom.xml

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<scope>provided</scope>
</dependency>





Apparently I should add this implementation

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


I do that, then I have :


java.lang.NoClassDefFoundError: javax/validation/ClockProvider
 at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:33)
 at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276)
 at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)

Caused by: java.lang.ClassNotFoundException: javax.validation.ClockProvider
 at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)





Then I add

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>test</scope>
</dependency>




and I get

Caused by: java.lang.ClassNotFoundException: javax.validation.ParameterNameProvider


Here they say you should remove the validation-api : https://stackoverflow.com/questions/24652753/java-lang-noclassdeffounderror-javax-validation-parameternameprovider


I do this:


<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<scope>test</scope>
</dependency>


now I get:



Caused by: javax.validation.ValidationException: HV000183: Unable to initialize 'javax.el.ExpressionFactory'. Check that you have the EL dependencies on the classpath, or use ParameterMessageInterpolator instead
 at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:123)
 at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.(ResourceBundleMessageInterpolator.java:47)
 at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:461)
 at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolatorConfiguredWithClassLoader(ConfigurationImpl.java:637)
 at org.hibernate.validator.internal.engine.ConfigurationImpl.getMessageInterpolator(ConfigurationImpl.java:388)
 at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.(ValidatorFactoryImpl.java:179)
 at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:38)
 at org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:355)
 at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:103)




So I add ( https://stackoverflow.com/questions/24386771/javax-validation-validationexception-hv000183-unable-to-load-javax-el-express )



<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.4</version>
<scope>test</scope>
</dependency>



and I get

java.lang.ClassNotFoundException: javax.el.ELManager


then I finally use

<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>


and it works!

once more, all you need is:

  <dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <scope>provided</scope>
  </dependency>

  <dependency>
    <groupId>org.hibernate.validator</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>6.0.7.Final</version>
    <scope>test</scope>
  </dependency>

  <dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>2.0.1.Final</version>
    <scope>test</scope>
  </dependency>

<dependency>
  <groupId>javax.el</groupId>
  <artifactId>javax.el-api</artifactId>
  <version>3.0.0</version>
    <scope>test</scope>
</dependency>

  <dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.el</artifactId>
    <version>2.2.4</version>
    <scope>test</scope>
  </dependency>
  















Sunday, December 4, 2011

nxsd:validation, nxsd:fieldValidation,

the question is risen here
https://forums.oracle.com/forums/thread.jspa?threadID=1054790

here the official doc

http://docs.oracle.com/cd/E15586_01/integration.1111/e10231/nfb.htm


Top-Level Validation -> nxsd:validation="true"

information about the line and column in the native stream where the error was encountered is not provided by top-level validation.


Field-Level Validation -> nxsd:fieldValidation="true"

only on inbound payloads

information about the exact line and character where the error was encountered is displayed.


So, what is the difference between

a) NOT using any validation at JCA level
b) using nxsd:validation="true" in the nXSD file
c) using nxsd:fieldValidation="true" in the nXSD file
d) using both nxsd:validation="true" and nxsd:fieldValidation="true" in the nXSD file

and submitting a file which has a correct structure but a validation error in a field.


In case a), the file passes the JCA adapter and is handed over to the Proxy Service

In case b), the file is rejected in the JCA adapter, with this message:



Error while translating inbound file : spaceattheend.dat
ORABPEL-11157

Error: translated xml document does not conform to xml schema.
error:Invalid text 'PAL ' in element: 'UOM'.
Please ensure that native data is correct. To turnoff result validation, unset flag nxsd:validation in nxsd

at oracle.tip.pc.services.translation.framework.XlatorHelper.validateDOMNode(XlatorHelper.java:701)
at oracle.tip.pc.services.translation.framework.XlatorHelper.validate(XlatorHelper.java:667)
at oracle.tip.pc.services.translation.xlators.nxsd.NXSDTranslatorImpl.translateFromNative(NXSDTranslatorImpl.java:612)
at oracle.tip.adapter.file.inbound.InboundTranslatorDelegate.xlate(InboundTranslatorDelegate.java:314)
at oracle.tip.adapter.file.inbound.InboundTranslatorDelegate.doXlate(InboundTranslatorDelegate.java:121)
at oracle.tip.adapter.file.inbound.ProcessorDelegate.doXlate(ProcessorDelegate.java:388)
at oracle.tip.adapter.file.inbound.ProcessorDelegate.process(ProcessorDelegate.java:174)
at oracle.tip.adapter.file.inbound.ProcessWork.run(ProcessWork.java:349)
at weblogic.work.ContextWrap.run(ContextWrap.java:41)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)



and


Sending message to Adapter Framework for rejection to user-configured rejection handlers : {
file=C:\in\spaceattheend.dat, Exception=ORABPEL-11157

Error: translated xml document does not conform to xml schema.
error:Invalid text 'PAL ' in element: 'UOM'.
Please ensure that native data is correct. To turnoff result validation, unset flag nxsd:validation in nxsd

}






in case c)

you get a similar message, but it shows also the line and column number




Sending message to Adapter Framework for rejection to user-configured rejection handlers : {
file=C:\in\spaceattheend.dat, Exception=ORABPEL-11156

Error: native data read does not conform to xsd type.
actual-value PAL is not valid for data type . Please check before Line=2, Col=1 in the native stream.
Please ensure that native data conforms to xsd type. To turnoff field validation, unset flag nxsd:fieldValidation in nxsd




in case d)

it's same as c)

Wednesday, November 9, 2011

OSB Validate action failed validation

The Exception logged is quite useless. You must examine the $fault in an error handler, to determine what went wrong:

<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
  <con:errorCode>BEA-382505</con:errorCode>
  <con:reason>OSB Validate action failed validation</con:reason>
  <con:details>
    <con1:ValidationFailureDetail xmlns:con1="http://www.bea.com/wli/sb/stages/transform/config">
      <con1:message>string length (4) is greater than maxLength facet (3) for UOMType in namespace http://acme.pippo.com/po</con1:message>
      <con1:xmlLocation>
        <po:UOM xmlns:po="http://acme.pippo.com/po">PAL</po:UOM>
      </con1:xmlLocation>
      <con1:message>string length (4) is greater than maxLength facet (3) for UOMType in namespace http://acme.pippo.com/po</con1:message>
      <con1:xmlLocation>
        <po:UOM xmlns:po="http://acme.pippo.com/po">PAL</po:UOM>
      </con1:xmlLocation>
    </con1:ValidationFailureDetail>
  </con:details>
  <con:location>
    <con:node>PPL_acme_PO_FFMW_FilePoller_file</con:node>
    <con:pipeline>PPL_acme_PO_FFMW_FilePoller_file_request</con:pipeline>
    <con:stage>Validation</con:stage>
    <con:path>request-pipeline</con:path>
  </con:location>
</con:fault>



For some funny reason, the error message and location are repeated twice.

Monday, December 27, 2010

XML validate that all elements have same value

I have a payload like this:


alfa>3
beta>3
gamma>3
delta>3




and I need to validate that all "number" are the same within the same element... can be 3, can be anything else.

Now, with Schematron I doubt this is possible. With XSD neither. They all seem to be NOT oriented to operate on collections, the validation scope is the single element.

We need to come up with a different strategy.

I wish there was a DSL allowing me to state:

test: assert all /lines/line/number are same within /lines
with message: 'all line number must be same'

where we establish a scope (/lines), a predicate (are same), a subject (/lines/line/number) and a selection rule (all)

Tuesday, November 23, 2010

XML Validation

When you define your Data Model, you better enforce as many restrictions as you can on your data.... too many times a request fails mysteriously because the input data fails to comply to business specifications, and the earlier you catch this - the better.

Here are the validations available in the XSD
http://www.w3schools.com/schema/schema_facets.asp


For more complex validation (like: is element E1 value is A, then element E2 can only be X or Z), you should use Schematron:

Here some links to Schematron

http://www.dpawson.co.uk/schematron/index.html
http://www.xfront.com/schematron/index.html
http://www.codeproject.com/KB/XML/schematron_started.aspx
http://www.docstoc.com/docs/2134799/Schematron-Editor-Tutorial

I am not aware of how much Schematron is supported in a Oracle "SOA Suite" project.... I shall investigate...