You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Vassilis Virvilis <v....@biovista.com> on 2014/10/17 16:35:46 UTC

jaxrs logging interceptor: get method name and parameter values

Hi,

I managed to install my own JAXRSInInterceptor and JAXRSOutInterceptor.

What I would like is to log the final method name and parameter values 
for logging purposes. I have done something similar for SOAP in the past 
but the crucial BindingOperationInfo is null in case of rest.

Any ideas?

     private String getMethod(Message message) {
         final BindingOperationInfo bop = 
message.getExchange().getBindingOperationInfo();
         if (bop != null) {
             final MethodDispatcher md = (MethodDispatcher) message
                     .getExchange().get(Service.class)
                     .get(MethodDispatcher.class.getName());

             Object parameters = message.getContent(List.class);
             if (parameters == null) {
                 parameters = message.getContent(Object.class);
             }

             return String.format("%s(%s)", md.getMethod(bop).getName(),
                 StringUtils.preetyPrintObject(new StringBuilder(), 
parameters,
                     -1));
         }
         final Method method = (Method) message
                 .get("org.apache.cxf.resource.method");
         if (method != null) {
             return method.getName();
         }
         return "unknown";
     }


     Vassilis Virvilis

-- 

__________________________________

Vassilis Virvilis Ph.D.
Head of IT
Biovista Inc.

US Offices
2421 Ivy Road
Charlottesville, VA 22903
USA
T: +1.434.971.1141
F: +1.434.971.1144

European Offices
34 Rodopoleos Street
Ellinikon, Athens 16777
GREECE
T: +30.210.9629848
F: +30.210.9647606

www.biovista.com

Biovista is a privately held biotechnology company that finds novel uses 
for existing drugs, and profiles their side effects using their 
mechanism of action. Biovista develops its own pipeline of drugs in CNS, 
oncology, auto-immune and rare diseases. Biovista is collaborating with 
biopharmaceutical companies on indication expansion and de-risking of 
their portfolios and with the FDA on adverse event prediction.



Re: jaxrs logging interceptor: get method name and parameter values

Posted by Vassilis Virvilis <v....@biovista.com>.
Hi,

Ok it worked.

Thanks for pointing me to the right direction.

      Vassilis

On 10/17/2014 09:38 PM, v.virvilis@biovista.com wrote:
> Hi,
>
> I don't want to customize anything. I just want to find the method name
> and arguments and log them in a generic manner so I don't have to put a
> log statement it in every service call.
>
> Looks like that JAXRSBeanValidationInInterceptor and its base class
> BeanValidationInInterceptor are gonna do the trick. I can't check right
> it now but it's the first thing I will check Monday morning.
>
> Thanks as always for the prompt answer.
>
>       Vassilis
>
>
> On 2014-10-17 12:43, Sergey Beryozkin wrote:
>> Hi
>>
>> Why do you have to customize these interceptors ?
>>
>> Have a look at
>> org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor
>>
>> it shows how all this info can be obtained...
>>
>> Cheers, Sergey
>> On 17/10/14 15:35, Vassilis Virvilis wrote:
>>> Hi,
>>>
>>> I managed to install my own JAXRSInInterceptor and JAXRSOutInterceptor.
>>>
>>> What I would like is to log the final method name and parameter values
>>> for logging purposes. I have done something similar for SOAP in the past
>>> but the crucial BindingOperationInfo is null in case of rest.
>>>
>>> Any ideas?
>>>
>>>      private String getMethod(Message message) {
>>>          final BindingOperationInfo bop =
>>> message.getExchange().getBindingOperationInfo();
>>>          if (bop != null) {
>>>              final MethodDispatcher md = (MethodDispatcher) message
>>>                      .getExchange().get(Service.class)
>>>                      .get(MethodDispatcher.class.getName());
>>>
>>>              Object parameters = message.getContent(List.class);
>>>              if (parameters == null) {
>>>                  parameters = message.getContent(Object.class);
>>>              }
>>>
>>>              return String.format("%s(%s)", md.getMethod(bop).getName(),
>>>                  StringUtils.preetyPrintObject(new StringBuilder(),
>>> parameters,
>>>                      -1));
>>>          }
>>>          final Method method = (Method) message
>>>                  .get("org.apache.cxf.resource.method");
>>>          if (method != null) {
>>>              return method.getName();
>>>          }
>>>          return "unknown";
>>>      }
>>>
>>>
>>>      Vassilis Virvilis
>>>
>
>

-- 

__________________________________

Vassilis Virvilis Ph.D.
Head of IT
Biovista Inc.

US Offices
2421 Ivy Road
Charlottesville, VA 22903
USA
T: +1.434.971.1141
F: +1.434.971.1144

European Offices
34 Rodopoleos Street
Ellinikon, Athens 16777
GREECE
T: +30.210.9629848
F: +30.210.9647606

www.biovista.com

Biovista is a privately held biotechnology company that finds novel uses 
for existing drugs, and profiles their side effects using their 
mechanism of action. Biovista develops its own pipeline of drugs in CNS, 
oncology, auto-immune and rare diseases. Biovista is collaborating with 
biopharmaceutical companies on indication expansion and de-risking of 
their portfolios and with the FDA on adverse event prediction.



Re: jaxrs logging interceptor: get method name and parameter values

Posted by v....@biovista.com.
Hi,

I don't want to customize anything. I just want to find the method name 
and arguments and log them in a generic manner so I don't have to put a 
log statement it in every service call.

Looks like that JAXRSBeanValidationInInterceptor and its base class 
BeanValidationInInterceptor are gonna do the trick. I can't check right 
it now but it's the first thing I will check Monday morning.

Thanks as always for the prompt answer.

      Vassilis


On 2014-10-17 12:43, Sergey Beryozkin wrote:
> Hi
> 
> Why do you have to customize these interceptors ?
> 
> Have a look at 
> org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor
> 
> it shows how all this info can be obtained...
> 
> Cheers, Sergey
> On 17/10/14 15:35, Vassilis Virvilis wrote:
>> Hi,
>> 
>> I managed to install my own JAXRSInInterceptor and 
>> JAXRSOutInterceptor.
>> 
>> What I would like is to log the final method name and parameter values
>> for logging purposes. I have done something similar for SOAP in the 
>> past
>> but the crucial BindingOperationInfo is null in case of rest.
>> 
>> Any ideas?
>> 
>>      private String getMethod(Message message) {
>>          final BindingOperationInfo bop =
>> message.getExchange().getBindingOperationInfo();
>>          if (bop != null) {
>>              final MethodDispatcher md = (MethodDispatcher) message
>>                      .getExchange().get(Service.class)
>>                      .get(MethodDispatcher.class.getName());
>> 
>>              Object parameters = message.getContent(List.class);
>>              if (parameters == null) {
>>                  parameters = message.getContent(Object.class);
>>              }
>> 
>>              return String.format("%s(%s)", 
>> md.getMethod(bop).getName(),
>>                  StringUtils.preetyPrintObject(new StringBuilder(),
>> parameters,
>>                      -1));
>>          }
>>          final Method method = (Method) message
>>                  .get("org.apache.cxf.resource.method");
>>          if (method != null) {
>>              return method.getName();
>>          }
>>          return "unknown";
>>      }
>> 
>> 
>>      Vassilis Virvilis
>> 

Re: jaxrs logging interceptor: get method name and parameter values

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

Why do you have to customize these interceptors ?

Have a look at 
org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor

it shows how all this info can be obtained...

Cheers, Sergey
On 17/10/14 15:35, Vassilis Virvilis wrote:
> Hi,
>
> I managed to install my own JAXRSInInterceptor and JAXRSOutInterceptor.
>
> What I would like is to log the final method name and parameter values
> for logging purposes. I have done something similar for SOAP in the past
> but the crucial BindingOperationInfo is null in case of rest.
>
> Any ideas?
>
>      private String getMethod(Message message) {
>          final BindingOperationInfo bop =
> message.getExchange().getBindingOperationInfo();
>          if (bop != null) {
>              final MethodDispatcher md = (MethodDispatcher) message
>                      .getExchange().get(Service.class)
>                      .get(MethodDispatcher.class.getName());
>
>              Object parameters = message.getContent(List.class);
>              if (parameters == null) {
>                  parameters = message.getContent(Object.class);
>              }
>
>              return String.format("%s(%s)", md.getMethod(bop).getName(),
>                  StringUtils.preetyPrintObject(new StringBuilder(),
> parameters,
>                      -1));
>          }
>          final Method method = (Method) message
>                  .get("org.apache.cxf.resource.method");
>          if (method != null) {
>              return method.getName();
>          }
>          return "unknown";
>      }
>
>
>      Vassilis Virvilis
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com