2

I have a Java 1.4 web app that uses Hessian to make web service calls. I'm trying to write it as robust and transparent as possible. I don't want any hessian exceptions to make it out of my delegate class when calling the proxy. I want to be able to catch any Hessian runtime exceptions, unwrap them and either rethrow some of the major exceptions (e.g., ConnectException) or rewrap them in another exception. But finding these exceptions are a bit of a challenge.

Every method I have in my delegating class has this sort of structure.

public MyResult myMethod(MyArgsType myArgs)
        throws ConnectException
{
    try
    {
        return proxy.myMethod(myArgs);
    }
    catch (HessianRuntimeException ex)
    {
        Throwable cause = ex.getCause();
        if (cause instanceof ConnectException)
            throw (ConnectException)cause;
        throw new MyRuntimeException(cause);
    }
}

This has been working fine in my own tests but some other runtime exceptions are making it out and I'm missing them. For instance, we recently found that it may throw a HessianConnectionException caused by a SocketException (the remote server was down). I was fully expecting that what I currently have would have caught that. The HessianConnectionException doesn't derive from the HessianRuntimeException so now I have to add that exception to be caught.

public MyResult myMethod(MyArgsType myArgs)
        throws SocketException, ConnectException
{
    try
    {
        return proxy.myMethod(myArgs);
    }
    catch (HessianException ex) // HessianConnectionException derives from HessianException
    {
        Throwable cause = ex.getCause();
        if (cause instanceof SocketException)
            throw (SocketException)cause;
        throw new MyRuntimeException(cause);
    }
    catch (HessianRuntimeException ex)
    {
        Throwable cause = ex.getCause();
        if (cause instanceof ConnectException)
            throw (ConnectException)cause;
        throw new MyRuntimeException(cause);
    }
}

Ok that's fine with me, it had to be done... but where does it end? I can't find any documentation on what other runtime exceptions that I need to be aware of or any of their underlying causes.

I'm hoping just catching HessianException and HessianRuntimeException would be enough since those are the only runtime exceptions that I can find listed here. But with these newly found issues, I'm not sure what exceptions I would want to unwrap since it seems like it's a mixed bag (as far as I knew, SocketException and ConnectException were different representations of the same problem).

Is there any documentation in what runtime exceptions are thrown when calling methods through the proxy and all their underlying causes?

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272

1 Answers1

0

I assume you have done web searches etc., so here is a fallback position in case you don't find the documentation you are looking for.

After your existing catches, catch RuntimeException. Test whether the Exception's class name begins with "Hessian" and/or check its package name. If it is not Hessian-originated, rethrow.

After you know it is a Hessian exception you can do something similar to your current strategy, looking through the cause chain for something that makes sense in your context or at least is from a non-Hessian package.

Patricia Shanahan
  • 25,849
  • 4
  • 38
  • 75