javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-1

ServletContext/PortletContext incompatibility

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: 1.0
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      1

      Description

      In com.sun.faces.application.ApplicationAssociate there are assumptions on
      context object being ServletContext. in case of FacesPortlet use,
      PortletContext object is passed here. Not sure what's the solution:

      1. return ServletContext instead of PortletContext in
      com.sun.faces.portlet.ExternalContextImpl.getContext
      2. remove ServletContext assumption in ApplicationAssociate

      now the result is ClassCastException in ApplicationAssociate.getInstance. i've
      made temporary patch as in p.1 and it seems to work...

      i'm using Novell Extend Director as portlet container. maybe in other
      containers PortletContext implementation class implements ServletContext as
      well and this might work. however, afaik it's not required in Portlet API
      specification.

        Activity

        Hide
        Manfred Riem added a comment -

        Closing out issue

        Show
        Manfred Riem added a comment - Closing out issue
        Hide
        jayashri added a comment -

        Jason verified that this fix works. So, I am closing this issue.

        Show
        jayashri added a comment - Jason verified that this fix works. So, I am closing this issue.
        Hide
        Ed Burns added a comment -

        r=edburns

        Show
        Ed Burns added a comment - r=edburns
        Hide
        jayashri added a comment -

        Fix for Issue 1
        Remove explicit casts and dependencies to ServletContext.

        M src/com/sun/faces/application/ApplicationAssociate.java
        Deal with ExternalContext that wraps ServletContext to avoid
        dependencies on servlet based environment.

        M src/com/sun/faces/application/NavigationHandlerImpl.java
        M src/com/sun/faces/application/ViewHandlerImpl.java
        Pass in ExternalContext that wraps ServletContext

        M src/com/sun/faces/config/ConfigureListener.java
        create a public inner class on ExternalContext that wraps
        ServletContext. This is because when contextInitialized() is
        invoked, FacesContext and ExternalContext do not exist.
        So this wrapper is created solely for the purpose of accessing
        ServletContext in a environment independent manner. So
        except ServletContext related methods, other methods are
        left unimplemented.

        M src/com/sun/faces/el/ValueBindingImpl.java
        M src/com/sun/faces/el/VariableResolverImpl.java
        M src/com/sun/faces/util/Util.java
        Remove unused method releaseFactoriesAndDefaultRenderkit()

        M test/com/sun/faces/FacesTestCaseService.java
        M test/com/sun/faces/application/TestApplicationFactoryImpl.java
        M test/com/sun/faces/application/TestNavigationHandler.java
        M test/com/sun/faces/config/ConfigFileTestCase.java
        M test/com/sun/faces/config/StoreServletContext.java
        M test/com/sun/faces/el/TestVariableResolverImpl.java
        update tests for the above changes.

        SECTION: DIFFS
        Index: src/com/sun/faces/application/ApplicationAssociate.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ApplicationAssociate.java,v
        retrieving revision 1.2
        diff -u -r1.2 ApplicationAssociate.java
        — src/com/sun/faces/application/ApplicationAssociate.java 11 May 2004
        21:35:23 -0000 1.2
        +++ src/com/sun/faces/application/ApplicationAssociate.java 15 Jul 2004 22:00:10
        -0000
        @@ -22,9 +22,8 @@
        import java.util.Comparator;
        import java.util.Collections;

        -import javax.servlet.ServletContext;
        -
        import javax.faces.context.FacesContext;
        +import javax.faces.context.ExternalContext;
        import javax.faces.FacesException;

        import com.sun.faces.config.ManagedBeanFactory;
        @@ -96,17 +95,17 @@

        public ApplicationAssociate(ApplicationImpl appImpl) {
        app = appImpl;

        • ServletContext servletContext = null;
        • if (null == (servletContext =
        • ConfigureListener.getServletContextDuringInitialize())) {
          + ExternalContext externalContext = null;
          + if (null == (externalContext =
          + ConfigureListener.getExternalContextDuringInitialize())) { // PENDING I18N throw new IllegalStateException("ApplicationAssociate ctor not called in same callstack as ConfigureListener.contextInitialized()"); }

          // PENDING I18N

        • if (null != servletContext.getAttribute(ASSOCIATE_KEY)) {
          + if (null != externalContext.getApplicationMap().get(ASSOCIATE_KEY)) { throw new IllegalStateException("ApplicationAssociate already exists for this webapp"); }
        • servletContext.setAttribute(ASSOCIATE_KEY, this);
          + externalContext.getApplicationMap().put(ASSOCIATE_KEY, this);
          managedBeanFactoriesMap = new HashMap();
          caseListMap = new HashMap();
          wildcardMatchList = new TreeSet(new SortIt());
          @@ -114,13 +113,17 @@
          expressionInfoInstancePool = new InstancePool();
          }
        • public static ApplicationAssociate getInstance(Object servletContext) {
          + public static ApplicationAssociate getInstance(ExternalContext
          + externalContext) { + Map applicationMap = externalContext.getApplicationMap(); return ((ApplicationAssociate) - ((ServletContext)servletContext).getAttribute(ASSOCIATE_KEY)); + applicationMap.get(ASSOCIATE_KEY)); }
        • public static void clearInstance(Object servletContext) {
        • ((ServletContext)servletContext).removeAttribute(ASSOCIATE_KEY);
          + public static void clearInstance(ExternalContext
          + externalContext) { + Map applicationMap = externalContext.getApplicationMap(); + applicationMap.remove(ASSOCIATE_KEY); }

        Index: src/com/sun/faces/application/NavigationHandlerImpl.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/NavigationHandlerImpl.java,v
        retrieving revision 1.33
        diff -u -r1.33 NavigationHandlerImpl.java
        — src/com/sun/faces/application/NavigationHandlerImpl.java 11 May 2004
        21:10:05 -0000 1.33
        +++ src/com/sun/faces/application/NavigationHandlerImpl.java 15 Jul 2004
        22:00:10 -0000
        @@ -73,7 +73,7 @@
        FactoryFinder.APPLICATION_FACTORY);
        aFactory.getApplication();
        associate =

        • ApplicationAssociate.getInstance(ConfigureListener.getServletContextDuringInitialize());
          +
          ApplicationAssociate.getInstance(ConfigureListener.getExternalContextDuringInitialize());

        }

        Index: src/com/sun/faces/application/ViewHandlerImpl.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ViewHandlerImpl.java,v
        retrieving revision 1.42
        diff -u -r1.42 ViewHandlerImpl.java
        — src/com/sun/faces/application/ViewHandlerImpl.java 14 Jul 2004 21:30:53
        -0000 1.42
        +++ src/com/sun/faces/application/ViewHandlerImpl.java 15 Jul 2004 22:00:11 -0000
        @@ -101,7 +101,7 @@
        throw new NullPointerException(message);
        }

        • ApplicationAssociate associate =
          ApplicationAssociate.getInstance(context.getExternalContext().getContext());
          + ApplicationAssociate associate =
          ApplicationAssociate.getInstance(context.getExternalContext());

        if (null != associate) {
        associate.responseRendered();
        Index: src/com/sun/faces/config/ConfigureListener.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/config/ConfigureListener.java,v
        retrieving revision 1.21
        diff -u -r1.21 ConfigureListener.java
        — src/com/sun/faces/config/ConfigureListener.java 14 Jul 2004 21:30:54 -0000 1.21
        +++ src/com/sun/faces/config/ConfigureListener.java 15 Jul 2004 22:00:11 -0000
        @@ -53,7 +53,10 @@
        import javax.servlet.ServletContext;
        import javax.servlet.ServletContextEvent;
        import javax.servlet.ServletContextListener;
        +import javax.faces.context.ExternalContext;

        +import java.util.Locale;
        +import java.util.Map;
        import java.io.IOException;
        import java.io.InputStream;
        import java.net.MalformedURLException;
        @@ -109,13 +112,13 @@
        *
        */

        • private static ThreadLocal tlsServletContext = new ThreadLocal() {
          + private static ThreadLocal tlsExternalContext = new ThreadLocal()
          Unknown macro: { protected Object initialValue() { return (null); } }

          ;

        • static ThreadLocal getThreadLocalServletContext() {
          + static ThreadLocal getThreadLocalExternalContext()
          Unknown macro: { if (RIConstants.IS_UNIT_TEST_MODE) { - return tlsServletContext; + return tlsExternalContext; } return null; }

          @@ -125,8 +128,8 @@

        • method will return the ServletContext instance.</p>
          */
        • public static ServletContext getServletContextDuringInitialize() {
        • return (ServletContext) tlsServletContext.get();
          + public static ExternalContext getExternalContextDuringInitialize() { + return (ExternalContext) tlsExternalContext.get(); }

        public void contextInitialized(ServletContextEvent sce) {
        @@ -139,7 +142,7 @@
        // This enables our Application's ApplicationAssociate to locate
        // it so it can store the ApplicationAssociate in the
        // ServletContext.

        • tlsServletContext.set(context);
          + tlsExternalContext.set(new ServletContextAdapter(context));

        // see if we're operating in the unit test environment
        try {
        @@ -331,11 +334,14 @@
        try

        { configure(context, fcb, mappings); }

        catch (FacesException e)

        { + e.printStackTrace(); throw e; }

        catch (Exception e)

        { + e.printStackTrace(); throw new FacesException(e); - }

        + }

        +
        // Step 8, verify that all the configured factories are available
        // and optionall that configured objects can be created
        verifyFactories();
        @@ -343,7 +349,7 @@
        verifyObjects(context, fcb);
        }

        • tlsServletContext.set(null);
          + tlsExternalContext.set(null);
          }

        @@ -357,8 +363,9 @@

        // Release any allocated application resources
        FactoryFinder.releaseFactories();

        • ApplicationAssociate.clearInstance(context);
        • tlsServletContext.set(null);
          + tlsExternalContext.set(new ServletContextAdapter(context));
          + ApplicationAssociate.clearInstance((ExternalContext)tlsExternalContext.get());
          + tlsExternalContext.set(null);

        // Release the initialization mark on this web application
        release(context);
        @@ -796,7 +803,7 @@
        }
        Application application = application();
        ApplicationAssociate associate =

        • ApplicationAssociate.getInstance(getServletContextDuringInitialize());
          + ApplicationAssociate.getInstance(getExternalContextDuringInitialize());

        if (null == associate)

        { return; @@ -828,7 +835,7 @@ }

        Application application = application();
        ApplicationAssociate associate =

        • ApplicationAssociate.getInstance(getServletContextDuringInitialize());
          + ApplicationAssociate.getInstance(getExternalContextDuringInitialize());

        if (null == associate)

        { return; @@ -1306,6 +1313,226 @@ }

        }
        +
        + public class ServletContextAdapter extends ExternalContext {
        +
        + private ServletContext servletContext = null;
        + private ApplicationMap applicationMap = null;
        +
        + public ServletContextAdapter(ServletContext sc)

        { + this.servletContext = sc; + }
        +
        + public void dispatch(String path) throws IOException { + }
        +
        + public String encodeActionURL(String url) { + return null; + }
        +
        + public String encodeNamespace(String name) { + return null; + }
        +
        +
        + public String encodeResourceURL(String url) { + return null; + }
        +
        + public Map getApplicationMap() {
        + if (applicationMap == null) { + applicationMap = new ApplicationMap(servletContext); + }
        + return applicationMap;
        + }
        +
        + public String getAuthType() { + return null; + }
        +
        + public Object getContext() { + return servletContext; + }
        +
        + public String getInitParameter(String name) { + return null; + }
        +
        + public Map getInitParameterMap() { + return null; + }
        +
        + public String getRemoteUser() { + return null; + }
        +
        +
        + public Object getRequest() { + return null; + }
        +
        + public String getRequestContextPath() { + return null; + }
        +
        + public Map getRequestCookieMap() { + return null; + }
        +
        + public Map getRequestHeaderMap() { + return null; + }
        +
        +
        + public Map getRequestHeaderValuesMap() { + return null; + }
        +
        +
        + public Locale getRequestLocale() { + return null; + }
        +
        + public Iterator getRequestLocales() { + return null; + }
        +
        +
        +
        + public Map getRequestMap() { + return null; + }
        +
        +
        + public Map getRequestParameterMap() { + return null; + }
        +
        +
        + public Iterator getRequestParameterNames() { + return null; + }
        +
        +
        + public Map getRequestParameterValuesMap() { + return null; + }
        +
        +
        + public String getRequestPathInfo() { + return null; + }
        +
        +
        + public String getRequestServletPath() { + return null; + }
        +
        + public URL getResource(String path) throws MalformedURLException { + return null; + }
        +
        +
        + public InputStream getResourceAsStream(String path) { + return null; + }
        +
        + public Set getResourcePaths(String path) { + return null; + }
        +
        + public Object getResponse() { + return null; + }
        +
        + public Object getSession(boolean create) { + return null; + }
        +
        + public Map getSessionMap() { + return null; + }
        +
        + public java.security.Principal getUserPrincipal() { + return null; + }
        +
        + public boolean isUserInRole(String role) { + return false; + }
        +
        + public void log(String message) { + }
        +
        + public void log(String message, Throwable exception){ + }
        +
        + public void redirect(String url) throws IOException { + }
        +
        + }
        +
        + class ApplicationMap extends java.util.AbstractMap {
        +
        + private ServletContext servletContext = null;
        +
        + ApplicationMap(ServletContext servletContext) { + this.servletContext = servletContext; + }
        +
        +
        + public Object get(Object key) {
        + if (key == null) { + throw new NullPointerException(); + }
        + return servletContext.getAttribute(key.toString());
        + }
        +
        +
        + public Object put(Object key, Object value) {
        + if (key == null) { + throw new NullPointerException(); + }
        + String keyString = key.toString();
        + Object result = servletContext.getAttribute(keyString);
        + servletContext.setAttribute(keyString, value);
        + return (result);
        + }
        +
        +
        + public Object remove(Object key) {
        + if (key == null) { + return null; + }
        + String keyString = key.toString();
        + Object result = servletContext.getAttribute(keyString);
        + servletContext.removeAttribute(keyString);
        + return (result);
        + }
        +
        +
        + public Set entrySet() { + throw new UnsupportedOperationException(); + }
        +
        +
        + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof ApplicationMap)) + return false; + return super.equals(obj); + }
        +
        + public void clear() { + throw new UnsupportedOperationException(); + }
        +
        + public void putAll(Map t) { + throw new UnsupportedOperationException(); + }
        +
        +
        + } // END ApplicationMap


        }
        +
        Index: src/com/sun/faces/el/ValueBindingImpl.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/el/ValueBindingImpl.java,v
        retrieving revision 1.34
        diff -u -r1.34 ValueBindingImpl.java
        — src/com/sun/faces/el/ValueBindingImpl.java 17 Jun 2004 16:50:37 -0000 1.34
        +++ src/com/sun/faces/el/ValueBindingImpl.java 15 Jul 2004 22:00:11 -0000
        @@ -96,7 +96,7 @@
        FacesContext facesContext = FacesContext.getCurrentInstance();
        this.application = application;
        this.appAssociate =
        -
        ApplicationAssociate.getInstance(facesContext.getExternalContext().getContext());
        + ApplicationAssociate.getInstance(facesContext.getExternalContext());

        if (null == applicationMap) {
        applicationMap =
        Index: src/com/sun/faces/el/VariableResolverImpl.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/el/VariableResolverImpl.java,v
        retrieving revision 1.19
        diff -u -r1.19 VariableResolverImpl.java
        — src/com/sun/faces/el/VariableResolverImpl.java 7 May 2004 13:53:14 -0000 1.19
        +++ src/com/sun/faces/el/VariableResolverImpl.java 15 Jul 2004 22:00:11 -0000
        @@ -72,7 +72,7 @@
        if (null == (value = ec.getApplicationMap().get(name))) {
        // if it's a managed bean try and create it
        ApplicationAssociate associate =
        - ApplicationAssociate.getInstance(context.getExternalContext().getContext());
        + ApplicationAssociate.getInstance(context.getExternalContext());

        if (null != associate) {
        value =
        Index: src/com/sun/faces/util/Util.java
        ===================================================================
        RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/util/Util.java,v
        retrieving revision 1.140
        diff -u -r1.140 Util.java
        — src/com/sun/faces/util/Util.java 4 Jun 2004 20:48:02 -0000 1.140
        +++ src/com/sun/faces/util/Util.java 15 Jul 2004 22:00:11 -0000
        @@ -561,22 +561,6 @@


        /**
        - * Release the factories and remove the default RenderKit from the
        - * ServletContext.
        - */
        -
        - public static void releaseFactoriesAndDefaultRenderKit(ServletContext context)
        - throws FacesException { - FactoryFinder.releaseFactories(); - - Util.doAssert(null != - context.getAttribute(RIConstants.HTML_BASIC_RENDER_KIT)); - context.removeAttribute(RIConstants.HTML_BASIC_RENDER_KIT); - ApplicationAssociate.clearInstance(context); - }
        -
        -
        - /**
        * <p>Return an Iterator over {@link SelectItemWrapper} instances
        representing the
        * available options for this component, assembled from the set of
        * {@link UISelectItem} and/or {@link UISelectItems} components that are
        Index: test/com/sun/faces/FacesTestCaseService.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/FacesTestCaseService.java,v
        retrieving revision 1.39
        diff -u -r1.39 FacesTestCaseService.java
        — test/com/sun/faces/FacesTestCaseService.java 7 May 2004 13:53:19 -0000 1.39
        +++ test/com/sun/faces/FacesTestCaseService.java 15 Jul 2004 22:00:11 -0000
        @@ -18,6 +18,7 @@

        import javax.faces.FactoryFinder;
        import javax.faces.context.FacesContext;
        +import javax.faces.context.ExternalContext;
        import javax.faces.context.FacesContextFactory;
        import javax.faces.context.ResponseWriter;
        import javax.faces.lifecycle.Lifecycle;
        @@ -35,6 +36,8 @@
        import java.util.Enumeration;
        import java.util.Iterator;

        +import com.sun.faces.RIConstants;
        +

        /**
        * Subclasses of ServletTestCase and JspTestCase use an instance of this
        @@ -135,7 +138,7 @@
        FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
        "com.sun.faces.renderkit.RenderKitFactoryImpl");

        - ApplicationAssociate.clearInstance(facesTestCase.getConfig().getServletContext());
        + ApplicationAssociate.clearInstance(storeSC.getServletContextWrapper());
        Util.verifyFactoriesAndInitDefaultRenderKit(
        facesTestCase.getConfig().getServletContext());

        @@ -185,6 +188,7 @@
        ResponseWriter responseWriter = new FileOutputResponseWriter();
        facesContext.setResponseWriter(responseWriter);
        }
        +
        TestBean testBean = new TestBean();
        facesContext.getExternalContext().getSessionMap().put("TestBean",
        testBean);
        @@ -219,14 +223,17 @@

        public void tearDown() {
        // make sure this gets called!
        + if ( facesTestCase.getConfig().getServletContext() != null ) { + facesTestCase.getConfig().getServletContext() + .removeAttribute(RIConstants.HTML_BASIC_RENDER_KIT); + }
        +
        ConfigureListener configListener = new ConfigureListener();
        ServletContextEvent e =
        new ServletContextEvent(
        facesTestCase.getConfig().getServletContext());
        configListener.contextDestroyed(e);

        - Util.releaseFactoriesAndDefaultRenderKit(
        - facesTestCase.getConfig().getServletContext());
        // make sure session is not null. It will null in case release
        // was invoked.
        try { @@ -240,7 +247,7 @@ }
        }

        -
        +
        public boolean verifyExpectedOutput() { boolean result = false; CompareFiles cf = new CompareFiles(); @@ -444,7 +451,7 @@ // clear out the attr that was set in the servletcontext attr set. facesTestCase.getConfig().getServletContext().removeAttribute( FacesServlet.CONFIG_FILES_ATTR); - ApplicationAssociate.clearInstance(facesTestCase.getConfig().getServletContext()); + ApplicationAssociate.clearInstance(facesContext.getExternalContext()); // clear out the renderKit factory FactoryFinder.releaseFactories(); Index: test/com/sun/faces/application/TestApplicationFactoryImpl.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/application/TestApplicationFactoryImpl.java,v retrieving revision 1.6 diff -u -r1.6 TestApplicationFactoryImpl.java --- test/com/sun/faces/application/TestApplicationFactoryImpl.java 7 May 2004 13:53:20 -0000 1.6 +++ test/com/sun/faces/application/TestApplicationFactoryImpl.java 15 Jul 2004 22:00:11 -0000 @@ -13,6 +13,7 @@ import com.sun.faces.JspFacesTestCase; +import com.sun.faces.config.ConfigureListener; import javax.faces.application.Application; /** @@ -67,7 +68,7 @@ com.sun.faces.config.StoreServletContext storeSC = new com.sun.faces.config.StoreServletContext(); storeSC.setServletContext(config.getServletContext()); - ApplicationAssociate.clearInstance(config.getServletContext()); + ApplicationAssociate.clearInstance(storeSC.getServletContextWrapper()); // 1. Verify "getApplication" returns the same Application instance @@ -80,7 +81,7 @@ // 2. Verify "setApplication" adds instances.. / // and "getApplication" returns the same instance // - ApplicationAssociate.clearInstance(config.getServletContext()); + ApplicationAssociate.clearInstance(storeSC.getServletContextWrapper()); Application application3 = new ApplicationImpl(); applicationFactory.setApplication(application3); Application application4 = applicationFactory.getApplication(); @@ -93,7 +94,7 @@ com.sun.faces.config.StoreServletContext storeSC = new com.sun.faces.config.StoreServletContext(); storeSC.setServletContext(config.getServletContext()); - ApplicationAssociate.clearInstance(config.getServletContext()); + ApplicationAssociate.clearInstance(storeSC.getServletContextWrapper()); assertTrue(null != applicationFactory.getApplication()); }
        Index: test/com/sun/faces/application/TestNavigationHandler.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/application/TestNavigationHandler.java,v
        retrieving revision 1.20
        diff -u -r1.20 TestNavigationHandler.java
        — test/com/sun/faces/application/TestNavigationHandler.java 7 May 2004
        13:53:20 -0000 1.20
        +++ test/com/sun/faces/application/TestNavigationHandler.java 15 Jul 2004
        22:00:11 -0000
        @@ -210,7 +210,7 @@
        FactoryFinder.APPLICATION_FACTORY);
        Application application = aFactory.getApplication();
        assertTrue(application instanceof ApplicationImpl);
        - ApplicationAssociate associate =
        ApplicationAssociate.getInstance(config.getServletContext());
        + ApplicationAssociate associate =
        ApplicationAssociate.getInstance(getFacesContext().getExternalContext());
        assertNotNull(associate);

        Map caseListMap = associate.getNavigationCaseListMappings();
        Index: test/com/sun/faces/config/ConfigFileTestCase.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/config/ConfigFileTestCase.java,v
        retrieving revision 1.60
        diff -u -r1.60 ConfigFileTestCase.java
        — test/com/sun/faces/config/ConfigFileTestCase.java 12 May 2004 03:09:47
        -0000 1.60
        +++ test/com/sun/faces/config/ConfigFileTestCase.java 15 Jul 2004 22:00:11 -0000
        @@ -300,7 +300,7 @@
        FactoryFinder.APPLICATION_FACTORY);
        ApplicationImpl application = (ApplicationImpl) aFactory.getApplication();

        - ApplicationAssociate associate =
        ApplicationAssociate.getInstance(config.getServletContext());
        + ApplicationAssociate associate =
        ApplicationAssociate.getInstance(getFacesContext().getExternalContext());
        Object bean =
        associate.createAndMaybeStoreManagedBeans(getFacesContext(),
        "SimpleBean");
        @@ -650,7 +650,7 @@
        ApplicationFactory aFactory = (ApplicationFactory)
        FactoryFinder.getFactory(
        FactoryFinder.APPLICATION_FACTORY);
        ApplicationImpl application = (ApplicationImpl) aFactory.getApplication();
        - ApplicationAssociate associate =
        ApplicationAssociate.getInstance(config.getServletContext());
        + ApplicationAssociate associate =
        ApplicationAssociate.getInstance(getFacesContext().getExternalContext());

        com.sun.faces.TestBean bean = (com.sun.faces.TestBean)
        associate.createAndMaybeStoreManagedBeans(getFacesContext(),
        Index: test/com/sun/faces/config/StoreServletContext.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/config/StoreServletContext.java,v
        retrieving revision 1.1
        diff -u -r1.1 StoreServletContext.java
        — test/com/sun/faces/config/StoreServletContext.java 7 May 2004 13:53:23 -0000 1.1
        +++ test/com/sun/faces/config/StoreServletContext.java 15 Jul 2004 22:00:11 -0000
        @@ -11,7 +11,12 @@
        package com.sun.faces.config;

        import javax.servlet.ServletContext;
        +import javax.faces.context.ExternalContext;

        +import java.util.Map;
        +import java.util.Set;
        +import java.util.Locale;
        +import java.util.Iterator;
        /**
        * <p>The purpose of this class is to call the package private
        * getThreadLocalServletContext() method to set the ServletContext into
        @@ -19,7 +24,234 @@
        */

        public class StoreServletContext extends Object {
        + ExternalContext ec = null;
        public void setServletContext(ServletContext sc) { - ConfigureListener.getThreadLocalServletContext().set(sc); + ec = new ServletContextAdapter(sc); + ConfigureListener.getThreadLocalExternalContext().set(new ServletContextAdapter(sc)); }
        +
        + public ExternalContext getServletContextWrapper() { + return ec; + }
        +
        + public class ServletContextAdapter extends ExternalContext {
        +
        + private ServletContext servletContext = null;
        + private ApplicationMap applicationMap = null;
        +
        + public ServletContextAdapter(ServletContext sc) { + this.servletContext = sc; + }

        +
        + public void dispatch(String path) throws java.io.IOException

        { + }
        +
        + public String encodeActionURL(String url) { + return null; + }
        +
        + public String encodeNamespace(String name) { + return null; + }
        +
        +
        + public String encodeResourceURL(String url) { + return null; + }
        +
        + public Map getApplicationMap() {
        + if (applicationMap == null) { + applicationMap = new ApplicationMap(servletContext); + }
        + return applicationMap;
        + }
        +
        + public String getAuthType() { + return null; + }
        +
        + public Object getContext() { + return servletContext; + }
        +
        + public String getInitParameter(String name) { + return null; + }
        +
        + public Map getInitParameterMap() { + return null; + }
        +
        + public String getRemoteUser() { + return null; + }
        +
        +
        + public Object getRequest() { + return null; + }
        +
        + public String getRequestContextPath() { + return null; + }
        +
        + public Map getRequestCookieMap() { + return null; + }
        +
        + public Map getRequestHeaderMap() { + return null; + }
        +
        +
        + public Map getRequestHeaderValuesMap() { + return null; + }
        +
        +
        + public Locale getRequestLocale() { + return null; + }
        +
        + public Iterator getRequestLocales() { + return null; + }
        +
        +
        +
        + public Map getRequestMap() { + return null; + }
        +
        +
        + public Map getRequestParameterMap() { + return null; + }
        +
        +
        + public Iterator getRequestParameterNames() { + return null; + }
        +
        +
        + public Map getRequestParameterValuesMap() { + return null; + }
        +
        +
        + public String getRequestPathInfo() { + return null; + }
        +
        +
        + public String getRequestServletPath() { + return null; + }
        +
        + public java.net.URL getResource(String path) throws
        + java.net.MalformedURLException { + return null; + }
        +
        +
        + public java.io.InputStream getResourceAsStream(String path) { + return null; + }
        +
        + public Set getResourcePaths(String path) { + return null; + }
        +
        + public Object getResponse() { + return null; + }
        +
        + public Object getSession(boolean create) { + return null; + }
        +
        + public Map getSessionMap() { + return null; + }
        +
        + public java.security.Principal getUserPrincipal() { + return null; + }
        +
        + public boolean isUserInRole(String role) { + return false; + }
        +
        + public void log(String message) { + }

        +
        + public void log(String message, Throwable exception)

        { + }
        +
        + public void redirect(String url) throws java.io.IOException { + }

        +
        + }
        +
        + class ApplicationMap extends java.util.AbstractMap {
        +
        + private ServletContext servletContext = null;
        +
        + ApplicationMap(ServletContext servletContext)

        { + this.servletContext = servletContext; + }

        +
        +
        + public Object get(Object key) {
        + if (key == null)

        { + throw new NullPointerException(); + }
        + return servletContext.getAttribute(key.toString());
        + }
        +
        +
        + public Object put(Object key, Object value) {
        + if (key == null) { + throw new NullPointerException(); + }

        + String keyString = key.toString();
        + Object result = servletContext.getAttribute(keyString);
        + servletContext.setAttribute(keyString, value);
        + return (result);
        + }
        +
        +
        + public Object remove(Object key) {
        + if (key == null)

        { + return null; + }

        + String keyString = key.toString();
        + Object result = servletContext.getAttribute(keyString);
        + servletContext.removeAttribute(keyString);
        + return (result);
        + }
        +
        +
        + public Set entrySet()

        { + throw new UnsupportedOperationException(); + }

        +
        +
        + public boolean equals(Object obj)

        { + if (obj == null || !(obj instanceof ApplicationMap)) + return false; + return super.equals(obj); + }

        +
        + public void clear()

        { + throw new UnsupportedOperationException(); + }
        +
        + public void putAll(Map t) { + throw new UnsupportedOperationException(); + }

        +
        +
        + } // END ApplicationMap
        }
        +
        Index: test/com/sun/faces/el/TestVariableResolverImpl.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/el/TestVariableResolverImpl.java,v
        retrieving revision 1.17
        diff -u -r1.17 TestVariableResolverImpl.java
        — test/com/sun/faces/el/TestVariableResolverImpl.java 7 May 2004 13:53:26
        -0000 1.17
        +++ test/com/sun/faces/el/TestVariableResolverImpl.java 15 Jul 2004 22:00:11 -0000
        @@ -258,7 +258,7 @@
        ApplicationFactory aFactory = (ApplicationFactory)
        FactoryFinder.getFactory(
        FactoryFinder.APPLICATION_FACTORY);
        ApplicationImpl application = (ApplicationImpl) aFactory.getApplication();

        • ApplicationAssociate associate =
          ApplicationAssociate.getInstance(config.getServletContext());
          + ApplicationAssociate associate =
          ApplicationAssociate.getInstance(getFacesContext().getExternalContext());

        associate.addManagedBeanFactory(beanName, mbf);

        Show
        jayashri added a comment - Fix for Issue 1 Remove explicit casts and dependencies to ServletContext. M src/com/sun/faces/application/ApplicationAssociate.java Deal with ExternalContext that wraps ServletContext to avoid dependencies on servlet based environment. M src/com/sun/faces/application/NavigationHandlerImpl.java M src/com/sun/faces/application/ViewHandlerImpl.java Pass in ExternalContext that wraps ServletContext M src/com/sun/faces/config/ConfigureListener.java create a public inner class on ExternalContext that wraps ServletContext. This is because when contextInitialized() is invoked, FacesContext and ExternalContext do not exist. So this wrapper is created solely for the purpose of accessing ServletContext in a environment independent manner. So except ServletContext related methods, other methods are left unimplemented. M src/com/sun/faces/el/ValueBindingImpl.java M src/com/sun/faces/el/VariableResolverImpl.java M src/com/sun/faces/util/Util.java Remove unused method releaseFactoriesAndDefaultRenderkit() M test/com/sun/faces/FacesTestCaseService.java M test/com/sun/faces/application/TestApplicationFactoryImpl.java M test/com/sun/faces/application/TestNavigationHandler.java M test/com/sun/faces/config/ConfigFileTestCase.java M test/com/sun/faces/config/StoreServletContext.java M test/com/sun/faces/el/TestVariableResolverImpl.java update tests for the above changes. SECTION: DIFFS Index: src/com/sun/faces/application/ApplicationAssociate.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ApplicationAssociate.java,v retrieving revision 1.2 diff -u -r1.2 ApplicationAssociate.java — src/com/sun/faces/application/ApplicationAssociate.java 11 May 2004 21:35:23 -0000 1.2 +++ src/com/sun/faces/application/ApplicationAssociate.java 15 Jul 2004 22:00:10 -0000 @@ -22,9 +22,8 @@ import java.util.Comparator; import java.util.Collections; -import javax.servlet.ServletContext; - import javax.faces.context.FacesContext; +import javax.faces.context.ExternalContext; import javax.faces.FacesException; import com.sun.faces.config.ManagedBeanFactory; @@ -96,17 +95,17 @@ public ApplicationAssociate(ApplicationImpl appImpl) { app = appImpl; ServletContext servletContext = null; if (null == (servletContext = ConfigureListener.getServletContextDuringInitialize())) { + ExternalContext externalContext = null; + if (null == (externalContext = + ConfigureListener.getExternalContextDuringInitialize())) { // PENDING I18N throw new IllegalStateException("ApplicationAssociate ctor not called in same callstack as ConfigureListener.contextInitialized()"); } // PENDING I18N if (null != servletContext.getAttribute(ASSOCIATE_KEY)) { + if (null != externalContext.getApplicationMap().get(ASSOCIATE_KEY)) { throw new IllegalStateException("ApplicationAssociate already exists for this webapp"); } servletContext.setAttribute(ASSOCIATE_KEY, this); + externalContext.getApplicationMap().put(ASSOCIATE_KEY, this); managedBeanFactoriesMap = new HashMap(); caseListMap = new HashMap(); wildcardMatchList = new TreeSet(new SortIt()); @@ -114,13 +113,17 @@ expressionInfoInstancePool = new InstancePool(); } public static ApplicationAssociate getInstance(Object servletContext) { + public static ApplicationAssociate getInstance(ExternalContext + externalContext) { + Map applicationMap = externalContext.getApplicationMap(); return ((ApplicationAssociate) - ((ServletContext)servletContext).getAttribute(ASSOCIATE_KEY)); + applicationMap.get(ASSOCIATE_KEY)); } public static void clearInstance(Object servletContext) { ((ServletContext)servletContext).removeAttribute(ASSOCIATE_KEY); + public static void clearInstance(ExternalContext + externalContext) { + Map applicationMap = externalContext.getApplicationMap(); + applicationMap.remove(ASSOCIATE_KEY); } Index: src/com/sun/faces/application/NavigationHandlerImpl.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/NavigationHandlerImpl.java,v retrieving revision 1.33 diff -u -r1.33 NavigationHandlerImpl.java — src/com/sun/faces/application/NavigationHandlerImpl.java 11 May 2004 21:10:05 -0000 1.33 +++ src/com/sun/faces/application/NavigationHandlerImpl.java 15 Jul 2004 22:00:10 -0000 @@ -73,7 +73,7 @@ FactoryFinder.APPLICATION_FACTORY); aFactory.getApplication(); associate = ApplicationAssociate.getInstance(ConfigureListener.getServletContextDuringInitialize()); + ApplicationAssociate.getInstance(ConfigureListener.getExternalContextDuringInitialize()); } Index: src/com/sun/faces/application/ViewHandlerImpl.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ViewHandlerImpl.java,v retrieving revision 1.42 diff -u -r1.42 ViewHandlerImpl.java — src/com/sun/faces/application/ViewHandlerImpl.java 14 Jul 2004 21:30:53 -0000 1.42 +++ src/com/sun/faces/application/ViewHandlerImpl.java 15 Jul 2004 22:00:11 -0000 @@ -101,7 +101,7 @@ throw new NullPointerException(message); } ApplicationAssociate associate = ApplicationAssociate.getInstance(context.getExternalContext().getContext()); + ApplicationAssociate associate = ApplicationAssociate.getInstance(context.getExternalContext()); if (null != associate) { associate.responseRendered(); Index: src/com/sun/faces/config/ConfigureListener.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/config/ConfigureListener.java,v retrieving revision 1.21 diff -u -r1.21 ConfigureListener.java — src/com/sun/faces/config/ConfigureListener.java 14 Jul 2004 21:30:54 -0000 1.21 +++ src/com/sun/faces/config/ConfigureListener.java 15 Jul 2004 22:00:11 -0000 @@ -53,7 +53,10 @@ import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import javax.faces.context.ExternalContext; +import java.util.Locale; +import java.util.Map; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -109,13 +112,13 @@ * */ private static ThreadLocal tlsServletContext = new ThreadLocal() { + private static ThreadLocal tlsExternalContext = new ThreadLocal() Unknown macro: { protected Object initialValue() { return (null); } } ; static ThreadLocal getThreadLocalServletContext() { + static ThreadLocal getThreadLocalExternalContext() Unknown macro: { if (RIConstants.IS_UNIT_TEST_MODE) { - return tlsServletContext; + return tlsExternalContext; } return null; } @@ -125,8 +128,8 @@ method will return the ServletContext instance.</p> */ public static ServletContext getServletContextDuringInitialize() { return (ServletContext) tlsServletContext.get(); + public static ExternalContext getExternalContextDuringInitialize() { + return (ExternalContext) tlsExternalContext.get(); } public void contextInitialized(ServletContextEvent sce) { @@ -139,7 +142,7 @@ // This enables our Application's ApplicationAssociate to locate // it so it can store the ApplicationAssociate in the // ServletContext. tlsServletContext.set(context); + tlsExternalContext.set(new ServletContextAdapter(context)); // see if we're operating in the unit test environment try { @@ -331,11 +334,14 @@ try { configure(context, fcb, mappings); } catch (FacesException e) { + e.printStackTrace(); throw e; } catch (Exception e) { + e.printStackTrace(); throw new FacesException(e); - } + } + // Step 8, verify that all the configured factories are available // and optionall that configured objects can be created verifyFactories(); @@ -343,7 +349,7 @@ verifyObjects(context, fcb); } tlsServletContext.set(null); + tlsExternalContext.set(null); } @@ -357,8 +363,9 @@ // Release any allocated application resources FactoryFinder.releaseFactories(); ApplicationAssociate.clearInstance(context); tlsServletContext.set(null); + tlsExternalContext.set(new ServletContextAdapter(context)); + ApplicationAssociate.clearInstance((ExternalContext)tlsExternalContext.get()); + tlsExternalContext.set(null); // Release the initialization mark on this web application release(context); @@ -796,7 +803,7 @@ } Application application = application(); ApplicationAssociate associate = ApplicationAssociate.getInstance(getServletContextDuringInitialize()); + ApplicationAssociate.getInstance(getExternalContextDuringInitialize()); if (null == associate) { return; @@ -828,7 +835,7 @@ } Application application = application(); ApplicationAssociate associate = ApplicationAssociate.getInstance(getServletContextDuringInitialize()); + ApplicationAssociate.getInstance(getExternalContextDuringInitialize()); if (null == associate) { return; @@ -1306,6 +1313,226 @@ } } + + public class ServletContextAdapter extends ExternalContext { + + private ServletContext servletContext = null; + private ApplicationMap applicationMap = null; + + public ServletContextAdapter(ServletContext sc) { + this.servletContext = sc; + } + + public void dispatch(String path) throws IOException { + } + + public String encodeActionURL(String url) { + return null; + } + + public String encodeNamespace(String name) { + return null; + } + + + public String encodeResourceURL(String url) { + return null; + } + + public Map getApplicationMap() { + if (applicationMap == null) { + applicationMap = new ApplicationMap(servletContext); + } + return applicationMap; + } + + public String getAuthType() { + return null; + } + + public Object getContext() { + return servletContext; + } + + public String getInitParameter(String name) { + return null; + } + + public Map getInitParameterMap() { + return null; + } + + public String getRemoteUser() { + return null; + } + + + public Object getRequest() { + return null; + } + + public String getRequestContextPath() { + return null; + } + + public Map getRequestCookieMap() { + return null; + } + + public Map getRequestHeaderMap() { + return null; + } + + + public Map getRequestHeaderValuesMap() { + return null; + } + + + public Locale getRequestLocale() { + return null; + } + + public Iterator getRequestLocales() { + return null; + } + + + + public Map getRequestMap() { + return null; + } + + + public Map getRequestParameterMap() { + return null; + } + + + public Iterator getRequestParameterNames() { + return null; + } + + + public Map getRequestParameterValuesMap() { + return null; + } + + + public String getRequestPathInfo() { + return null; + } + + + public String getRequestServletPath() { + return null; + } + + public URL getResource(String path) throws MalformedURLException { + return null; + } + + + public InputStream getResourceAsStream(String path) { + return null; + } + + public Set getResourcePaths(String path) { + return null; + } + + public Object getResponse() { + return null; + } + + public Object getSession(boolean create) { + return null; + } + + public Map getSessionMap() { + return null; + } + + public java.security.Principal getUserPrincipal() { + return null; + } + + public boolean isUserInRole(String role) { + return false; + } + + public void log(String message) { + } + + public void log(String message, Throwable exception){ + } + + public void redirect(String url) throws IOException { + } + + } + + class ApplicationMap extends java.util.AbstractMap { + + private ServletContext servletContext = null; + + ApplicationMap(ServletContext servletContext) { + this.servletContext = servletContext; + } + + + public Object get(Object key) { + if (key == null) { + throw new NullPointerException(); + } + return servletContext.getAttribute(key.toString()); + } + + + public Object put(Object key, Object value) { + if (key == null) { + throw new NullPointerException(); + } + String keyString = key.toString(); + Object result = servletContext.getAttribute(keyString); + servletContext.setAttribute(keyString, value); + return (result); + } + + + public Object remove(Object key) { + if (key == null) { + return null; + } + String keyString = key.toString(); + Object result = servletContext.getAttribute(keyString); + servletContext.removeAttribute(keyString); + return (result); + } + + + public Set entrySet() { + throw new UnsupportedOperationException(); + } + + + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof ApplicationMap)) + return false; + return super.equals(obj); + } + + public void clear() { + throw new UnsupportedOperationException(); + } + + public void putAll(Map t) { + throw new UnsupportedOperationException(); + } + + + } // END ApplicationMap } + Index: src/com/sun/faces/el/ValueBindingImpl.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/el/ValueBindingImpl.java,v retrieving revision 1.34 diff -u -r1.34 ValueBindingImpl.java — src/com/sun/faces/el/ValueBindingImpl.java 17 Jun 2004 16:50:37 -0000 1.34 +++ src/com/sun/faces/el/ValueBindingImpl.java 15 Jul 2004 22:00:11 -0000 @@ -96,7 +96,7 @@ FacesContext facesContext = FacesContext.getCurrentInstance(); this.application = application; this.appAssociate = - ApplicationAssociate.getInstance(facesContext.getExternalContext().getContext()); + ApplicationAssociate.getInstance(facesContext.getExternalContext()); if (null == applicationMap) { applicationMap = Index: src/com/sun/faces/el/VariableResolverImpl.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/el/VariableResolverImpl.java,v retrieving revision 1.19 diff -u -r1.19 VariableResolverImpl.java — src/com/sun/faces/el/VariableResolverImpl.java 7 May 2004 13:53:14 -0000 1.19 +++ src/com/sun/faces/el/VariableResolverImpl.java 15 Jul 2004 22:00:11 -0000 @@ -72,7 +72,7 @@ if (null == (value = ec.getApplicationMap().get(name))) { // if it's a managed bean try and create it ApplicationAssociate associate = - ApplicationAssociate.getInstance(context.getExternalContext().getContext()); + ApplicationAssociate.getInstance(context.getExternalContext()); if (null != associate) { value = Index: src/com/sun/faces/util/Util.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/util/Util.java,v retrieving revision 1.140 diff -u -r1.140 Util.java — src/com/sun/faces/util/Util.java 4 Jun 2004 20:48:02 -0000 1.140 +++ src/com/sun/faces/util/Util.java 15 Jul 2004 22:00:11 -0000 @@ -561,22 +561,6 @@ /** - * Release the factories and remove the default RenderKit from the - * ServletContext. - */ - - public static void releaseFactoriesAndDefaultRenderKit(ServletContext context) - throws FacesException { - FactoryFinder.releaseFactories(); - - Util.doAssert(null != - context.getAttribute(RIConstants.HTML_BASIC_RENDER_KIT)); - context.removeAttribute(RIConstants.HTML_BASIC_RENDER_KIT); - ApplicationAssociate.clearInstance(context); - } - - - /** * <p>Return an Iterator over {@link SelectItemWrapper} instances representing the * available options for this component, assembled from the set of * {@link UISelectItem} and/or {@link UISelectItems} components that are Index: test/com/sun/faces/FacesTestCaseService.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/FacesTestCaseService.java,v retrieving revision 1.39 diff -u -r1.39 FacesTestCaseService.java — test/com/sun/faces/FacesTestCaseService.java 7 May 2004 13:53:19 -0000 1.39 +++ test/com/sun/faces/FacesTestCaseService.java 15 Jul 2004 22:00:11 -0000 @@ -18,6 +18,7 @@ import javax.faces.FactoryFinder; import javax.faces.context.FacesContext; +import javax.faces.context.ExternalContext; import javax.faces.context.FacesContextFactory; import javax.faces.context.ResponseWriter; import javax.faces.lifecycle.Lifecycle; @@ -35,6 +36,8 @@ import java.util.Enumeration; import java.util.Iterator; +import com.sun.faces.RIConstants; + /** * Subclasses of ServletTestCase and JspTestCase use an instance of this @@ -135,7 +138,7 @@ FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY, "com.sun.faces.renderkit.RenderKitFactoryImpl"); - ApplicationAssociate.clearInstance(facesTestCase.getConfig().getServletContext()); + ApplicationAssociate.clearInstance(storeSC.getServletContextWrapper()); Util.verifyFactoriesAndInitDefaultRenderKit( facesTestCase.getConfig().getServletContext()); @@ -185,6 +188,7 @@ ResponseWriter responseWriter = new FileOutputResponseWriter(); facesContext.setResponseWriter(responseWriter); } + TestBean testBean = new TestBean(); facesContext.getExternalContext().getSessionMap().put("TestBean", testBean); @@ -219,14 +223,17 @@ public void tearDown() { // make sure this gets called! + if ( facesTestCase.getConfig().getServletContext() != null ) { + facesTestCase.getConfig().getServletContext() + .removeAttribute(RIConstants.HTML_BASIC_RENDER_KIT); + } + ConfigureListener configListener = new ConfigureListener(); ServletContextEvent e = new ServletContextEvent( facesTestCase.getConfig().getServletContext()); configListener.contextDestroyed(e); - Util.releaseFactoriesAndDefaultRenderKit( - facesTestCase.getConfig().getServletContext()); // make sure session is not null. It will null in case release // was invoked. try { @@ -240,7 +247,7 @@ } } - + public boolean verifyExpectedOutput() { boolean result = false; CompareFiles cf = new CompareFiles(); @@ -444,7 +451,7 @@ // clear out the attr that was set in the servletcontext attr set. facesTestCase.getConfig().getServletContext().removeAttribute( FacesServlet.CONFIG_FILES_ATTR); - ApplicationAssociate.clearInstance(facesTestCase.getConfig().getServletContext()); + ApplicationAssociate.clearInstance(facesContext.getExternalContext()); // clear out the renderKit factory FactoryFinder.releaseFactories(); Index: test/com/sun/faces/application/TestApplicationFactoryImpl.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/application/TestApplicationFactoryImpl.java,v retrieving revision 1.6 diff -u -r1.6 TestApplicationFactoryImpl.java --- test/com/sun/faces/application/TestApplicationFactoryImpl.java 7 May 2004 13:53:20 -0000 1.6 +++ test/com/sun/faces/application/TestApplicationFactoryImpl.java 15 Jul 2004 22:00:11 -0000 @@ -13,6 +13,7 @@ import com.sun.faces.JspFacesTestCase; +import com.sun.faces.config.ConfigureListener; import javax.faces.application.Application; /** @@ -67,7 +68,7 @@ com.sun.faces.config.StoreServletContext storeSC = new com.sun.faces.config.StoreServletContext(); storeSC.setServletContext(config.getServletContext()); - ApplicationAssociate.clearInstance(config.getServletContext()); + ApplicationAssociate.clearInstance(storeSC.getServletContextWrapper()); // 1. Verify "getApplication" returns the same Application instance @@ -80,7 +81,7 @@ // 2. Verify "setApplication" adds instances.. / // and "getApplication" returns the same instance // - ApplicationAssociate.clearInstance(config.getServletContext()); + ApplicationAssociate.clearInstance(storeSC.getServletContextWrapper()); Application application3 = new ApplicationImpl(); applicationFactory.setApplication(application3); Application application4 = applicationFactory.getApplication(); @@ -93,7 +94,7 @@ com.sun.faces.config.StoreServletContext storeSC = new com.sun.faces.config.StoreServletContext(); storeSC.setServletContext(config.getServletContext()); - ApplicationAssociate.clearInstance(config.getServletContext()); + ApplicationAssociate.clearInstance(storeSC.getServletContextWrapper()); assertTrue(null != applicationFactory.getApplication()); } Index: test/com/sun/faces/application/TestNavigationHandler.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/application/TestNavigationHandler.java,v retrieving revision 1.20 diff -u -r1.20 TestNavigationHandler.java — test/com/sun/faces/application/TestNavigationHandler.java 7 May 2004 13:53:20 -0000 1.20 +++ test/com/sun/faces/application/TestNavigationHandler.java 15 Jul 2004 22:00:11 -0000 @@ -210,7 +210,7 @@ FactoryFinder.APPLICATION_FACTORY); Application application = aFactory.getApplication(); assertTrue(application instanceof ApplicationImpl); - ApplicationAssociate associate = ApplicationAssociate.getInstance(config.getServletContext()); + ApplicationAssociate associate = ApplicationAssociate.getInstance(getFacesContext().getExternalContext()); assertNotNull(associate); Map caseListMap = associate.getNavigationCaseListMappings(); Index: test/com/sun/faces/config/ConfigFileTestCase.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/config/ConfigFileTestCase.java,v retrieving revision 1.60 diff -u -r1.60 ConfigFileTestCase.java — test/com/sun/faces/config/ConfigFileTestCase.java 12 May 2004 03:09:47 -0000 1.60 +++ test/com/sun/faces/config/ConfigFileTestCase.java 15 Jul 2004 22:00:11 -0000 @@ -300,7 +300,7 @@ FactoryFinder.APPLICATION_FACTORY); ApplicationImpl application = (ApplicationImpl) aFactory.getApplication(); - ApplicationAssociate associate = ApplicationAssociate.getInstance(config.getServletContext()); + ApplicationAssociate associate = ApplicationAssociate.getInstance(getFacesContext().getExternalContext()); Object bean = associate.createAndMaybeStoreManagedBeans(getFacesContext(), "SimpleBean"); @@ -650,7 +650,7 @@ ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder.getFactory( FactoryFinder.APPLICATION_FACTORY); ApplicationImpl application = (ApplicationImpl) aFactory.getApplication(); - ApplicationAssociate associate = ApplicationAssociate.getInstance(config.getServletContext()); + ApplicationAssociate associate = ApplicationAssociate.getInstance(getFacesContext().getExternalContext()); com.sun.faces.TestBean bean = (com.sun.faces.TestBean) associate.createAndMaybeStoreManagedBeans(getFacesContext(), Index: test/com/sun/faces/config/StoreServletContext.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/config/StoreServletContext.java,v retrieving revision 1.1 diff -u -r1.1 StoreServletContext.java — test/com/sun/faces/config/StoreServletContext.java 7 May 2004 13:53:23 -0000 1.1 +++ test/com/sun/faces/config/StoreServletContext.java 15 Jul 2004 22:00:11 -0000 @@ -11,7 +11,12 @@ package com.sun.faces.config; import javax.servlet.ServletContext; +import javax.faces.context.ExternalContext; +import java.util.Map; +import java.util.Set; +import java.util.Locale; +import java.util.Iterator; /** * <p>The purpose of this class is to call the package private * getThreadLocalServletContext() method to set the ServletContext into @@ -19,7 +24,234 @@ */ public class StoreServletContext extends Object { + ExternalContext ec = null; public void setServletContext(ServletContext sc) { - ConfigureListener.getThreadLocalServletContext().set(sc); + ec = new ServletContextAdapter(sc); + ConfigureListener.getThreadLocalExternalContext().set(new ServletContextAdapter(sc)); } + + public ExternalContext getServletContextWrapper() { + return ec; + } + + public class ServletContextAdapter extends ExternalContext { + + private ServletContext servletContext = null; + private ApplicationMap applicationMap = null; + + public ServletContextAdapter(ServletContext sc) { + this.servletContext = sc; + } + + public void dispatch(String path) throws java.io.IOException { + } + + public String encodeActionURL(String url) { + return null; + } + + public String encodeNamespace(String name) { + return null; + } + + + public String encodeResourceURL(String url) { + return null; + } + + public Map getApplicationMap() { + if (applicationMap == null) { + applicationMap = new ApplicationMap(servletContext); + } + return applicationMap; + } + + public String getAuthType() { + return null; + } + + public Object getContext() { + return servletContext; + } + + public String getInitParameter(String name) { + return null; + } + + public Map getInitParameterMap() { + return null; + } + + public String getRemoteUser() { + return null; + } + + + public Object getRequest() { + return null; + } + + public String getRequestContextPath() { + return null; + } + + public Map getRequestCookieMap() { + return null; + } + + public Map getRequestHeaderMap() { + return null; + } + + + public Map getRequestHeaderValuesMap() { + return null; + } + + + public Locale getRequestLocale() { + return null; + } + + public Iterator getRequestLocales() { + return null; + } + + + + public Map getRequestMap() { + return null; + } + + + public Map getRequestParameterMap() { + return null; + } + + + public Iterator getRequestParameterNames() { + return null; + } + + + public Map getRequestParameterValuesMap() { + return null; + } + + + public String getRequestPathInfo() { + return null; + } + + + public String getRequestServletPath() { + return null; + } + + public java.net.URL getResource(String path) throws + java.net.MalformedURLException { + return null; + } + + + public java.io.InputStream getResourceAsStream(String path) { + return null; + } + + public Set getResourcePaths(String path) { + return null; + } + + public Object getResponse() { + return null; + } + + public Object getSession(boolean create) { + return null; + } + + public Map getSessionMap() { + return null; + } + + public java.security.Principal getUserPrincipal() { + return null; + } + + public boolean isUserInRole(String role) { + return false; + } + + public void log(String message) { + } + + public void log(String message, Throwable exception) { + } + + public void redirect(String url) throws java.io.IOException { + } + + } + + class ApplicationMap extends java.util.AbstractMap { + + private ServletContext servletContext = null; + + ApplicationMap(ServletContext servletContext) { + this.servletContext = servletContext; + } + + + public Object get(Object key) { + if (key == null) { + throw new NullPointerException(); + } + return servletContext.getAttribute(key.toString()); + } + + + public Object put(Object key, Object value) { + if (key == null) { + throw new NullPointerException(); + } + String keyString = key.toString(); + Object result = servletContext.getAttribute(keyString); + servletContext.setAttribute(keyString, value); + return (result); + } + + + public Object remove(Object key) { + if (key == null) { + return null; + } + String keyString = key.toString(); + Object result = servletContext.getAttribute(keyString); + servletContext.removeAttribute(keyString); + return (result); + } + + + public Set entrySet() { + throw new UnsupportedOperationException(); + } + + + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof ApplicationMap)) + return false; + return super.equals(obj); + } + + public void clear() { + throw new UnsupportedOperationException(); + } + + public void putAll(Map t) { + throw new UnsupportedOperationException(); + } + + + } // END ApplicationMap } + Index: test/com/sun/faces/el/TestVariableResolverImpl.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/el/TestVariableResolverImpl.java,v retrieving revision 1.17 diff -u -r1.17 TestVariableResolverImpl.java — test/com/sun/faces/el/TestVariableResolverImpl.java 7 May 2004 13:53:26 -0000 1.17 +++ test/com/sun/faces/el/TestVariableResolverImpl.java 15 Jul 2004 22:00:11 -0000 @@ -258,7 +258,7 @@ ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder.getFactory( FactoryFinder.APPLICATION_FACTORY); ApplicationImpl application = (ApplicationImpl) aFactory.getApplication(); ApplicationAssociate associate = ApplicationAssociate.getInstance(config.getServletContext()); + ApplicationAssociate associate = ApplicationAssociate.getInstance(getFacesContext().getExternalContext()); associate.addManagedBeanFactory(beanName, mbf);
        Hide
        Ed Burns added a comment -

        Jayashri, can you please address this? Perhaps we need to do an instanceof check.

        Ed

        Show
        Ed Burns added a comment - Jayashri, can you please address this? Perhaps we need to do an instanceof check. Ed

          People

          • Assignee:
            javaserverfaces-issues
            Reporter:
            jesion
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: