Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-906

ClassCastException in CXFServlet.loadSpringBus when context initialization fails

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0
    • 2.0.2
    • Core
    • None
    • using Spring Framework 2.1 m2

    Description

      CXFServlet.java line 136 obtains the Spring application context from the servlet context:

      if (ctx == null)

      { ctx = (ApplicationContext)svCtx .getAttribute("org.springframework.web.context.WebApplicationContext.ROOT"); }

      If the Spring application context failed to load however, Spring (somewhat inexplicably) sets this attribute to be the exception rather than the context. See org/springframework/web/context/ContextLoader.java line 202:

      catch (RuntimeException ex)

      { logger.error("Context initialization failed", ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; }

      To avoid repeated ClassCastExceptions that obscure the underlying problem with the Spring application context, CXFServlet should check the type of the attribute before attempting to cast to ApplicationContext:

      if (ctx == null) {
      Object ctxObject = svCtx
      .getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
      if (ctxObject instanceof ApplicationContext)

      { ctx = (ApplicationContext) ctxObject; }

      }

      Attachments

        Activity

          People

            njiang Willem Jiang
            karlgoldstein Karl Goldstein
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: