You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by jordan <zh...@cn.ibm.com> on 2015/02/13 04:23:36 UTC

Report NPE when use custom callback in client async request

Hi,

I found a problem when I use cxf client. could you please take a look. :)

I would like to create a callback instance for my client async request. It's
ok if I create instance by new an InvocationCallback :
InvocationCallback<String> callback = new InvocationCallback<String>() {
...


But if I use an abstract inner class
abstract class Callback<RESPONSE> implements InvocationCallback<RESPONSE> {
...

And the create instance by using this new Callback():
InvocationCallback<String> callback = new Callback<String>() {
...

Because RESPONSE is a generic type, cxf doesn't handle it, so report NPE.

The exception stack is:
[javatest.batch] java.lang.RuntimeException:
javax.ws.rs.ProcessingException: java.lang.NullPointerException
[javatest.batch]        at
com.sun.ts.tests.jaxrs.ee.rs.client.asyncinvoker.JAXRSClient$Callback.failed(JAXRSClient.java:2834)
[javatest.batch]        at
org.apache.cxf.jaxrs.client.JaxrsClientCallback.handleException(JaxrsClientCallback.java:90)
[javatest.batch]        at
org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:1020)
[javatest.batch]        at
org.apache.cxf.jaxrs.client.WebClient.access$100(WebClient.java:81)
[javatest.batch]        at
org.apache.cxf.jaxrs.client.WebClient$ClientAsyncResponseInterceptor.handleMessage(WebClient.java:1296)
[javatest.batch]        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
[javatest.batch]        at
org.apache.cxf.jaxrs.client.ClientMessageObserver.onMessage(ClientMessageObserver.java:56)
[javatest.batch]        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1638)
[javatest.batch]        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1145)
[javatest.batch]        at
org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)
[javatest.batch]        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1157)
[javatest.batch]        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
[javatest.batch]        at
org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)
[javatest.batch]        at java.lang.Thread.run(Thread.java:863)
[javatest.batch] Caused by: javax.ws.rs.ProcessingException:
java.lang.NullPointerException
[javatest.batch]        at
org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1185)
[javatest.batch]        at
org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:1016)
[javatest.batch]        ... 11 more
[javatest.batch] Caused by: java.lang.NullPointerException
[javatest.batch]        at java.lang.Class.isAssignableFrom(Native Method)
[javatest.batch]        at
org.apache.cxf.jaxrs.provider.BinaryDataProvider.isReadable(BinaryDataProvider.java:65)
[javatest.batch]        at
org.apache.cxf.jaxrs.provider.ProviderFactory.matchesReaderCriterias(ProviderFactory.java:671)
[javatest.batch]        at
org.apache.cxf.jaxrs.provider.ProviderFactory.chooseMessageReader(ProviderFactory.java:635)
[javatest.batch]        at
org.apache.cxf.jaxrs.provider.ProviderFactory.createMessageBodyReader(ProviderFactory.java:416)
[javatest.batch]        at
org.apache.cxf.jaxrs.provider.ProviderFactory.createMessageBodyReader(ProviderFactory.java:426)
[javatest.batch]        at
org.apache.cxf.jaxrs.provider.ProviderFactory.createMessageBodyReaderInterceptor(ProviderFactory.java:340)
[javatest.batch]        at
org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:357)
[javatest.batch]        at
org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:499)
[javatest.batch]        at
org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1166)


I took a look of the cxf code, and think something may not good in WebClient
class:

protected <T> Future<T> doInvokeAsyncCallback(String httpMethod, Object
body, Class<?> requestClass, Type inType, InvocationCallback<T> callback)
  {
    Type outType = getCallbackType(callback);
    Class respClass = null;
    if (outType instanceof Class) {
      respClass = (Class)outType;
    } else if (outType instanceof ParameterizedType) {
      ParameterizedType pt = (ParameterizedType)outType;
      if (pt.getRawType() instanceof Class) {
        respClass = (Class)pt.getRawType();
        outType = InjectionUtils.getActualType(pt);
      }
    } 

    return doInvokeAsync(httpMethod, body, requestClass, inType, respClass,
outType, callback);
  }

Because RESPONSE is a generic type, so outType cannot be handle so in these
code is null, so pass null to next, then report NPE. I'm not sure if need
add a else condition to check avoid NPE.

