eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.
Other
231 stars 72 forks source link

[BUG] ConstraintViolationException #412

Closed georgleber closed 1 year ago

georgleber commented 1 year ago

Which JNoSQL project the issue refers to?

JNoSQL (Core)

Bug description

Failing validations with the repository pattern are not mappable by the DefaultExceptionMapper of Resteasy, because the ConstraintValidationException is encapsulated in a UndeclaredThrowableException. Using the template it results correctly in the ConstraintValidationException.

Problem is that the InvocationHandler (f.e. AbstractDocumentRepositoryProxy) is not analyzing the exception and just rethrowing it.

16:34:51,325 ERROR [org.jboss.resteasy.core.providerfactory.DefaultExceptionMapper] (default task-1) RESTEASY002375: Error processing request POST /jakarta-nosql-bookstore/api/books - org.jnosql.example.infrastructure.rest.BookResource.add: java.lang.reflect.UndeclaredThrowableException
    at deployment.jakarta-nosql-bookstore.war/jdk.proxy19/jdk.proxy19.$Proxy78.save(Unknown Source)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:106)
    at deployment.jakarta-nosql-bookstore.war//org.jnosql.example.domain.BookRepository$948624726$Proxy$_$$_WeldClientProxy.save(Unknown Source)
    at deployment.jakarta-nosql-bookstore.war//org.jnosql.example.application.BookService.addBook(BookService.java:34)
    at deployment.jakarta-nosql-bookstore.war//org.jnosql.example.application.BookService$Proxy$_$$_WeldClientProxy.addBook(Unknown Source)
    at deployment.jakarta-nosql-bookstore.war//org.jnosql.example.infrastructure.rest.BookResource.add(BookResource.java:39)
    at deployment.jakarta-nosql-bookstore.war//org.jnosql.example.infrastructure.rest.BookResource$Proxy$_$$_WeldClientProxy.add(Unknown Source)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:154)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:118)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:560)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:452)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:413)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:321)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:415)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:378)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:356)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:70)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:429)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:240)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:154)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:321)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:157)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:229)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:222)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
    at org.jboss.resteasy.resteasy-core@6.2.4.Final//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at jakarta.servlet.api@6.0.0//jakarta.servlet.http.HttpServlet.service(HttpServlet.java:614)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.security.elytron-web.undertow-server@3.0.1.Final//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.lambda$handleRequest$1(ElytronRunAsHandler.java:68)
    at org.wildfly.security.elytron-base@2.1.0.Final//org.wildfly.security.auth.server.FlexibleIdentityAssociation.runAsFunctionEx(FlexibleIdentityAssociation.java:103)
    at org.wildfly.security.elytron-base@2.1.0.Final//org.wildfly.security.auth.server.Scoped.runAsFunctionEx(Scoped.java:161)
    at org.wildfly.security.elytron-base@2.1.0.Final//org.wildfly.security.auth.server.Scoped.runAs(Scoped.java:73)
    at org.wildfly.security.elytron-web.undertow-server@3.0.1.Final//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.handleRequest(ElytronRunAsHandler.java:67)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.core@2.3.6.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.core@2.3.6.Final//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.core@2.3.6.Final//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at org.wildfly.security.elytron-web.undertow-server-servlet@3.0.1.Final//org.wildfly.elytron.web.undertow.server.servlet.CleanUpHandler.handleRequest(CleanUpHandler.java:38)
    at io.undertow.core@2.3.6.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow@28.0.1.Final//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.core@2.3.6.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow@28.0.1.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
    at io.undertow.core@2.3.6.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:276)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:132)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at org.wildfly.extension.undertow@28.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
    at org.wildfly.extension.undertow@28.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
    at org.wildfly.extension.undertow@28.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
    at org.wildfly.extension.undertow@28.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1430)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:256)
    at io.undertow.servlet@2.3.6.Final//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:101)
    at io.undertow.core@2.3.6.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
    at io.undertow.core@2.3.6.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at org.jboss.xnio@3.8.9.Final//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
    at java.base/java.lang.Thread.run(Thread.java:1623)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.document.query.AbstractDocumentRepositoryProxy.invoke(AbstractDocumentRepositoryProxy.java:48)
    ... 74 more
Caused by: jakarta.validation.ConstraintViolationException: isbn: ISBN not valid (checksum is wrong)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.validation.MappingValidator.validate(MappingValidator.java:62)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.validation.MappingValidator$Proxy$_$$_WeldClientProxy.validate(Unknown Source)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.validation.EntityObserver.validate(EntityObserver.java:33)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:168)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286)
    at jakarta.enterprise.api//jakarta.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:142)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.util.Observers.notify(Observers.java:166)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273)
    at org.jboss.weld.core@5.1.0.Final//org.jboss.weld.event.EventImpl.fire(EventImpl.java:96)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.document.DocumentEventPersistManager.firePreEntity(DocumentEventPersistManager.java:46)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.document.DocumentEventPersistManager$Proxy$_$$_WeldClientProxy.firePreEntity(Unknown Source)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.document.AbstractDocumentTemplate.lambda$toUnary$9(AbstractDocumentTemplate.java:277)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.stream.Streams$StreamBuilderImpl.tryAdvance(Streams.java:397)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.document.AbstractDocumentTemplate.persist(AbstractDocumentTemplate.java:271)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.document.AbstractDocumentTemplate.insert(AbstractDocumentTemplate.java:82)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.document.DefaultDocumentTemplate$Proxy$_$$_WeldClientProxy.insert(Unknown Source)
    at deployment.jakarta-nosql-bookstore.war//org.eclipse.jnosql.mapping.document.query.AbstractDocumentRepository.save(AbstractDocumentRepository.java:56)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ... 76 more

JNoSQL Version

JNoSQL version 1.0.1-SNAPSHOT

Steps To Reproduce

  1. Build / Deploy war of bookstore module.
  2. curl --header "Content-Type: application/json" --request POST --data '{"isbn": "9x78-3-7657-2781-8","title": "Test","published": "2019-07-04T13:33:03.969Z","edition": "1","authors": [{"firstName": "Georg","lastName": "Leber","initials": "G."}]}' http://localhost:8080/jakarta-nosql-bookstore/api/books

Expected Results

Response Body: jakarta.validation.ConstraintViolationException: isbn: ISBN not valid (checksum is wrong)

Code example, screenshot, or link to a repository

Repository: https://github.com/georgleber/demo-ee Branch: bookstore

otaviojava commented 1 year ago

@dearrudam did you fix also at Graph, Key-value, and Column repository?

georgleber commented 1 year ago

@otaviojava I created a PR for this. Sorry doing it parallel here

otaviojava commented 1 year ago

That is nice @georgleber!

dearrudam commented 1 year ago

@georgleber @otaviojava, I'm sorry for putting my fingers on it ... I'll try to talk to you before doing anything next time...

otaviojava commented 1 year ago

Don't worry Max. Thank you for your help.

georgleber commented 1 year ago

@dearrudam I should have mentioned, that I am working on it. Hadn't enough time yesterday to solve the bug, but wanted to document it. Next time I will be more talkative 😄