dev@javaserverfaces.java.net

Re: Review: Fix for bug 6229938

From: Jayashri Visvanathan <Jayashri.Visvanathan_at_Sun.COM>
Date: Fri, 22 Jul 2005 09:29:05 -0700

Sorry, forgot to attach ApplicationObjectInputStream.java Here it is
-Jayashri
Jayashri Visvanathan wrote:

> Fix for bug 6299638
> The ResponseStateManagerImpl.java file attempts to deserialize the
> UIComponent t
> ree when in client state saving using the system classloader (when
> this jar file
> is not in the application's WEB-INF/lib directory). This is OK as
> long as all
> classes can be found via the system classloader. However, this does
> not work wh
> en application-defined classes are part of the UIComponent tree.
>
> Fix already verified by Ken Paulsen
>
> M com/sun/faces/application/ViewHandlerImpl.java
> remove logging the snapshot of the tree because this could result
> in Null Ptr if ResponseWriter is not set.
>
> A com/sun/faces/renderkit/ApplicationObjectInputStream.java
> InputStream that resolves using WebApp class loader
> instead of the system classloader.
>
> M com/sun/faces/renderkit/ResponseStateManagerImpl.java
> Use the new ApplicationObjectInputStream that knows how to resolve
> application objects.
>
> M com/sun/faces/util/Util.java
> log JSF messages under webcontainer logger.
>
>------------------------------------------------------------------------
>
>Index: com/sun/faces/application/ViewHandlerImpl.java
>===================================================================
>RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ViewHandlerImpl.java,v
>retrieving revision 1.54
>diff -u -r1.54 ViewHandlerImpl.java
>--- com/sun/faces/application/ViewHandlerImpl.java 9 Jun 2005 22:37:45 -0000 1.54
>+++ com/sun/faces/application/ViewHandlerImpl.java 21 Jul 2005 22:45:32 -0000
>@@ -105,10 +105,8 @@
> }
>
> if (logger.isLoggable(Level.FINE)) {
>- String treePrintout =
>- com.sun.faces.util.DebugUtil.printTree(viewToRender);
>- logger.log(Level.FINE, "View after executing page: \n" +
>- treePrintout);
>+ logger.log(Level.FINE, "Completed building view for : \n" +
>+ viewToRender.getViewId());
> }
>
> // set up the ResponseWriter
>Index: com/sun/faces/renderkit/ResponseStateManagerImpl.java
>===================================================================
>RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/ResponseStateManagerImpl.java,v
>retrieving revision 1.23
>diff -u -r1.23 ResponseStateManagerImpl.java
>--- com/sun/faces/renderkit/ResponseStateManagerImpl.java 18 Jul 2005 22:49:03 -0000 1.23
>+++ com/sun/faces/renderkit/ResponseStateManagerImpl.java 21 Jul 2005 22:45:32 -0000
>@@ -126,7 +126,7 @@
> GZIPInputStream gis = null;
> ObjectInputStream ois = null;
> boolean compress = isCompressStateSet(context);
>-
>+
> try {
> byte[] bytes = byteArrayGuard.decrypt(context,
> (Base64.decode(viewString.getBytes())));
>@@ -136,9 +136,9 @@
> logger.fine("Deflating state before restoring..");
> }
> gis = new GZIPInputStream(bis);
>- ois = new ObjectInputStream(gis);
>+ ois = new ApplicationObjectInputStream(gis);
> } else {
>- ois = new ObjectInputStream(bis);
>+ ois = new ApplicationObjectInputStream(bis);
> }
> structure = ois.readObject();
> state = ois.readObject();
>Index: com/sun/faces/util/Util.java
>===================================================================
>RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/util/Util.java,v
>retrieving revision 1.166
>diff -u -r1.166 Util.java
>--- com/sun/faces/util/Util.java 20 Jul 2005 17:03:54 -0000 1.166
>+++ com/sun/faces/util/Util.java 21 Jul 2005 22:45:32 -0000
>@@ -74,7 +74,7 @@
> //
> // Private/Protected Constants
> //
>- public static final String FACES_LOGGER = "javax.enterprise.resource.jsf";
>+ public static final String FACES_LOGGER = "javax.enterprise.resource.webcontainer.jsf";
>
> public static final String FACES_LOG_STRINGS =
> "com.sun.faces.LogStrings";
>
>
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
>For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net
>
>


/*
 * $Id: HtmlBasicRenderer.java,v 1.96 2005/07/11 17:43:49 jayashri Exp $
 */

/*
 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package com.sun.faces.renderkit;

import com.sun.faces.RIConstants;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.util.Map;
import javax.faces.context.FacesContext;


/**
 * An ObjectInputStream that can deserialize objects relative to the current
 * application's class loader. In particular, this class works around
 * deserialization problems when the JSF JARs are shared (i.e. the
 * classloader has no access to application objects).
 */
public class ApplicationObjectInputStream extends ObjectInputStream {
   
    public ApplicationObjectInputStream() throws IOException,
            SecurityException {
        super();
    }
    
    public ApplicationObjectInputStream(InputStream in) throws IOException {
        super(in);
    }

    protected Class resolveClass(ObjectStreamClass desc) throws IOException,
            ClassNotFoundException {
        // When the container is about to call code associated with a
        // particular web application, it sets the context classloader to the
        // web app class loader. We make use of that here to locate any classes
        // that the UIComponent may hold references to. This won't cause a
        // problem to locate classes in the system class loader because
        // class loaders can look up the chain and not down the chain.
        return Class.forName(desc.getName(),true,
                Thread.currentThread().getContextClassLoader());
    }
}