Coverage Report - org.apache.myfaces.shared.util.MyFacesObjectInputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
MyFacesObjectInputStream
15%
2/13
0%
0/2
3.667
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.shared.util;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.io.InputStream;
 23  
 import java.io.ObjectInputStream;
 24  
 import java.io.ObjectStreamClass;
 25  
 import java.lang.reflect.Proxy;
 26  
 
 27  
 /**
 28  
  * Tried to deploy v0.4.2 on JBoss 3.2.1 and had a classloading problem again.
 29  
  * The problem seemed to be with JspInfo, line 98. We are using an
 30  
  * ObjectInputStream Class, which then cannot find the classes to deserialize
 31  
  * the input stream.  The solution appears to be to subclass ObjectInputStream
 32  
  * (eg. CustomInputStream), and specify a different class-loading mechanism.
 33  
  */
 34  
 public class MyFacesObjectInputStream
 35  
     extends ObjectInputStream
 36  
 {
 37  
     public MyFacesObjectInputStream(InputStream in) throws IOException
 38  
     {
 39  32
         super(in);
 40  24
     }
 41  
 
 42  
     protected Class resolveClass(ObjectStreamClass desc)
 43  
         throws ClassNotFoundException, IOException
 44  
     {
 45  
         try
 46  
         {
 47  0
             return ClassUtils.classForName(desc.getName());
 48  
         }
 49  0
         catch (ClassNotFoundException e)
 50  
         {
 51  0
             return super.resolveClass(desc);
 52  
         }
 53  
     }
 54  
 
 55  
     protected Class resolveProxyClass(String[] interfaces) 
 56  
             throws IOException, ClassNotFoundException
 57  
     {
 58  
         // Only option that would match the current code would be to
 59  
         // expand ClassLoaderExtension to handle 'getProxyClass', which
 60  
         // would break all existing ClassLoaderExtension implementations
 61  0
         Class[] cinterfaces = new Class[interfaces.length];
 62  0
         for (int i = 0; i < interfaces.length; i++)
 63  
         {
 64  0
             cinterfaces[i] = ClassUtils.classForName(interfaces[i]);
 65  
         }
 66  
 
 67  
         try
 68  
         {
 69  
             // Try WebApp ClassLoader first
 70  0
             return Proxy.getProxyClass(ClassUtils.getContextClassLoader(), cinterfaces);
 71  
         }
 72  0
         catch (Exception ex)
 73  
         {
 74  
             // fallback: Try ClassLoader for MyFacesObjectInputStream (i.e. the myfaces.jar lib)
 75  
             try
 76  
             {
 77  0
                 return Proxy.getProxyClass(
 78  
                         MyFacesObjectInputStream.class.getClassLoader(), cinterfaces);
 79  
             }
 80  0
             catch (IllegalArgumentException e)
 81  
             {
 82  0
                 throw new ClassNotFoundException(e.toString(), e);
 83  
             }
 84  
         }
 85  
     }
 86  
 }