That what I see, hope it's helpful. Pls let me know if you have any
question.

Thanks a lot! :)



--
View this message in context: http://cxf.547215.n5.nabble.com/Report-NPE-when-use-custom-callback-in-client-async-request-tp5754325.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Report NPE when use custom callback in client async request

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

Fixed as part of CXF-6260 (no TypeVariable was introspected), thanks for 
reporting this issue

Cheers, Sergey
On 13/02/15 03:23, jordan wrote:
> Hi,
>
> I found a problem when I use cxf client. could you please take a look. :)
>
> I would like to create a callback instance for my client async request. It's
> ok if I create instance by new an InvocationCallback :
> InvocationCallback<String> callback = new InvocationCallback<String>() {
> ...
>
>
> But if I use an abstract inner class
> abstract class Callback<RESPONSE> implements InvocationCallback<RESPONSE> {
> ...
>
> And the create instance by using this new Callback():
> InvocationCallback<String> callback = new Callback<String>() {
> ...
>
> Because RESPONSE is a generic type, cxf doesn't handle it, so report NPE.
>
> The exception stack is:
> [javatest.batch] java.lang.RuntimeException:
> javax.ws.rs.ProcessingException: java.lang.NullPointerException
> [javatest.batch]        at
> com.sun.ts.tests.jaxrs.ee.rs.client.asyncinvoker.JAXRSClient$Callback.failed(JAXRSClient.java:2834)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.JaxrsClientCallback.handleException(JaxrsClientCallback.java:90)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:1020)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.WebClient.access$100(WebClient.java:81)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.WebClient$ClientAsyncResponseInterceptor.handleMessage(WebClient.java:1296)
> [javatest.batch]        at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.ClientMessageObserver.onMessage(ClientMessageObserver.java:56)
> [javatest.batch]        at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1638)
> [javatest.batch]        at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1145)
> [javatest.batch]        at
> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)
> [javatest.batch]        at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1157)
> [javatest.batch]        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
> [javatest.batch]        at
> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)
> [javatest.batch]        at java.lang.Thread.run(Thread.java:863)
> [javatest.batch] Caused by: javax.ws.rs.ProcessingException:
> java.lang.NullPointerException
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1185)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:1016)
> [javatest.batch]        ... 11 more
> [javatest.batch] Caused by: java.lang.NullPointerException
> [javatest.batch]        at java.lang.Class.isAssignableFrom(Native Method)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.provider.BinaryDataProvider.isReadable(BinaryDataProvider.java:65)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.provider.ProviderFactory.matchesReaderCriterias(ProviderFactory.java:671)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.provider.ProviderFactory.chooseMessageReader(ProviderFactory.java:635)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.provider.ProviderFactory.createMessageBodyReader(ProviderFactory.java:416)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.provider.ProviderFactory.createMessageBodyReader(ProviderFactory.java:426)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.provider.ProviderFactory.createMessageBodyReaderInterceptor(ProviderFactory.java:340)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:357)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:499)
> [javatest.batch]        at
> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1166)
>
>
> I took a look of the cxf code, and think something may not good in WebClient
> class:
>
> protected <T> Future<T> doInvokeAsyncCallback(String httpMethod, Object
> body, Class<?> requestClass, Type inType, InvocationCallback<T> callback)
>    {
>      Type outType = getCallbackType(callback);
>      Class respClass = null;
>      if (outType instanceof Class) {
>        respClass = (Class)outType;
>      } else if (outType instanceof ParameterizedType) {
>        ParameterizedType pt = (ParameterizedType)outType;
>        if (pt.getRawType() instanceof Class) {
>          respClass = (Class)pt.getRawType();
>          outType = InjectionUtils.getActualType(pt);
>        }
>      }
>
>      return doInvokeAsync(httpMethod, body, requestClass, inType, respClass,
> outType, callback);
>    }
>
> Because RESPONSE is a generic type, so outType cannot be handle so in these
> code is null, so pass null to next, then report NPE. I'm not sure if need
> add a else condition to check avoid NPE.
>
> That what I see, hope it's helpful. Pls let me know if you have any
> question.
>
> Thanks a lot! :)
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Report-NPE-when-use-custom-callback-in-client-async-request-tp5754325.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>