cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: Automatic client-side beanvalidation?
Date Fri, 18 Nov 2016 19:53:09 GMT
Hi Johannes

It was nice to meet you too and thanks for supporting our talk.

As I promised to you before a talk I'll commit to adding the validation 
interceptor.

However lets keep the whole wadl-to-java, Swagger, BeanValidation for a 
separate conversation. We've already had 2 iterations so far :-) but I'm 
ready for another one if you'd like.

Many thanks
Sergey
On 18/11/16 18:57, J. Fiala wrote:
> Hi Sergey,
>
> It was nice to meet you @ApacheCon, I lost you somehow after we talked!
> pls let me know if I should provide a PR on this or if you want to
> finish this yourself?
> If I should do the PR can you give me a hint where I should
> add/implement a test for this? In fact to test it we'd need a
> client-module with wadl2java + jaxb-krasa-tools (to have at least
> BeanValidation annotations for the Request/Response). Pls let me know if
> I should add a separate module for this?
>
> Best regards,
> Johannes
>
>
> Am 15.11.2016 um 17:38 schrieb Sergey Beryozkin:
>> Hi Johannes
>>
>> Sorry, was under a time pressure on Mon eve,
>>
>> Is Object really required to enable the validation of the method ?
>> Sorry, I know the individual (entity) bean can be easily validated but
>> not sure if providing the object in this case is a must
>>
>> Thanks, Sergey
>> On 14/11/16 22:11, Sergey Beryozkin wrote:
>>> I'll add a CXF Message property when I will start applying your patch -
>>> please open a CXF JIRA when you are ready.
>>>
>>> Please also work with the CXF BeanValidationProvider utility code which
>>> initializes the factory and add more utility code to it if needed for
>>> validating the individual parameters, it def has a method for validating
>>> the entity only, .validateBean().
>>>
>>> Sergey
>>>
>>>
>>> On 14/11/16 21:52, Sergey Beryozkin wrote:
>>>> This Object is a proxy.
>>>>
>>>> Please focus on validating the request parameters only. And simply
>>>> create a local final var with the same property
>>>>
>>>> Sergey
>>>>
>>>> On 14/11/16 21:35, J. Fiala wrote:
>>>>> Dear Sergey,
>>>>>
>>>>> Can you please also add the Object o (from public Object invoke(Object
>>>>> o, Method m, Object[] params) throws Throwable) as "method.object" CXF
>>>>> Message property at ClientProxyImpl.java?
>>>>>
>>>>> Then the interceptor works straightforward like this:
>>>>>
>>>>> public class ClientBeanValidationOutInterceptor extends
>>>>> AbstractPhaseInterceptor<Message> {
>>>>>
>>>>>
>>>>>     public ClientBeanValidationOutInterceptor() {
>>>>>         super(Phase.PRE_LOGICAL);
>>>>>     }
>>>>>
>>>>>     public ClientBeanValidationOutInterceptor(String phase) {
>>>>>         super(phase);
>>>>>     }
>>>>>
>>>>>     @Override
>>>>>     public void handleMessage(Message message) throws Fault {
>>>>>
>>>>>         Object objectToRunOn = (Object) message.get("method.object");
>>>>>         Object[] parameterValues = (Object[])
>>>>> message.get("method.parameters");
>>>>>
>>>>>         OperationResourceInfo info =
>>>>> message.getContent(OperationResourceInfo.class);
>>>>>
>>>>>         try {
>>>>>             ValidatorFactory factory =
>>>>> Validation.buildDefaultValidatorFactory();
>>>>>             ExecutableValidator executableValidator =
>>>>> factory.getValidator().forExecutables();
>>>>>
>>>>>
>>>>>             Method method = info.getMethodToInvoke();
>>>>>             Set<ConstraintViolation<Object>> violations =
>>>>> executableValidator
>>>>>                     .validateParameters(objectToRunOn, method,
>>>>>                     parameterValues);
>>>>>
>>>>>             if (violations.size() > 0) {
>>>>>                 Set<ConstraintViolation<Object>> violationsObj
=
>>>>> (Set<ConstraintViolation<Object>>) violations;
>>>>>                 throw new BeanValidationException(violationsObj);
>>>>>             }
>>>>>
>>>>>         } catch (SecurityException e) {
>>>>>             e.printStackTrace();
>>>>>         }
>>>>>
>>>>>     }
>>>>> }
>>>>>
>>>>> Pls let me know if I should add a PR for this (on separate branch
>>>>> client_beanvalidation) or if you are going to add it yourself ...
>>>>>
>>>>> Thank you & Best regards,
>>>>> Johannes
>>>>>
>>>>>
>>>>> Am 14.11.2016 um 13:08 schrieb Sergey Beryozkin:
>>>>>> Hi
>>>>>>
>>>>>> I've updated ClientProxyImpl to pass them as a "method.parameters"
>>>>>> CXF
>>>>>> Message property
>>>>>>
>>>>>> Thanks, Sergey.
>>>>>> On 13/11/16 19:49, J. Fiala wrote:
>>>>>>> Dear Sergey,
>>>>>>>
>>>>>>> To be more specific, at ClientProxyImpl.java the Object[] params
are
>>>>>>> available, but they are not passed onto the interceptor chain:
>>>>>>>
>>>>>>> return doChainedInvocation(uri, headers, ori, body, bodyIndex,
null,
>>>>>>> null);
>>>>>>>
>>>>>>> Is there a another way I can access the Object[] params in an
>>>>>>> interceptor?
>>>>>>>
>>>>>>> Or do I have to subclass ClientProxyImpl.java?
>>>>>>>
>>>>>>> Best regards,
>>>>>>> Johannes
>>>>>>>
>>>>>>>
>>>>>>> Am 13.11.2016 um 20:45 schrieb J. Fiala:
>>>>>>>> Dear Sergey,
>>>>>>>>
>>>>>>>> I tried to implement the BeanValidation for the client for
outgoing
>>>>>>>> operations in an OutInterceptor.
>>>>>>>>
>>>>>>>> I need to be able to validate the parameters for the method:
>>>>>>>> Set<ConstraintViolation<Object>> violations =
>>>>>>>> executableValidator.validateParameters(this, method,
>>>>>>>>                     parameterValues);
>>>>>>>>
>>>>>>>> Getting access to the method is no problem using
>>>>>>>> OperationResourceInfo.class.
>>>>>>>>
>>>>>>>> How can I access the parameter values (Object[] parameterValues)
of
>>>>>>>> the method that has been invoked so I can validate them?
>>>>>>>>
>>>>>>>> I can get easily access to the json objects if passed to
the
>>>>>>>> method,
>>>>>>>> but I need access to the original method invocation, before
the
>>>>>>>> message has been assembled to query/path/body params etc.
>>>>>>>>
>>>>>>>> Best regards,
>>>>>>>> Johannes
>>>>>>>>
>>>>>>>>
>>>>>>>> Am 24.10.2016 um 17:04 schrieb Sergey Beryozkin:
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> I guess it can be interesting to support an optional
client side
>>>>>>>>> bean
>>>>>>>>> validation for the proxy clients as they have all the
bean
>>>>>>>>> validation
>>>>>>>>> annotations available...
>>>>>>>>>
>>>>>>>>> Cheers, Sergey
>>>>>>>>> On 24/10/16 14:47, J. Fiala wrote:
>>>>>>>>>> Hi there,
>>>>>>>>>>
>>>>>>>>>> Is automatic client-side beanvalidation supported
somehow
>>>>>>>>>> (currently
>>>>>>>>>> this is not mentioned in the docs)?
>>>>>>>>>>
>>>>>>>>>> Maybe it would make sense to add this to the configuration,
so
>>>>>>>>>> this has
>>>>>>>>>> not to be done manually before calling the server?
>>>>>>>>>>
>>>>>>>>>> Best regards,
>>>>>>>>>> Johannes
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>


Mime
View raw message