Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-2799

resteasy-client-3.15.0.Final requires servlet-spec

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • 3.15.1.Final
    • 3.14.0.Final, 3.15.0.Final
    • None
    • None
    • Hide
      • Unpack resteasy-2799.zip
      • In the folder where the file was unpacked, execute the following:
        mvn verify
      • Observe that a NoClassDefFoundError is thrown.

      Execute the following to see no exception:

      mvn verify -Dversion.resteasy=3.13.2.Final
      Show
      Unpack resteasy-2799.zip In the folder where the file was unpacked, execute the following: mvn verify Observe that a NoClassDefFoundError is thrown. Execute the following to see no exception: mvn verify -Dversion.resteasy=3.13.2.Final
    • Undefined

      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.

            jperkins-rhn James Perkins
            rob.spoor@isaac.nl Rob Spoor (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: