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












--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Reply via email to