cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iris ding <irisdin...@gmail.com>
Subject Re: NPE when calling ServiceUnavailableException.getRetryTime()
Date Mon, 20 Apr 2015 03:17:19 GMT
Hi Sergey,

Let's take a look about the implementation details in
ServiceUnavailableException.getRetryTime():

public Date getRetryTime(Date requestTime)
  {
    RuntimeDelegate.HeaderDelegate dateDelegate;
    String value = getResponse().getHeaderString("Retry-After");
    if (value == null)
      return null;

    try
    {
      Long interval = Long.valueOf(Long.parseLong(value));
      return new Date(requestTime.getTime() + interval.longValue() * 1000L);
    }
    catch (NumberFormatException dateDelegate)
    {
      dateDelegate =
RuntimeDelegate.getInstance().createHeaderDelegate(Date.class);
    }
    return ((Date)dateDelegate.fromString(value));
  }

If you pass a Date object to it, it will go into this:

dateDelegate =
RuntimeDelegate.getInstance().createHeaderDelegate(Date.class);

org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl is CXF implementation for
RuntimeDelegate, In this class, you can see it does not register a provider
to handle Date type:

public RuntimeDelegateImpl() {
        headerProviders.put(MediaType.class, new MediaTypeHeaderProvider());
        headerProviders.put(CacheControl.class, new
CacheControlHeaderProvider());
        headerProviders.put(EntityTag.class, new EntityTagHeaderProvider());
        headerProviders.put(Cookie.class, new CookieHeaderProvider());
        headerProviders.put(NewCookie.class, new NewCookieHeaderProvider());

    }
So the NPE occurs and the API call fails.

The fix I proposed here is to add a DateHeaderProvider to handle Date type.

I do not think NPE here is correct. If so, does it mean we do not support
this API( ServiceUnavailableException.getRetryTime())  call at all?


Thanks & Best Regards,

Iris Ding




--
View this message in context: http://cxf.547215.n5.nabble.com/NPE-when-calling-ServiceUnavailableException-getRetryTime-tp5756231p5756249.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Mime
View raw message