You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Kiren Pillay <ki...@gmail.com> on 2012/01/30 15:24:12 UTC

JaxRS - Issue with Restful app aspect

Hi All,

I have a transaction aspect which returns an object called Response. The
Aspect works fine,  ie, when debugging it, the value at the return point is
exactly as expected and no exceptions are thrown. However, once this is
completed, I am getting a classCast exception with an error trace shown
below:

za.co.vodacom.pams.messaging.response.Response cannot be cast to
za.co.vodacom.pams.rechargerecords.RechargeRecords
$Proxy69.query(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)

At no point in my application code am I doing this cast. RechargeRecords is
a subclass of Payload, its a Jaxb generated object.

My problem is that I have no line numbers which tells me exactly where this
cast occurs. It doesn't look like its in my application code but rather
within the cxf AbstractInvoker's proxy. Any ideas to help me resolve this
problem (more specifically, finding where the it actually happens) ?

Regards
Kiren
CXF 2.5.1


@Around("execution(@za.co.pams.bs.PAMSTransaction * *(..))")
public Object recordStats(ProceedingJoinPoint point) throws Throwable {

Response response = null;

if (resultObject instanceof Response) {
response = (Response) resultObject;
}
else
if (Payload.class.isAssignableFrom(resultObject.getClass())) {

response = of.createResponse();

Payload payload = (Payload) resultObject;
response.setPayload(payload);
}

try {
populateSystemInfo(took, response);
response.setMethodSignature(point.getSignature().toString());

response.getRequestParams().addAll(list);

auditWorker.createSuccessfulAuditRecord(response);
}catch (Throwable e) {
         response.setDuration(0);  // Test code just to prove no exceptions
where thrown here
}

return response;
}

Re: JaxRS - Issue with Restful app aspect

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 30/01/12 16:35, Kiren Pillay wrote:
> The Response is actually our custom response object in a different
> namespace (import za.co.pams.messaging.response.Response) from our own
> packages, not one of the JAXRS objects.
>

It's not that important, it just appears that the type of the object 
that the JAXRS Invoker gets back is different from the type which is 
statically typed in the response method.

May be you can get the JAX-RS resource method return JAX-RS Response and 
then recreate it inside the handler by setting an alternative entity 
such as your own custom Response object on 
(JAXRS)ResponseBuilder.setEntity().build()

Sergey

