You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by wi...@yahoo.com on 2014/03/04 19:49:20 UTC

Advice on overwriting @PathParameters jax-rs and cxf proxies

Hi,

First of all I apologize if this has been asked before. 
I wanted to ask for good solution that won't be too inefficient.
I do know about cxf interceptors and also request handlers method to
add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.

We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).

On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
On server side I would like to revert those and unwrap and get back the original parameter.
@PathParam("test1") test1

on client take test1 original value and add some extra characters to it
on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.

So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).

please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.

thanks,
parwiz

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by wi...@yahoo.com.
thanks Sergey.

I will try to test/play using BeanParam with Jersey and RestEasy later this weekend when i get some free cycles and i'll add my findings at the jira you linked.

Again thanks for fixing it for other types of parameters. It's made life much easier on me :)  thanks for all the hard work.

parwiz


________________________________
 From: Sergey Beryozkin <sb...@gmail.com>
To: users@cxf.apache.org 
Sent: Thursday, March 13, 2014 4:20 AM
Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
 

Hi,

you've raised an interesting issue, specifically, which annotations are 
effective when using bean setters in JAX-RS, BeanParam is only one 
example, the other one is injecting path/query/etc parameters into 
per-request root resources.

I've opened
https://java.net/jira/browse/JAX_RS_SPEC-450

In meantime I've temp reverted the client proxy code change related to 
BeanParam, parameter-level annotations are used for now, for the sake of 
the consistency.

Can you comment on that JIRA ? Or may be you can give me a favor and 
test Jersey or RestEasy and see what annotations they have passed in 
case of bean setters, method or parameter annotations or both method and 
parameter annotations and may be report at that JIRA ?

Many thanks, Sergey


On 12/03/14 10:12, wizpar@yahoo.com wrote:
> Thank you Sergey for looking at this again.
> I tried the snapshot build and the fix is only applied to Client side so yes it does call param converter provider with annotations of the BeanParam inner fields as well but on server side the bug still remains
>
>> Now on server side we are only sending m.getParameterAnnotations()[0]
>> and again since for BeanParam the annotations are delcaredAnnotations
>> then we have to do some sort of check and choose between m.getParameterAnnotations() or m.getDeclaredAnnotations() for BeanParams
>>
>> inside JAXRSUtils.injectParameters()
>>
>>                    o = createHttpParameterValue(p,
>>                                                    m.getParameterTypes()[0],
>>                                                    m.getGenericParameterTypes()[0],
>>                                                    m.getParameterAnnotations()[0],
>>                                                    message,
>>                                                    values,
>>                                                    ori);
>
>
> please take a look at applying your client fix to server end as well so it can call param converter with annotations passed in.. otherwise i tested with client side and it correctly
> sent annotations ..
> thanks,
> parwiz
>
>
>
> ________________________________
>   From: Sergey Beryozkin <sb...@gmail.com>
> To: users@cxf.apache.org
> Sent: Tuesday, March 11, 2014 4:59 AM
> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>
>
> Hi
>
> Thanks for spotting it, fixed now, try the snapshots please
>
> Sergey
>
> On 06/03/14 21:37, wizpar@yahoo.com wrote:
>> Sergey,
>>
>> The only situtation where it's not working for is if we have a @BeanParam
>> it does not pass the annotations of the method related to that param
>> down to ParamConvertProvider
>>
>> public class MyBean {
>>
>> private String field1;
>> private String field2;
>>
>> public String getField1() {
>> return field1;
>> }
>>
>> @PathParam("field1")
>> @Encoded
>> public void setField1(String field1) {
>> this.field1 = field1;
>> }
>>
>> public String getField2() {
>> return field2;
>> }
>>
>> @PathParam("field1")
>> public void setField2(String field2) {
>> this.field2 = field2;
>> }
>> }
>>
>> @Path("/server")
>> public interface Server {
>> @GET
>> @Path("/{field1}/{field2}")
>> public BookBean book(@BeanParam MyBean myBean);
>> }
>>
>> i think on clientside we can just send PathParam.class as anotations for these guys since we know in this method we are dealing with pathparam be it from service bean or be it from @BeanParam
>> ClientProxyImpl.getPathParamValues()
>>
>>
>>            for (String varName : methodVars) {
>>                Parameter p = paramsMap.remove(varName);
>>                if (p != null) {
>>                    list.add(convertParamValue(params[p.getIndex()], getParamAnnotations(m, p)));
>>                } else if (beanParamValues.containsKey(varName)) {
>>                    list.add(convertParamValue(beanParamValues.get(varName), null));
>>                }
>>            }
>>
>> if it's from beanParamValues
>> we can just do convertParamValue(beanParamValues.get(varName), new Annotation[] {PathParam.class});
>>
>> or get m.getDeclaredAnnotations() since these are declared and not part of
>> parameter formal definition itself in method signature.
>>
>> Now on server side we are only sending m.getParameterAnnotations()[0]
>> and again since for BeanParam the annotations are delcaredAnnotations
>> then we have to do some sort of check and choose between m.getParameterAnnotations() or m.getDeclaredAnnotations() for BeanParams
>>
>> inside JAXRSUtils.injectParameters()
>>
>>                    o = createHttpParameterValue(p,
>>                                                    m.getParameterTypes()[0],
>>                                                    m.getGenericParameterTypes()[0],
>>                                                    m.getParameterAnnotations()[0],
>>                                                    message,
>>                                                    values,
>>                                                    ori);
>>
>> please take a look as i believe this will fix the only param type so far that's not consistent with other params.
>>
>> i tested with @PathParam, @QueryParam, @MatrixParam, @FormParam
>> in service layer and they all work fine with param converters
>> but @BeanParam is the only one that leaves out sending annotations of it's related method to converter.
>>
>> thanks,
>> parwiz
>>
>>
>> ________________________________
>>     From: Sergey Beryozkin <sb...@gmail.com>
>> To: users@cxf.apache.org
>> Sent: Wednesday, March 5, 2014 6:13 AM
>> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>>
>>
>> It has been fixed, try the snapshots please
>> Sergey
>>
>> On 04/03/14 21:36, wizpar@yahoo.com wrote:
>>> Thanks Sergey.
>>>
>>> i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.
>>>
>>> "
>>>          protected String convertParamValue(Object pValue) {
>>>              if (pValue == null) {
>>>                  return null;
>>>              }
>>>              Class<?> pClass = pValue.getClass();
>>>              if (pClass == String.class || pClass.isPrimitive()) {
>>>                  return pValue.toString();
>>>              }
>>>
>>>             ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
>>>              if (pf != null) {
>>>                  @SuppressWarnings("unchecked")
>>>                  ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
>>>                  if (prov != null) {
>>>                      return prov.toString(pValue);
>>>                  }
>>>              }
>>>              return pValue.toString();
>>>          }
>>>
>>> "
>>> if it's just a string param it skips calling any custom param handlers.
>>>
>>> the other thing i noticed which maybe a bug is for ParamConverterProvider
>>> i thought the annotations would be populated so you can see what type of param it is
>>>
>>> public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)
>>>
>>>
>>> but in my tests both server side and client side
>>> arg2 was always null.
>>> i thought it might be set with actual anotations from the @PathParam declaration.
>>>
>>> I'll look into filters then in my case or interceptors.
>>> would you recommend a good location to do the param modifications as to be
>>> most efficient in the cxf chain of filters/interceptors.
>>>
>>> again my param is just a simple string and i want to apply this modification
>>> to only @PathParam params.. query and form i want to leave those as is.
>>> so I need a way to check a) is it a String variable only and b) is it a PathParam
>>> the modify/wrap/unwrap.
>>>
>>> thanks,
>>> parwiz
>>>
>>>
>>>
>>> ________________________________
>>>       From: Sergey Beryozkin <sb...@gmail.com>
>>> To: users@cxf.apache.org
>>> Sent: Tuesday, March 4, 2014 1:08 PM
>>> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>>>
>>>
>>> Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter
>>> can be used to override the request URI.
>>>
>>> JAX-RS 2.0 ParamConverterProvider can be used on the client and server
>>> sides, may give you a finer control...
>>>
>>> HTH, Sergey
>>>
>>> On 04/03/14 18:49, wizpar@yahoo.com wrote:
>>>> Hi,
>>>>
>>>> First of all I apologize if this has been asked before.
>>>> I wanted to ask for good solution that won't be too inefficient.
>>>> I do know about cxf interceptors and also request handlers method to
>>>> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>>>>
>>>> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
>>>> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>>>>
>>>> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
>>>> On server side I would like to revert those and unwrap and get back the original parameter.
>>>> @PathParam("test1") test1
>>>>
>>>> on client take test1 original value and add some extra characters to it
>>>> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>>>>
>>>> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>>>>
>>>> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>>>>
>>>> thanks,
>>>> parwiz
>>>>
>>>
>>>
>>
>>
>
>

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,

