-
Bug
-
Resolution: Done
-
Minor
-
3.14.0.Final, 3.15.0.Final
-
None
-
None
I have a project that uses resteasy-client version 3.x in a standalone application. This project just fine until version 3.13.2.Final. If I upgrade to version 3.14.0.Final I get an error whenever the server returns an error. The reason lies in ClientInvocation, and its use of WebApplicationExceptionWrapper.wrap. This method contains the following code:
final boolean originalBehavior = Boolean.parseBoolean(config.getValue(ResteasyContextParameters.RESTEASY_ORIGINAL_WEBAPPLICATIONEXCEPTION_BEHAVIOR, ResteasyConfig.SOURCE.SERVLET_CONTEXT, "false")); final boolean serverSide = ResteasyProviderFactory.searchContextData(Dispatcher.class) != null; if (originalBehavior || !serverSide) { return e; }
The first line eventually triggers a NoClassDefFoundError because it cannot find ServletContext. However, in a standalone application it's quite common to not have ServletContext available.
A possible solution is to check on serverSide before attempting to read from the ServletContext. For instance:
final boolean serverSide = ResteasyProviderFactory.searchContextData(Dispatcher.class) != null; if (!serverSide) { return e; } final boolean originalBehavior = Boolean.parseBoolean(config.getValue(ResteasyContextParameters.RESTEASY_ORIGINAL_WEBAPPLICATIONEXCEPTION_BEHAVIOR, ResteasyConfig.SOURCE.SERVLET_CONTEXT, "false")); if (originalBehavior) { return e; }
The logic is still the same - return the original exception if either originalBehavior is true or if serverSide is false. The difference is that originalBehavior is only evaluated if the client is running server side, and therefore also ServletContext is only used if the client is running server side.
- is incorporated by
-
WFLY-14499 Upgrade RESTEasy from 3.15.0.Final to 3.15.1.Final
- Closed
-
WFLY-14537 Upgrade to RestEasy 3.15.1.Final
- Closed