> I will download the source and debug, hopefully something comes up!
>
> On Mon, Jan 30, 2012 at 6:15 PM, Sergey Beryozkin<sb...@gmail.com>wrote:
>
>> Hi
>>
>> On 30/01/12 16:08, Kiren Pillay wrote:
>>
>>> Hi Sergei,
>>>
>>> It is returning the correct type ( RechargeRecords ), and this gets
>>> handled
>>> via the aspect without any exception (debugged it with my own eyes), but
>>> an
>>> exception is getting thrown after the code completion from within the
>>> framework.
>>>
>>> /@Path("/fi/rechargeHistory")
>>> public interface RechargeHistoryService {
>>>
>>>      @GET
>>>      @Path("/query/msisdn/{msisdn}"**)
>>>      @Produces("text/xml")
>>>      public RechargeRecords query(@PathParam("msisdn") long msisdn,
>>> @QueryParam("fromDate") int fromDate, @QueryParam("toDate")int toDate)
>>> throws PAMSException;
>>>
>>> }
>>>
>>>
>> I'm assuming the aspect handler is run after the query(...) method returns
>> but before the JAX-RS runtime gets the control back, right ?
>>
>> Why do you wrap the response object from query(...) in JAX-RS Response
>> inside the handler ? I think this is what causes the problem
>>
>> May be you can provide a basic Maven-based test ? Or checkout the CXF
>> source and put a breakpoint in JAXRSInvoker ?
>>
>> Cheers, Sergey
>>
>>   On Mon, Jan 30, 2012 at 5:04 PM, Sergey Beryozkin<sberyozkin@gmail.com**
>>>> wrote:
>>>
>>>   Hi
>>>>
>>>>
>>>> On 30/01/12 14:24, Kiren Pillay wrote:
>>>>
>>>>   Hi All,
>>>>>
>>>>> I have a transaction aspect which returns an object called Response. The
>>>>> Aspect works fine,  ie, when debugging it, the value at the return point
>>>>> is
>>>>> exactly as expected and no exceptions are thrown. However, once this is
>>>>> completed, I am getting a classCast exception with an error trace shown
>>>>> below:
>>>>>
>>>>> za.co.vodacom.pams.messaging.****response.Response cannot be cast to
>>>>> za.co.vodacom.pams.****rechargerecords.****RechargeRecords
>>>>> $Proxy69.query(Unknown Source)
>>>>> sun.reflect.****NativeMethodAccessorImpl.****invoke0(Native Method)
>>>>> sun.reflect.****NativeMethodAccessorImpl.****invoke(**
>>>>> NativeMethodAccessorImpl.java:****39)
>>>>> sun.reflect.****DelegatingMethodAccessorImpl.****invoke(**
>>>>> DelegatingMethodAccessorImpl.****java:25)
>>>>> java.lang.reflect.Method.****invoke(Method.java:597)
>>>>> org.apache.cxf.service.****invoker.AbstractInvoker.****
>>>>> performInvocation(**
>>>>>
>>>>> AbstractInvoker.java:173)
>>>>>
>>>>> At no point in my application code am I doing this cast. RechargeRecords
>>>>> is
>>>>> a subclass of Payload, its a Jaxb generated object.
>>>>>
>>>>> My problem is that I have no line numbers which tells me exactly where
>>>>> this
>>>>> cast occurs. It doesn't look like its in my application code but rather
>>>>> within the cxf AbstractInvoker's proxy. Any ideas to help me resolve
>>>>> this
>>>>> problem (more specifically, finding where the it actually happens) ?
>>>>>
>>>>>
>>>> What does the actual resource method return ?
>>>> is it Response or some Payload instance ?
>>>>
>>>> It appears that the resource method is typed to return Payload while
>>>> the aspect returns Response so it confuses the runtime a bit...
>>>>
>>>> Cheers, Sergey
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>   Regards
>>>>> Kiren
>>>>> CXF 2.5.1
>>>>>
>>>>>
>>>>> @Around("execution(@za.co.****pams.bs.PAMSTransaction * *(..))")
>>>>> public Object recordStats(****ProceedingJoinPoint point) throws
>>>>> Throwable {
>>>>>
>>>>>
>>>>> Response response = null;
>>>>>
>>>>> if (resultObject instanceof Response) {
>>>>> response = (Response) resultObject;
>>>>> }
>>>>> else
>>>>> if (Payload.class.****isAssignableFrom(resultObject.****getClass())) {
>>>>>
>>>>>
>>>>> response = of.createResponse();
>>>>>
>>>>> Payload payload = (Payload) resultObject;
>>>>> response.setPayload(payload);
>>>>> }
>>>>>
>>>>> try {
>>>>> populateSystemInfo(took, response);
>>>>> response.setMethodSignature(****point.getSignature().toString(****));
>>>>>
>>>>> response.getRequestParams().****addAll(list);
>>>>>
>>>>> auditWorker.****createSuccessfulAuditRecord(****response);
>>>>>
>>>>> }catch (Throwable e) {
>>>>>           response.setDuration(0);  // Test code just to prove no
>>>>> exceptions
>>>>> where thrown here
>>>>> }
>>>>>
>>>>> return response;
>>>>> }
>>>>>
>>>>>
>>>>>
>>>> --
>>>> Sergey Beryozkin
>>>>
>>>> Talend Community Coders
>>>> http://coders.talend.com/
>>>>
>>>> Blog: http://sberyozkin.blogspot.com
>>>>
>>>>
>>>
>

Re: JaxRS - Issue with Restful app aspect

Posted by Kiren Pillay <ki...@gmail.com>.
The Response is actually our custom response object in a different
namespace (import za.co.pams.messaging.response.Response) from our own
packages, not one of the JAXRS objects.

I will download the source and debug, hopefully something comes up!

On Mon, Jan 30, 2012 at 6:15 PM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi
>
> On 30/01/12 16:08, Kiren Pillay wrote:
>
>> Hi Sergei,
>>
>> It is returning the correct type ( RechargeRecords ), and this gets
>> handled
>> via the aspect without any exception (debugged it with my own eyes), but
>> an
>> exception is getting thrown after the code completion from within the
>> framework.
>>
>> /@Path("/fi/rechargeHistory")
>> public interface RechargeHistoryService {
>>
>>     @GET
>>     @Path("/query/msisdn/{msisdn}"**)
>>     @Produces("text/xml")
>>     public RechargeRecords query(@PathParam("msisdn") long msisdn,
>> @QueryParam("fromDate") int fromDate, @QueryParam("toDate")int toDate)
>> throws PAMSException;
>>
>> }
>>
>>
> I'm assuming the aspect handler is run after the query(...) method returns
> but before the JAX-RS runtime gets the control back, right ?
>
> Why do you wrap the response object from query(...) in JAX-RS Response
> inside the handler ? I think this is what causes the problem
>
> May be you can provide a basic Maven-based test ? Or checkout the CXF
> source and put a breakpoint in JAXRSInvoker ?
>
> Cheers, Sergey
>
>  On Mon, Jan 30, 2012 at 5:04 PM, Sergey Beryozkin<sberyozkin@gmail.com**
>> >wrote:
>>
>>  Hi
>>>
>>>
>>> On 30/01/12 14:24, Kiren Pillay wrote:
>>>
>>>  Hi All,
>>>>
>>>> I have a transaction aspect which returns an object called Response. The
>>>> Aspect works fine,  ie, when debugging it, the value at the return point
>>>> is
>>>> exactly as expected and no exceptions are thrown. However, once this is
>>>> completed, I am getting a classCast exception with an error trace shown
>>>> below:
>>>>
>>>> za.co.vodacom.pams.messaging.****response.Response cannot be cast to
>>>> za.co.vodacom.pams.****rechargerecords.****RechargeRecords
>>>> $Proxy69.query(Unknown Source)
>>>> sun.reflect.****NativeMethodAccessorImpl.****invoke0(Native Method)
>>>> sun.reflect.****NativeMethodAccessorImpl.****invoke(**
>>>> NativeMethodAccessorImpl.java:****39)
>>>> sun.reflect.****DelegatingMethodAccessorImpl.****invoke(**
>>>> DelegatingMethodAccessorImpl.****java:25)
>>>> java.lang.reflect.Method.****invoke(Method.java:597)
>>>> org.apache.cxf.service.****invoker.AbstractInvoker.****
>>>> performInvocation(**
>>>>
>>>> AbstractInvoker.java:173)
>>>>
>>>> At no point in my application code am I doing this cast. RechargeRecords
>>>> is
>>>> a subclass of Payload, its a Jaxb generated object.
>>>>
>>>> My problem is that I have no line numbers which tells me exactly where
>>>> this
>>>> cast occurs. It doesn't look like its in my application code but rather
>>>> within the cxf AbstractInvoker's proxy. Any ideas to help me resolve
>>>> this
>>>> problem (more specifically, finding where the it actually happens) ?
>>>>
>>>>
>>> What does the actual resource method return ?
>>> is it Response or some Payload instance ?
>>>
>>> It appears that the resource method is typed to return Payload while
>>> the aspect returns Response so it confuses the runtime a bit...
>>>
>>> Cheers, Sergey
>>>
>>>
>>>
>>>
>>>
>>>
>>>  Regards
>>>> Kiren
>>>> CXF 2.5.1
>>>>
>>>>
>>>> @Around("execution(@za.co.****pams.bs.PAMSTransaction * *(..))")
>>>> public Object recordStats(****ProceedingJoinPoint point) throws
>>>> Throwable {
>>>>
>>>>
>>>> Response response = null;
>>>>
>>>> if (resultObject instanceof Response) {
>>>> response = (Response) resultObject;
>>>> }
>>>> else
>>>> if (Payload.class.****isAssignableFrom(resultObject.****getClass())) {
>>>>
>>>>
>>>> response = of.createResponse();
>>>>
>>>> Payload payload = (Payload) resultObject;
>>>> response.setPayload(payload);
>>>> }
>>>>
>>>> try {
>>>> populateSystemInfo(took, response);
>>>> response.setMethodSignature(****point.getSignature().toString(****));
>>>>
>>>> response.getRequestParams().****addAll(list);
>>>>
>>>> auditWorker.****createSuccessfulAuditRecord(****response);
>>>>
>>>> }catch (Throwable e) {
>>>>          response.setDuration(0);  // Test code just to prove no
>>>> exceptions
>>>> where thrown here
>>>> }
>>>>
>>>> return response;
>>>> }
>>>>
>>>>
>>>>
>>> --
>>> Sergey Beryozkin
>>>
>>> Talend Community Coders
>>> http://coders.talend.com/
>>>
>>> Blog: http://sberyozkin.blogspot.com
>>>
>>>
>>

Re: JaxRS - Issue with Restful app aspect

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 30/01/12 16:08, Kiren Pillay wrote:
> Hi Sergei,
>
> It is returning the correct type ( RechargeRecords ), and this gets handled
> via the aspect without any exception (debugged it with my own eyes), but an
> exception is getting thrown after the code completion from within the
> framework.
>
> /@Path("/fi/rechargeHistory")
> public interface RechargeHistoryService {
>
>      @GET
>      @Path("/query/msisdn/{msisdn}")
>      @Produces("text/xml")
>      public RechargeRecords query(@PathParam("msisdn") long msisdn,
> @QueryParam("fromDate") int fromDate, @QueryParam("toDate")int toDate)
> throws PAMSException;
>
> }
>

I'm assuming the aspect handler is run after the query(...) method 
returns but before the JAX-RS runtime gets the control back, right ?

Why do you wrap the response object from query(...) in JAX-RS Response 
inside the handler ? I think this is what causes the problem

May be you can provide a basic Maven-based test ? Or checkout the CXF 
source and put a breakpoint in JAXRSInvoker ?

Cheers, Sergey

> On Mon, Jan 30, 2012 at 5:04 PM, Sergey Beryozkin<sb...@gmail.com>wrote:
>
>> Hi
>>
>>
>> On 30/01/12 14:24, Kiren Pillay wrote:
>>
>>> Hi All,
>>>
>>> I have a transaction aspect which returns an object called Response. The
>>> Aspect works fine,  ie, when debugging it, the value at the return point
>>> is
>>> exactly as expected and no exceptions are thrown. However, once this is
>>> completed, I am getting a classCast exception with an error trace shown
>>> below:
>>>
>>> za.co.vodacom.pams.messaging.**response.Response cannot be cast to
>>> za.co.vodacom.pams.**rechargerecords.**RechargeRecords
>>> $Proxy69.query(Unknown Source)
>>> sun.reflect.**NativeMethodAccessorImpl.**invoke0(Native Method)
>>> sun.reflect.**NativeMethodAccessorImpl.**invoke(**
>>> NativeMethodAccessorImpl.java:**39)
>>> sun.reflect.**DelegatingMethodAccessorImpl.**invoke(**
>>> DelegatingMethodAccessorImpl.**java:25)
>>> java.lang.reflect.Method.**invoke(Method.java:597)
>>> org.apache.cxf.service.**invoker.AbstractInvoker.**performInvocation(**
>>> AbstractInvoker.java:173)
>>>
>>> At no point in my application code am I doing this cast. RechargeRecords
>>> is
>>> a subclass of Payload, its a Jaxb generated object.
>>>
>>> My problem is that I have no line numbers which tells me exactly where
>>> this
>>> cast occurs. It doesn't look like its in my application code but rather
>>> within the cxf AbstractInvoker's proxy. Any ideas to help me resolve this
>>> problem (more specifically, finding where the it actually happens) ?
>>>
>>
>> What does the actual resource method return ?
>> is it Response or some Payload instance ?
>>
>> It appears that the resource method is typed to return Payload while
>> the aspect returns Response so it confuses the runtime a bit...
>>
>> Cheers, Sergey
>>
>>
>>
>>
>>
>>
>>> Regards
>>> Kiren
>>> CXF 2.5.1
>>>
>>>
>>> @Around("execution(@za.co.**pams.bs.PAMSTransaction * *(..))")
>>> public Object recordStats(**ProceedingJoinPoint point) throws Throwable {
>>>
>>> Response response = null;
>>>
>>> if (resultObject instanceof Response) {
>>> response = (Response) resultObject;
>>> }
>>> else
>>> if (Payload.class.**isAssignableFrom(resultObject.**getClass())) {
>>>
>>> response = of.createResponse();
>>>
>>> Payload payload = (Payload) resultObject;
>>> response.setPayload(payload);
>>> }
>>>
>>> try {
>>> populateSystemInfo(took, response);
>>> response.setMethodSignature(**point.getSignature().toString(**));
>>>
>>> response.getRequestParams().**addAll(list);
>>>
>>> auditWorker.**createSuccessfulAuditRecord(**response);
>>> }catch (Throwable e) {
>>>           response.setDuration(0);  // Test code just to prove no
>>> exceptions
>>> where thrown here
>>> }
>>>
>>> return response;
>>> }
>>>
>>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>> Blog: http://sberyozkin.blogspot.com
>>
>

Re: JaxRS - Issue with Restful app aspect

Posted by Kiren Pillay <ki...@gmail.com>.
Hi Sergei,

It is returning the correct type ( RechargeRecords ), and this gets handled
via the aspect without any exception (debugged it with my own eyes), but an
exception is getting thrown after the code completion from within the
framework.

/@Path("/fi/rechargeHistory")
public interface RechargeHistoryService {

    @GET
    @Path("/query/msisdn/{msisdn}")
    @Produces("text/xml")
    public RechargeRecords query(@PathParam("msisdn") long msisdn,
@QueryParam("fromDate") int fromDate, @QueryParam("toDate")int toDate)
throws PAMSException;

}

On Mon, Jan 30, 2012 at 5:04 PM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi
>
>
> On 30/01/12 14:24, Kiren Pillay wrote:
>
>> Hi All,
>>
>> I have a transaction aspect which returns an object called Response. The
>> Aspect works fine,  ie, when debugging it, the value at the return point
>> is
>> exactly as expected and no exceptions are thrown. However, once this is
>> completed, I am getting a classCast exception with an error trace shown
>> below:
>>
>> za.co.vodacom.pams.messaging.**response.Response cannot be cast to
>> za.co.vodacom.pams.**rechargerecords.**RechargeRecords
>> $Proxy69.query(Unknown Source)
>> sun.reflect.**NativeMethodAccessorImpl.**invoke0(Native Method)
>> sun.reflect.**NativeMethodAccessorImpl.**invoke(**
>> NativeMethodAccessorImpl.java:**39)
>> sun.reflect.**DelegatingMethodAccessorImpl.**invoke(**
>> DelegatingMethodAccessorImpl.**java:25)
>> java.lang.reflect.Method.**invoke(Method.java:597)
>> org.apache.cxf.service.**invoker.AbstractInvoker.**performInvocation(**
>> AbstractInvoker.java:173)
>>
>> At no point in my application code am I doing this cast. RechargeRecords
>> is
>> a subclass of Payload, its a Jaxb generated object.
>>
>> My problem is that I have no line numbers which tells me exactly where
>> this
>> cast occurs. It doesn't look like its in my application code but rather
>> within the cxf AbstractInvoker's proxy. Any ideas to help me resolve this
>> problem (more specifically, finding where the it actually happens) ?
>>
>
> What does the actual resource method return ?
> is it Response or some Payload instance ?
>
> It appears that the resource method is typed to return Payload while
> the aspect returns Response so it confuses the runtime a bit...
>
> Cheers, Sergey
>
>
>
>
>
>
>> Regards
>> Kiren
>> CXF 2.5.1
>>
>>
>> @Around("execution(@za.co.**pams.bs.PAMSTransaction * *(..))")
>> public Object recordStats(**ProceedingJoinPoint point) throws Throwable {
>>
>> Response response = null;
>>
>> if (resultObject instanceof Response) {
>> response = (Response) resultObject;
>> }
>> else
>> if (Payload.class.**isAssignableFrom(resultObject.**getClass())) {
>>
>> response = of.createResponse();
>>
>> Payload payload = (Payload) resultObject;
>> response.setPayload(payload);
>> }
>>
>> try {
>> populateSystemInfo(took, response);
>> response.setMethodSignature(**point.getSignature().toString(**));
>>
>> response.getRequestParams().**addAll(list);
>>
>> auditWorker.**createSuccessfulAuditRecord(**response);
>> }catch (Throwable e) {
>>          response.setDuration(0);  // Test code just to prove no
>> exceptions
>> where thrown here
>> }
>>
>> return response;
>> }
>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com
>