you've raised an interesting issue, specifically, which annotations are 
effective when using bean setters in JAX-RS, BeanParam is only one 
example, the other one is injecting path/query/etc parameters into 
per-request root resources.

I've opened
https://java.net/jira/browse/JAX_RS_SPEC-450

In meantime I've temp reverted the client proxy code change related to 
BeanParam, parameter-level annotations are used for now, for the sake of 
the consistency.

Can you comment on that JIRA ? Or may be you can give me a favor and 
test Jersey or RestEasy and see what annotations they have passed in 
case of bean setters, method or parameter annotations or both method and 
parameter annotations and may be report at that JIRA ?

Many thanks, Sergey

On 12/03/14 10:12, wizpar@yahoo.com wrote:
> Thank you Sergey for looking at this again.
> I tried the snapshot build and the fix is only applied to Client side so yes it does call param converter provider with annotations of the BeanParam inner fields as well but on server side the bug still remains
>
>> Now on server side we are only sending m.getParameterAnnotations()[0]
>> and again since for BeanParam the annotations are delcaredAnnotations
>> then we have to do some sort of check and choose between m.getParameterAnnotations() or m.getDeclaredAnnotations() for BeanParams
>>
>> inside JAXRSUtils.injectParameters()
>>
>>                    o = createHttpParameterValue(p,
>>                                                    m.getParameterTypes()[0],
>>                                                    m.getGenericParameterTypes()[0],
>>                                                    m.getParameterAnnotations()[0],
>>                                                    message,
>>                                                    values,
>>                                                    ori);
>
>
> please take a look at applying your client fix to server end as well so it can call param converter with annotations passed in.. otherwise i tested with client side and it correctly
> sent annotations ..
> thanks,
> parwiz
>
>
>
> ________________________________
>   From: Sergey Beryozkin <sb...@gmail.com>
> To: users@cxf.apache.org
> Sent: Tuesday, March 11, 2014 4:59 AM
> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>
>
> Hi
>
> Thanks for spotting it, fixed now, try the snapshots please
>
> Sergey
>
> On 06/03/14 21:37, wizpar@yahoo.com wrote:
>> Sergey,
>>
>> The only situtation where it's not working for is if we have a @BeanParam
>> it does not pass the annotations of the method related to that param
>> down to ParamConvertProvider
>>
>> public class MyBean {
>>
>> private String field1;
>> private String field2;
>>
>> public String getField1() {
>> return field1;
>> }
>>
>> @PathParam("field1")
>> @Encoded
>> public void setField1(String field1) {
>> this.field1 = field1;
>> }
>>
>> public String getField2() {
>> return field2;
>> }
>>
>> @PathParam("field1")
>> public void setField2(String field2) {
>> this.field2 = field2;
>> }
>> }
>>
>> @Path("/server")
>> public interface Server {
>> @GET
>> @Path("/{field1}/{field2}")
>> public BookBean book(@BeanParam MyBean myBean);
>> }
>>
>> i think on clientside we can just send PathParam.class as anotations for these guys since we know in this method we are dealing with pathparam be it from service bean or be it from @BeanParam
>> ClientProxyImpl.getPathParamValues()
>>
>>
>>            for (String varName : methodVars) {
>>                Parameter p = paramsMap.remove(varName);
>>                if (p != null) {
>>                    list.add(convertParamValue(params[p.getIndex()], getParamAnnotations(m, p)));
>>                } else if (beanParamValues.containsKey(varName)) {
>>                    list.add(convertParamValue(beanParamValues.get(varName), null));
>>                }
>>            }
>>
>> if it's from beanParamValues
>> we can just do convertParamValue(beanParamValues.get(varName), new Annotation[] {PathParam.class});
>>
>> or get m.getDeclaredAnnotations() since these are declared and not part of
>> parameter formal definition itself in method signature.
>>
>> Now on server side we are only sending m.getParameterAnnotations()[0]
>> and again since for BeanParam the annotations are delcaredAnnotations
>> then we have to do some sort of check and choose between m.getParameterAnnotations() or m.getDeclaredAnnotations() for BeanParams
>>
>> inside JAXRSUtils.injectParameters()
>>
>>                    o = createHttpParameterValue(p,
>>                                                    m.getParameterTypes()[0],
>>                                                    m.getGenericParameterTypes()[0],
>>                                                    m.getParameterAnnotations()[0],
>>                                                    message,
>>                                                    values,
>>                                                    ori);
>>
>> please take a look as i believe this will fix the only param type so far that's not consistent with other params.
>>
>> i tested with @PathParam, @QueryParam, @MatrixParam, @FormParam
>> in service layer and they all work fine with param converters
>> but @BeanParam is the only one that leaves out sending annotations of it's related method to converter.
>>
>> thanks,
>> parwiz
>>
>>
>> ________________________________
>>     From: Sergey Beryozkin <sb...@gmail.com>
>> To: users@cxf.apache.org
>> Sent: Wednesday, March 5, 2014 6:13 AM
>> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>>
>>
>> It has been fixed, try the snapshots please
>> Sergey
>>
>> On 04/03/14 21:36, wizpar@yahoo.com wrote:
>>> Thanks Sergey.
>>>
>>> i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.
>>>
>>> "
>>>          protected String convertParamValue(Object pValue) {
>>>              if (pValue == null) {
>>>                  return null;
>>>              }
>>>              Class<?> pClass = pValue.getClass();
>>>              if (pClass == String.class || pClass.isPrimitive()) {
>>>                  return pValue.toString();
>>>              }
>>>
>>>             ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
>>>              if (pf != null) {
>>>                  @SuppressWarnings("unchecked")
>>>                  ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
>>>                  if (prov != null) {
>>>                      return prov.toString(pValue);
>>>                  }
>>>              }
>>>              return pValue.toString();
>>>          }
>>>
>>> "
>>> if it's just a string param it skips calling any custom param handlers.
>>>
>>> the other thing i noticed which maybe a bug is for ParamConverterProvider
>>> i thought the annotations would be populated so you can see what type of param it is
>>>
>>> public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)
>>>
>>>
>>> but in my tests both server side and client side
>>> arg2 was always null.
>>> i thought it might be set with actual anotations from the @PathParam declaration.
>>>
>>> I'll look into filters then in my case or interceptors.
>>> would you recommend a good location to do the param modifications as to be
>>> most efficient in the cxf chain of filters/interceptors.
>>>
>>> again my param is just a simple string and i want to apply this modification
>>> to only @PathParam params.. query and form i want to leave those as is.
>>> so I need a way to check a) is it a String variable only and b) is it a PathParam
>>> the modify/wrap/unwrap.
>>>
>>> thanks,
>>> parwiz
>>>
>>>
>>>
>>> ________________________________
>>>       From: Sergey Beryozkin <sb...@gmail.com>
>>> To: users@cxf.apache.org
>>> Sent: Tuesday, March 4, 2014 1:08 PM
>>> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>>>
>>>
>>> Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter
>>> can be used to override the request URI.
>>>
>>> JAX-RS 2.0 ParamConverterProvider can be used on the client and server
>>> sides, may give you a finer control...
>>>
>>> HTH, Sergey
>>>
>>> On 04/03/14 18:49, wizpar@yahoo.com wrote:
>>>> Hi,
>>>>
>>>> First of all I apologize if this has been asked before.
>>>> I wanted to ask for good solution that won't be too inefficient.
>>>> I do know about cxf interceptors and also request handlers method to
>>>> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>>>>
>>>> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
>>>> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>>>>
>>>> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
>>>> On server side I would like to revert those and unwrap and get back the original parameter.
>>>> @PathParam("test1") test1
>>>>
>>>> on client take test1 original value and add some extra characters to it
>>>> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>>>>
>>>> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>>>>
>>>> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>>>>
>>>> thanks,
>>>> parwiz
>>>>
>>>
>>>
>>
>>
>
>

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by wi...@yahoo.com.
Thank you Sergey for looking at this again.
I tried the snapshot build and the fix is only applied to Client side so yes it does call param converter provider with annotations of the BeanParam inner fields as well but on server side the bug still remains

> Now on server side we are only sending m.getParameterAnnotations()[0]
> and again since for BeanParam the annotations are delcaredAnnotations
> then we have to do some sort of check and choose between m.getParameterAnnotations() or m.getDeclaredAnnotations() for BeanParams
>
> inside JAXRSUtils.injectParameters()
>
>                  o = createHttpParameterValue(p,
>                                                  m.getParameterTypes()[0],
>                                                  m.getGenericParameterTypes()[0],
>                                                  m.getParameterAnnotations()[0],
>                                                  message,
>                                                  values,
>                                                  ori);


please take a look at applying your client fix to server end as well so it can call param converter with annotations passed in.. otherwise i tested with client side and it correctly
sent annotations ..
thanks,
parwiz



________________________________
 From: Sergey Beryozkin <sb...@gmail.com>
To: users@cxf.apache.org 
Sent: Tuesday, March 11, 2014 4:59 AM
Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
 

Hi

Thanks for spotting it, fixed now, try the snapshots please

Sergey

On 06/03/14 21:37, wizpar@yahoo.com wrote:
> Sergey,
>
> The only situtation where it's not working for is if we have a @BeanParam
> it does not pass the annotations of the method related to that param
> down to ParamConvertProvider
>
> public class MyBean {
>
> private String field1;
> private String field2;
>
> public String getField1() {
> return field1;
> }
>
> @PathParam("field1")
> @Encoded
> public void setField1(String field1) {
> this.field1 = field1;
> }
>
> public String getField2() {
> return field2;
> }
>
> @PathParam("field1")
> public void setField2(String field2) {
> this.field2 = field2;
> }
> }
>
> @Path("/server")
> public interface Server {
> @GET
> @Path("/{field1}/{field2}")
> public BookBean book(@BeanParam MyBean myBean);
> }
>
> i think on clientside we can just send PathParam.class as anotations for these guys since we know in this method we are dealing with pathparam be it from service bean or be it from @BeanParam
> ClientProxyImpl.getPathParamValues()
>
>
>          for (String varName : methodVars) {
>              Parameter p = paramsMap.remove(varName);
>              if (p != null) {
>                  list.add(convertParamValue(params[p.getIndex()], getParamAnnotations(m, p)));
>              } else if (beanParamValues.containsKey(varName)) {
>                  list.add(convertParamValue(beanParamValues.get(varName), null));
>              }
>          }
>
> if it's from beanParamValues
> we can just do convertParamValue(beanParamValues.get(varName), new Annotation[] {PathParam.class});
>
> or get m.getDeclaredAnnotations() since these are declared and not part of
> parameter formal definition itself in method signature.
>
> Now on server side we are only sending m.getParameterAnnotations()[0]
> and again since for BeanParam the annotations are delcaredAnnotations
> then we have to do some sort of check and choose between m.getParameterAnnotations() or m.getDeclaredAnnotations() for BeanParams
>
> inside JAXRSUtils.injectParameters()
>
>                  o = createHttpParameterValue(p,
>                                                  m.getParameterTypes()[0],
>                                                  m.getGenericParameterTypes()[0],
>                                                  m.getParameterAnnotations()[0],
>                                                  message,
>                                                  values,
>                                                  ori);
>
> please take a look as i believe this will fix the only param type so far that's not consistent with other params.
>
> i tested with @PathParam, @QueryParam, @MatrixParam, @FormParam
> in service layer and they all work fine with param converters
> but @BeanParam is the only one that leaves out sending annotations of it's related method to converter.
>
> thanks,
> parwiz
>
>
> ________________________________
>   From: Sergey Beryozkin <sb...@gmail.com>
> To: users@cxf.apache.org
> Sent: Wednesday, March 5, 2014 6:13 AM
> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>
>
> It has been fixed, try the snapshots please
> Sergey
>
> On 04/03/14 21:36, wizpar@yahoo.com wrote:
>> Thanks Sergey.
>>
>> i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.
>>
>> "
>>        protected String convertParamValue(Object pValue) {
>>            if (pValue == null) {
>>                return null;
>>            }
>>            Class<?> pClass = pValue.getClass();
>>            if (pClass == String.class || pClass.isPrimitive()) {
>>                return pValue.toString();
>>            }
>>
>>           ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
>>            if (pf != null) {
>>                @SuppressWarnings("unchecked")
>>                ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
>>                if (prov != null) {
>>                    return prov.toString(pValue);
>>                }
>>            }
>>            return pValue.toString();
>>        }
>>
>> "
>> if it's just a string param it skips calling any custom param handlers.
>>
>> the other thing i noticed which maybe a bug is for ParamConverterProvider
>> i thought the annotations would be populated so you can see what type of param it is
>>
>> public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)
>>
>>
>> but in my tests both server side and client side
>> arg2 was always null.
>> i thought it might be set with actual anotations from the @PathParam declaration.
>>
>> I'll look into filters then in my case or interceptors.
>> would you recommend a good location to do the param modifications as to be
>> most efficient in the cxf chain of filters/interceptors.
>>
>> again my param is just a simple string and i want to apply this modification
>> to only @PathParam params.. query and form i want to leave those as is.
>> so I need a way to check a) is it a String variable only and b) is it a PathParam
>> the modify/wrap/unwrap.
>>
>> thanks,
>> parwiz
>>
>>
>>
>> ________________________________
>>     From: Sergey Beryozkin <sb...@gmail.com>
>> To: users@cxf.apache.org
>> Sent: Tuesday, March 4, 2014 1:08 PM
>> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>>
>>
>> Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter
>> can be used to override the request URI.
>>
>> JAX-RS 2.0 ParamConverterProvider can be used on the client and server
>> sides, may give you a finer control...
>>
>> HTH, Sergey
>>
>> On 04/03/14 18:49, wizpar@yahoo.com wrote:
>>> Hi,
>>>
>>> First of all I apologize if this has been asked before.
>>> I wanted to ask for good solution that won't be too inefficient.
>>> I do know about cxf interceptors and also request handlers method to
>>> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>>>
>>> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
>>> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>>>
>>> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
>>> On server side I would like to revert those and unwrap and get back the original parameter.
>>> @PathParam("test1") test1
>>>
>>> on client take test1 original value and add some extra characters to it
>>> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>>>
>>> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>>>
>>> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>>>
>>> thanks,
>>> parwiz
>>>
>>
>>
>
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Thanks for spotting it, fixed now, try the snapshots please

Sergey
On 06/03/14 21:37, wizpar@yahoo.com wrote:
> Sergey,
>
> The only situtation where it's not working for is if we have a @BeanParam
> it does not pass the annotations of the method related to that param
> down to ParamConvertProvider
>
> public class MyBean {
>
> private String field1;
> private String field2;
>
> public String getField1() {
> return field1;
> }
>
> @PathParam("field1")
> @Encoded
> public void setField1(String field1) {
> this.field1 = field1;
> }
>
> public String getField2() {
> return field2;
> }
>
> @PathParam("field1")
> public void setField2(String field2) {
> this.field2 = field2;
> }
> }
>
> @Path("/server")
> public interface Server {
> @GET
> @Path("/{field1}/{field2}")
> public BookBean book(@BeanParam MyBean myBean);
> }
>
> i think on clientside we can just send PathParam.class as anotations for these guys since we know in this method we are dealing with pathparam be it from service bean or be it from @BeanParam
> ClientProxyImpl.getPathParamValues()
>
>
>          for (String varName : methodVars) {
>              Parameter p = paramsMap.remove(varName);
>              if (p != null) {
>                  list.add(convertParamValue(params[p.getIndex()], getParamAnnotations(m, p)));
>              } else if (beanParamValues.containsKey(varName)) {
>                  list.add(convertParamValue(beanParamValues.get(varName), null));
>              }
>          }
>
> if it's from beanParamValues
> we can just do convertParamValue(beanParamValues.get(varName), new Annotation[] {PathParam.class});
>
> or get m.getDeclaredAnnotations() since these are declared and not part of
> parameter formal definition itself in method signature.
>
> Now on server side we are only sending m.getParameterAnnotations()[0]
> and again since for BeanParam the annotations are delcaredAnnotations
> then we have to do some sort of check and choose between m.getParameterAnnotations() or m.getDeclaredAnnotations() for BeanParams
>
> inside JAXRSUtils.injectParameters()
>
>                  o = createHttpParameterValue(p,
>                                                  m.getParameterTypes()[0],
>                                                  m.getGenericParameterTypes()[0],
>                                                  m.getParameterAnnotations()[0],
>                                                  message,
>                                                  values,
>                                                  ori);
>
> please take a look as i believe this will fix the only param type so far that's not consistent with other params.
>
> i tested with @PathParam, @QueryParam, @MatrixParam, @FormParam
> in service layer and they all work fine with param converters
> but @BeanParam is the only one that leaves out sending annotations of it's related method to converter.
>
> thanks,
> parwiz
>
>
> ________________________________
>   From: Sergey Beryozkin <sb...@gmail.com>
> To: users@cxf.apache.org
> Sent: Wednesday, March 5, 2014 6:13 AM
> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>
>
> It has been fixed, try the snapshots please
> Sergey
>
> On 04/03/14 21:36, wizpar@yahoo.com wrote:
>> Thanks Sergey.
>>
>> i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.
>>
>> "
>>        protected String convertParamValue(Object pValue) {
>>            if (pValue == null) {
>>                return null;
>>            }
>>            Class<?> pClass = pValue.getClass();
>>            if (pClass == String.class || pClass.isPrimitive()) {
>>                return pValue.toString();
>>            }
>>
>>           ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
>>            if (pf != null) {
>>                @SuppressWarnings("unchecked")
>>                ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
>>                if (prov != null) {
>>                    return prov.toString(pValue);
>>                }
>>            }
>>            return pValue.toString();
>>        }
>>
>> "
>> if it's just a string param it skips calling any custom param handlers.
>>
>> the other thing i noticed which maybe a bug is for ParamConverterProvider
>> i thought the annotations would be populated so you can see what type of param it is
>>
>> public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)
>>
>>
>> but in my tests both server side and client side
>> arg2 was always null.
>> i thought it might be set with actual anotations from the @PathParam declaration.
>>
>> I'll look into filters then in my case or interceptors.
>> would you recommend a good location to do the param modifications as to be
>> most efficient in the cxf chain of filters/interceptors.
>>
>> again my param is just a simple string and i want to apply this modification
>> to only @PathParam params.. query and form i want to leave those as is.
>> so I need a way to check a) is it a String variable only and b) is it a PathParam
>> the modify/wrap/unwrap.
>>
>> thanks,
>> parwiz
>>
>>
>>
>> ________________________________
>>     From: Sergey Beryozkin <sb...@gmail.com>
>> To: users@cxf.apache.org
>> Sent: Tuesday, March 4, 2014 1:08 PM
>> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>>
>>
>> Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter
>> can be used to override the request URI.
>>
>> JAX-RS 2.0 ParamConverterProvider can be used on the client and server
>> sides, may give you a finer control...
>>
>> HTH, Sergey
>>
>> On 04/03/14 18:49, wizpar@yahoo.com wrote:
>>> Hi,
>>>
>>> First of all I apologize if this has been asked before.
>>> I wanted to ask for good solution that won't be too inefficient.
>>> I do know about cxf interceptors and also request handlers method to
>>> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>>>
>>> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
>>> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>>>
>>> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
>>> On server side I would like to revert those and unwrap and get back the original parameter.
>>> @PathParam("test1") test1
>>>
>>> on client take test1 original value and add some extra characters to it
>>> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>>>
>>> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>>>
>>> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>>>
>>> thanks,
>>> parwiz
>>>
>>
>>
>
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by wi...@yahoo.com.
Sergey,

