users@tyrus.java.net

WebSocket+EJB+BV integration bug?

From: Reza Rahman <Reza.Rahman_at_oracle.com>
Date: Thu, 08 Aug 2013 17:06:39 -0400

I have a pretty simple chat server that uses Bean Validation 1.1 to
validate an inbound WebSocket message like so:

     @OnMessage
     public void message(@Valid ChatMessage message) {

The validation part is working correctly (i.e. I can make the validation
fail). However, the part that I'm finding surprising is the fact that
when the validation fails, the websocket client does not receive an
error message? I just see the below error message on the console and the
@OnMessage processing is blocked (which is desirable). Is this correct?
Should it be fixed such that an error is sent back to the client when
validation fails (a la JAX-RS 2)? My code is attached in the zip.

WARNING: EJB5184:A system exception occurred during an invocation on
EJB ChatServer, method: public void
org.example.chat.server.ChatServer.message(org.example.chat.server.ChatMessage)
WARNING: javax.ejb.EJBException
     at
com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
     at
com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:698)
     at
com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503)
     at
com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4475)
     at
com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2009)
     at
com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1979)
     at
com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220)
     at
com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
     at com.sun.proxy.$Proxy305.message(Unknown Source)
     at
org.example.chat.server.__EJB31_Generated__ChatServer__Intf____Bean__.message(Unknown
Source)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:601)
     at
org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:396)
     at
org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:108)
     at
org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
     at
org.jboss.weld.bean.proxy.InjectionPointPropagatingEnterpriseTargetBeanInstance.invoke(InjectionPointPropagatingEnterpriseTargetBeanInstance.java:63)
     at
org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:101)
     at
org.example.chat.server.ChatServer$Proxy$_$$_Weld$EnterpriseProxy$.message(Unknown
Source)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:601)
     at
org.glassfish.tyrus.core.AnnotatedEndpoint.callMethod(AnnotatedEndpoint.java:431)
     at
org.glassfish.tyrus.core.AnnotatedEndpoint.access$100(AnnotatedEndpoint.java:83)
     at
org.glassfish.tyrus.core.AnnotatedEndpoint$WholeHandler$1.onMessage(AnnotatedEndpoint.java:518)
     at
org.glassfish.tyrus.core.SessionImpl.notifyMessageHandlers(SessionImpl.java:389)
     at
org.glassfish.tyrus.core.EndpointWrapper.onMessage(EndpointWrapper.java:495)
     at
org.glassfish.tyrus.server.TyrusEndpoint.onMessage(TyrusEndpoint.java:174)
     at
org.glassfish.tyrus.websockets.DefaultWebSocket.onMessage(DefaultWebSocket.java:156)
     at
org.glassfish.tyrus.websockets.frametypes.TextFrameType.respond(TextFrameType.java:66)
     at org.glassfish.tyrus.websockets.DataFrame.respond(DataFrame.java:102)
     at
org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler.onDataAvailable(TyrusHttpUpgradeHandler.java:113)
     at
org.apache.catalina.connector.InputBuffer$ReadHandlerImpl.processDataAvailable(InputBuffer.java:488)
     at
org.apache.catalina.connector.InputBuffer$ReadHandlerImpl.onDataAvailable(InputBuffer.java:453)
     at
org.glassfish.grizzly.http.io.InputBuffer.append(InputBuffer.java:855)
     at
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:222)
     at
org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
     at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
     at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
     at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
     at
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
     at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
     at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
     at
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
     at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
     at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
     at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
     at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
     at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
     at java.lang.Thread.run(Thread.java:722)
Caused by: javax.validation.ConstraintViolationException: 1 constraint
violation(s) occurred during method validation.
Constructor or Method: public void
org.example.chat.server.ChatServer.message(org.example.chat.server.ChatMessage)
Argument values: [org.example.chat.server.ChatMessage_at_3197e3fa]
Constraint violations:
  (1) Kind: PROPERTY
  message: size must be between 1 and 255
  root bean: org.example.chat.server.ChatServer_at_2eedd120
  property path: message.arg0.message
  constraint:
@javax.validation.constraints.Size(message={javax.validation.constraints.Size.message},
min=1, max=255, payload=[], groups=[])
     at
org.hibernate.validator.internal.cdi.interceptor.ValidationInterceptor.validateMethodInvocation(ValidationInterceptor.java:81)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:601)
     at
com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
     at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
     at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
     at
org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:601)
     at
com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
     at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
     at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
     at
com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
     at
com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:601)
     at
com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
     at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
     at
com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
     at
com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
     at
com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
     at
com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
     ... 45 more