Re: JaxRS - Issue with Restful app aspect

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

On 30/01/12 14:24, Kiren Pillay wrote:
> Hi All,
>
> I have a transaction aspect which returns an object called Response. The
> Aspect works fine,  ie, when debugging it, the value at the return point is
> exactly as expected and no exceptions are thrown. However, once this is
> completed, I am getting a classCast exception with an error trace shown
> below:
>
> za.co.vodacom.pams.messaging.response.Response cannot be cast to
> za.co.vodacom.pams.rechargerecords.RechargeRecords
> $Proxy69.query(Unknown Source)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> java.lang.reflect.Method.invoke(Method.java:597)
> org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)
>
> At no point in my application code am I doing this cast. RechargeRecords is
> a subclass of Payload, its a Jaxb generated object.
>
> My problem is that I have no line numbers which tells me exactly where this
> cast occurs. It doesn't look like its in my application code but rather
> within the cxf AbstractInvoker's proxy. Any ideas to help me resolve this
> problem (more specifically, finding where the it actually happens) ?

What does the actual resource method return ?
is it Response or some Payload instance ?

It appears that the resource method is typed to return Payload while
the aspect returns Response so it confuses the runtime a bit...

Cheers, Sergey




>
> Regards
> Kiren
> CXF 2.5.1
>
>
> @Around("execution(@za.co.pams.bs.PAMSTransaction * *(..))")
> public Object recordStats(ProceedingJoinPoint point) throws Throwable {
>
> Response response = null;
>
> if (resultObject instanceof Response) {
> response = (Response) resultObject;
> }
> else
> if (Payload.class.isAssignableFrom(resultObject.getClass())) {
>
> response = of.createResponse();
>
> Payload payload = (Payload) resultObject;
> response.setPayload(payload);
> }
>
> try {
> populateSystemInfo(took, response);
> response.setMethodSignature(point.getSignature().toString());
>
> response.getRequestParams().addAll(list);
>
> auditWorker.createSuccessfulAuditRecord(response);
> }catch (Throwable e) {
>           response.setDuration(0);  // Test code just to prove no exceptions
> where thrown here
> }
>
> return response;
> }
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com