The only situtation where it's not working for is if we have a @BeanParam
it does not pass the annotations of the method related to that param
down to ParamConvertProvider 

public class MyBean {

private String field1;
private String field2;

public String getField1() {
return field1;
}

@PathParam("field1")
@Encoded
public void setField1(String field1) {
this.field1 = field1;
}

public String getField2() {
return field2;
}

@PathParam("field1")
public void setField2(String field2) {
this.field2 = field2;
}
}

@Path("/server")
public interface Server {
@GET
@Path("/{field1}/{field2}")
public BookBean book(@BeanParam MyBean myBean);
}

i think on clientside we can just send PathParam.class as anotations for these guys since we know in this method we are dealing with pathparam be it from service bean or be it from @BeanParam
ClientProxyImpl.getPathParamValues()


        for (String varName : methodVars) {
            Parameter p = paramsMap.remove(varName);
            if (p != null) {
                list.add(convertParamValue(params[p.getIndex()], getParamAnnotations(m, p)));
            } else if (beanParamValues.containsKey(varName)) {
                list.add(convertParamValue(beanParamValues.get(varName), null));
            }
        }

if it's from beanParamValues 
we can just do convertParamValue(beanParamValues.get(varName), new Annotation[] {PathParam.class});

or get m.getDeclaredAnnotations() since these are declared and not part of 
parameter formal definition itself in method signature.

Now on server side we are only sending m.getParameterAnnotations()[0]
and again since for BeanParam the annotations are delcaredAnnotations
then we have to do some sort of check and choose between m.getParameterAnnotations() or m.getDeclaredAnnotations() for BeanParams

inside JAXRSUtils.injectParameters()

                o = createHttpParameterValue(p, 
                                                m.getParameterTypes()[0],
                                                m.getGenericParameterTypes()[0],
                                                m.getParameterAnnotations()[0],
                                                message,
                                                values,
                                                ori);

please take a look as i believe this will fix the only param type so far that's not consistent with other params.

i tested with @PathParam, @QueryParam, @MatrixParam, @FormParam
in service layer and they all work fine with param converters
but @BeanParam is the only one that leaves out sending annotations of it's related method to converter.

thanks,
parwiz


________________________________
 From: Sergey Beryozkin <sb...@gmail.com>
To: users@cxf.apache.org 
Sent: Wednesday, March 5, 2014 6:13 AM
Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
 

It has been fixed, try the snapshots please
Sergey

On 04/03/14 21:36, wizpar@yahoo.com wrote:
> Thanks Sergey.
>
> i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.
>
> "
>      protected String convertParamValue(Object pValue) {
>          if (pValue == null) {
>              return null;
>          }
>          Class<?> pClass = pValue.getClass();
>          if (pClass == String.class || pClass.isPrimitive()) {
>              return pValue.toString();
>          }
>
>         ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
>          if (pf != null) {
>              @SuppressWarnings("unchecked")
>              ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
>              if (prov != null) {
>                  return prov.toString(pValue);
>              }
>          }
>          return pValue.toString();
>      }
>
> "
> if it's just a string param it skips calling any custom param handlers.
>
> the other thing i noticed which maybe a bug is for ParamConverterProvider
> i thought the annotations would be populated so you can see what type of param it is
>
> public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)
>
>
> but in my tests both server side and client side
> arg2 was always null.
> i thought it might be set with actual anotations from the @PathParam declaration.
>
> I'll look into filters then in my case or interceptors.
> would you recommend a good location to do the param modifications as to be
> most efficient in the cxf chain of filters/interceptors.
>
> again my param is just a simple string and i want to apply this modification
> to only @PathParam params.. query and form i want to leave those as is.
> so I need a way to check a) is it a String variable only and b) is it a PathParam
> the modify/wrap/unwrap.
>
> thanks,
> parwiz
>
>
>
> ________________________________
>   From: Sergey Beryozkin <sb...@gmail.com>
> To: users@cxf.apache.org
> Sent: Tuesday, March 4, 2014 1:08 PM
> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>
>
> Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter
> can be used to override the request URI.
>
> JAX-RS 2.0 ParamConverterProvider can be used on the client and server
> sides, may give you a finer control...
>
> HTH, Sergey
>
> On 04/03/14 18:49, wizpar@yahoo.com wrote:
>> Hi,
>>
>> First of all I apologize if this has been asked before.
>> I wanted to ask for good solution that won't be too inefficient.
>> I do know about cxf interceptors and also request handlers method to
>> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>>
>> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
>> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>>
>> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
>> On server side I would like to revert those and unwrap and get back the original parameter.
>> @PathParam("test1") test1
>>
>> on client take test1 original value and add some extra characters to it
>> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>>
>> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>>
>> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>>
>> thanks,
>> parwiz
>>
>
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by wi...@yahoo.com.
Hi Sergey,

I pulled snapshots and it's working great. You saved me a ton of hacky work-around of making it work before this fix but now with ParamConverter and ParamConvertProvider it's working like a charm. 

Thank you very much for taking care of this so quickly. You are awesome :)
Appreciate all the hard work you are putting into this project.

thanks,
parwiz


________________________________
 From: Sergey Beryozkin <sb...@gmail.com>
To: users@cxf.apache.org 
Sent: Wednesday, March 5, 2014 6:13 AM
Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
 

It has been fixed, try the snapshots please
Sergey

On 04/03/14 21:36, wizpar@yahoo.com wrote:
> Thanks Sergey.
>
> i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.
>
> "
>      protected String convertParamValue(Object pValue) {
>          if (pValue == null) {
>              return null;
>          }
>          Class<?> pClass = pValue.getClass();
>          if (pClass == String.class || pClass.isPrimitive()) {
>              return pValue.toString();
>          }
>
>         ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
>          if (pf != null) {
>              @SuppressWarnings("unchecked")
>              ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
>              if (prov != null) {
>                  return prov.toString(pValue);
>              }
>          }
>          return pValue.toString();
>      }
>
> "
> if it's just a string param it skips calling any custom param handlers.
>
> the other thing i noticed which maybe a bug is for ParamConverterProvider
> i thought the annotations would be populated so you can see what type of param it is
>
> public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)
>
>
> but in my tests both server side and client side
> arg2 was always null.
> i thought it might be set with actual anotations from the @PathParam declaration.
>
> I'll look into filters then in my case or interceptors.
> would you recommend a good location to do the param modifications as to be
> most efficient in the cxf chain of filters/interceptors.
>
> again my param is just a simple string and i want to apply this modification
> to only @PathParam params.. query and form i want to leave those as is.
> so I need a way to check a) is it a String variable only and b) is it a PathParam
> the modify/wrap/unwrap.
>
> thanks,
> parwiz
>
>
>
> ________________________________
>   From: Sergey Beryozkin <sb...@gmail.com>
> To: users@cxf.apache.org
> Sent: Tuesday, March 4, 2014 1:08 PM
> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>
>
> Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter
> can be used to override the request URI.
>
> JAX-RS 2.0 ParamConverterProvider can be used on the client and server
> sides, may give you a finer control...
>
> HTH, Sergey
>
> On 04/03/14 18:49, wizpar@yahoo.com wrote:
>> Hi,
>>
>> First of all I apologize if this has been asked before.
>> I wanted to ask for good solution that won't be too inefficient.
>> I do know about cxf interceptors and also request handlers method to
>> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>>
>> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
>> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>>
>> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
>> On server side I would like to revert those and unwrap and get back the original parameter.
>> @PathParam("test1") test1
>>
>> on client take test1 original value and add some extra characters to it
>> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>>
>> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>>
>> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>>
>> thanks,
>> parwiz
>>
>
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by Sergey Beryozkin <sb...@gmail.com>.
It has been fixed, try the snapshots please
Sergey
On 04/03/14 21:36, wizpar@yahoo.com wrote:
> Thanks Sergey.
>
> i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.
>
> "
>      protected String convertParamValue(Object pValue) {
>          if (pValue == null) {
>              return null;
>          }
>          Class<?> pClass = pValue.getClass();
>          if (pClass == String.class || pClass.isPrimitive()) {
>              return pValue.toString();
>          }
>
>         ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
>          if (pf != null) {
>              @SuppressWarnings("unchecked")
>              ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
>              if (prov != null) {
>                  return prov.toString(pValue);
>              }
>          }
>          return pValue.toString();
>      }
>
> "
> if it's just a string param it skips calling any custom param handlers.
>
> the other thing i noticed which maybe a bug is for ParamConverterProvider
> i thought the annotations would be populated so you can see what type of param it is
>
> public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)
>
>
> but in my tests both server side and client side
> arg2 was always null.
> i thought it might be set with actual anotations from the @PathParam declaration.
>
> I'll look into filters then in my case or interceptors.
> would you recommend a good location to do the param modifications as to be
> most efficient in the cxf chain of filters/interceptors.
>
> again my param is just a simple string and i want to apply this modification
> to only @PathParam params.. query and form i want to leave those as is.
> so I need a way to check a) is it a String variable only and b) is it a PathParam
> the modify/wrap/unwrap.
>
> thanks,
> parwiz
>
>
>
> ________________________________
>   From: Sergey Beryozkin <sb...@gmail.com>
> To: users@cxf.apache.org
> Sent: Tuesday, March 4, 2014 1:08 PM
> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>
>
> Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter
> can be used to override the request URI.
>
> JAX-RS 2.0 ParamConverterProvider can be used on the client and server
> sides, may give you a finer control...
>
> HTH, Sergey
>
> On 04/03/14 18:49, wizpar@yahoo.com wrote:
>> Hi,
>>
>> First of all I apologize if this has been asked before.
>> I wanted to ask for good solution that won't be too inefficient.
>> I do know about cxf interceptors and also request handlers method to
>> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>>
>> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
>> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>>
>> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
>> On server side I would like to revert those and unwrap and get back the original parameter.
>> @PathParam("test1") test1
>>
>> on client take test1 original value and add some extra characters to it
>> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>>
>> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>>
>> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>>
>> thanks,
>> parwiz
>>
>
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by Sergey Beryozkin <sb...@gmail.com>.
Right, I see it's only excluded on the client side, this and the fact 
the annotations are missed out needs to be fixed

Thanks, Sergey
On 04/03/14 21:36, wizpar@yahoo.com wrote:
> Thanks Sergey.
>
> i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.
>
> "
>      protected String convertParamValue(Object pValue) {
>          if (pValue == null) {
>              return null;
>          }
>          Class<?> pClass = pValue.getClass();
>          if (pClass == String.class || pClass.isPrimitive()) {
>              return pValue.toString();
>          }
>
>         ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
>          if (pf != null) {
>              @SuppressWarnings("unchecked")
>              ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
>              if (prov != null) {
>                  return prov.toString(pValue);
>              }
>          }
>          return pValue.toString();
>      }
>
> "
> if it's just a string param it skips calling any custom param handlers.
>
> the other thing i noticed which maybe a bug is for ParamConverterProvider
> i thought the annotations would be populated so you can see what type of param it is
>
> public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)
>
>
> but in my tests both server side and client side
> arg2 was always null.
> i thought it might be set with actual anotations from the @PathParam declaration.
>
> I'll look into filters then in my case or interceptors.
> would you recommend a good location to do the param modifications as to be
> most efficient in the cxf chain of filters/interceptors.
>
> again my param is just a simple string and i want to apply this modification
> to only @PathParam params.. query and form i want to leave those as is.
> so I need a way to check a) is it a String variable only and b) is it a PathParam
> the modify/wrap/unwrap.
>
> thanks,
> parwiz
>
>
>
> ________________________________
>   From: Sergey Beryozkin <sb...@gmail.com>
> To: users@cxf.apache.org
> Sent: Tuesday, March 4, 2014 1:08 PM
> Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
>
>
> Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter
> can be used to override the request URI.
>
> JAX-RS 2.0 ParamConverterProvider can be used on the client and server
> sides, may give you a finer control...
>
> HTH, Sergey
>
> On 04/03/14 18:49, wizpar@yahoo.com wrote:
>> Hi,
>>
>> First of all I apologize if this has been asked before.
>> I wanted to ask for good solution that won't be too inefficient.
>> I do know about cxf interceptors and also request handlers method to
>> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>>
>> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
>> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>>
>> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
>> On server side I would like to revert those and unwrap and get back the original parameter.
>> @PathParam("test1") test1
>>
>> on client take test1 original value and add some extra characters to it
>> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>>
>> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>>
>> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>>
>> thanks,
>> parwiz
>>
>
>


Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by wi...@yahoo.com.
Thanks Sergey.

i tried ParamConverterProvider but problem is it is skipped for param types of String... it will work with custom classes but since these params are just strings with special characters added or converted somehow it will not work.

"
    protected String convertParamValue(Object pValue) {
        if (pValue == null) {
            return null;
        }
        Class<?> pClass = pValue.getClass();
        if (pClass == String.class || pClass.isPrimitive()) {
            return pValue.toString();
        }

       ProviderFactory pf = ProviderFactory.getInstance(cfg.getBus());
        if (pf != null) {
            @SuppressWarnings("unchecked")
            ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass);
            if (prov != null) {
                return prov.toString(pValue);
            }
        }
        return pValue.toString();
    }

"
if it's just a string param it skips calling any custom param handlers.
 
the other thing i noticed which maybe a bug is for ParamConverterProvider
i thought the annotations would be populated so you can see what type of param it is

public <T> ParamConverter<T> getConverter(Class<T> cls, Type arg1, Annotation[] arg2)


but in my tests both server side and client side 
arg2 was always null.
i thought it might be set with actual anotations from the @PathParam declaration.

I'll look into filters then in my case or interceptors.
would you recommend a good location to do the param modifications as to be
most efficient in the cxf chain of filters/interceptors.

again my param is just a simple string and i want to apply this modification
to only @PathParam params.. query and form i want to leave those as is. 
so I need a way to check a) is it a String variable only and b) is it a PathParam
the modify/wrap/unwrap.

thanks,
parwiz



________________________________
 From: Sergey Beryozkin <sb...@gmail.com>
To: users@cxf.apache.org 
Sent: Tuesday, March 4, 2014 1:08 PM
Subject: Re: Advice on overwriting @PathParameters jax-rs and cxf proxies
 

Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter 
can be used to override the request URI.

JAX-RS 2.0 ParamConverterProvider can be used on the client and server 
sides, may give you a finer control...

HTH, Sergey

On 04/03/14 18:49, wizpar@yahoo.com wrote:
> Hi,
>
> First of all I apologize if this has been asked before.
> I wanted to ask for good solution that won't be too inefficient.
> I do know about cxf interceptors and also request handlers method to
> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>
> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>
> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
> On server side I would like to revert those and unwrap and get back the original parameter.
> @PathParam("test1") test1
>
> on client take test1 original value and add some extra characters to it
> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>
> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>
> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>
> thanks,
> parwiz
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: Advice on overwriting @PathParameters jax-rs and cxf proxies

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi, JAX-RS 2.0 ClientRequestFilter  and PreMatch ContainterRequestFilter 
can be used to override the request URI.

JAX-RS 2.0 ParamConverterProvider can be used on the client and server 
sides, may give you a finer control...

HTH, Sergey
On 04/03/14 18:49, wizpar@yahoo.com wrote:
> Hi,
>
> First of all I apologize if this has been asked before.
> I wanted to ask for good solution that won't be too inefficient.
> I do know about cxf interceptors and also request handlers method to
> add to chain of inbound/outbound but not sure what would be a good place so please give me some pointers/advice.
>
> We are using cxf jax-rs rest with jackson as our json serializer/deserializer.
> We are also using cxf java proxies on client side to call our code so we do have control over our callers and would like to apply a custom handling to these (yes I know it won't support per say web callers but the services are right now internal only and will be consumed only by java proxy client).
>
> On proxy/client side I would like to overwrite path parameters and do some custom modifications before it's handed it to server (say add some wrapping to it or extra characters .. maybe mask a password but other usages too)
> On server side I would like to revert those and unwrap and get back the original parameter.
> @PathParam("test1") test1
>
> on client take test1 original value and add some extra characters to it
> on server side remove the extra characters and then pass it on to the service method. Basically the java client and service impl code should not need to know about this nor juggly this portion.. all of it done in interceptors/request handlers prior to getting into service layer code and post leaving client caller.
>
> So should i extend JAXRSInInterceptor and do this there or creae a new interceptor of my own and add it to the chain (out on client side, in on server side).
>
> please advice if you have done similiar thing on your end. I noticed JAXRSInInterceptor does parameter settings so I would hoping I could tap into that and not redo that portion and slow down our services.
>
> thanks,
> parwiz
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com