Top Description Fields Constructors Methods
org.apache.catalina.util

public final Class CustomObjectInputStream

extends ObjectInputStream
Class Inheritance
Imports
java.io.IOException, .InputStream, .InvalidClassException, .ObjectInputStream, .ObjectStreamClass, java.lang.reflect.Proxy, java.util.Set, .WeakHashMap, java.util.concurrent.ConcurrentHashMap, java.util.regex.Pattern, org.apache.juli.logging.Log, org.apache.tomcat.util.res.StringManager

Custom subclass of ObjectInputStream that loads from the class loader for this web application. This allows classes defined only with the web application to be found correctly.
Authors
Craig R. McClanahan, Bip Thelin

Field Summary

Modifier and TypeField and Description
private final String
private final Pattern
private final ClassLoader
classLoader

The class loader we will use to resolve classes.

private final Log
private static final WeakHashMap<ClassLoader, Set<String>>
private final Set<String>
private static final StringManager
private final boolean

Constructor Summary

AccessConstructor and Description
public
CustomObjectInputStream(InputStream
The input stream we will read from
stream
,
ClassLoader
The class loader used to instantiate objects
classLoader
)

Construct a new instance of CustomObjectInputStream without any filtering of deserialized classes.

public
CustomObjectInputStream(InputStream
The input stream we will read from
stream
,
ClassLoader
The class loader used to instantiate objects
classLoader
,
Log
The logger to use to report any issues. It may only be null if the filterMode does not require logging
log
,
Pattern
The regular expression to use to filter deserialized classes. The fully qualified class name must match this pattern for deserialization to be allowed if filtering is enabled.
allowedClassNamePattern
,
boolean
Should any failures be logged?
warnOnFailure
)

Construct a new instance of CustomObjectInputStream with filtering of deserialized classes.

Method Summary

Modifier and TypeMethod and Description
public Class<?>
resolveClass(ObjectStreamClass
Class description from the input stream
classDesc
)

Overrides java.io.ObjectInputStream.resolveClass.

Load the local class equivalent of the specified stream class description, by using the class loader assigned to this Context.

protected Class<?>
resolveProxyClass(String[]
the list of interface names that were deserialized in the proxy class descriptor
interfaces
)

Overrides java.io.ObjectInputStream.resolveProxyClass.

Return a proxy class that implements the interfaces named in a proxy class descriptor.

Inherited from java.io.ObjectInputStream:
availableclosedefaultReadObjectenableResolveObjectgetObjectInputFilterreadreadreadBooleanreadBytereadCharreadClassDescriptorreadDoublereadFieldsreadFloatreadFullyreadFullyreadIntreadLinereadLongreadObjectreadObjectOverridereadShortreadStreamHeaderreadUnsharedreadUnsignedBytereadUnsignedShortreadUTFregisterValidationresolveObjectsetObjectInputFilterskipBytes

Field Detail

allowedClassNameFilterback to summary
private final String allowedClassNameFilter
allowedClassNamePatternback to summary
private final Pattern allowedClassNamePattern
classLoaderback to summary
private final ClassLoader classLoader

The class loader we will use to resolve classes.

logback to summary
private final Log log
reportedClassCacheback to summary
private static final WeakHashMap<ClassLoader, Set<String>> reportedClassCache
reportedClassesback to summary
private final Set<String> reportedClasses
smback to summary
private static final StringManager sm
warnOnFailureback to summary
private final boolean warnOnFailure

Constructor Detail

CustomObjectInputStreamback to summary
public CustomObjectInputStream(InputStream stream, ClassLoader classLoader) throws IOException

Construct a new instance of CustomObjectInputStream without any filtering of deserialized classes.

Parameters
stream:InputStream

The input stream we will read from

classLoader:ClassLoader

The class loader used to instantiate objects

Exceptions
IOException:
if an input/output error occurs
CustomObjectInputStreamback to summary
public CustomObjectInputStream(InputStream stream, ClassLoader classLoader, Log log, Pattern allowedClassNamePattern, boolean warnOnFailure) throws IOException

Construct a new instance of CustomObjectInputStream with filtering of deserialized classes.

Parameters
stream:InputStream

The input stream we will read from

classLoader:ClassLoader

The class loader used to instantiate objects

log:Log

The logger to use to report any issues. It may only be null if the filterMode does not require logging

allowedClassNamePattern:Pattern

The regular expression to use to filter deserialized classes. The fully qualified class name must match this pattern for deserialization to be allowed if filtering is enabled.

warnOnFailure:boolean

Should any failures be logged?

Exceptions
IOException:
if an input/output error occurs

Method Detail

resolveClassback to summary
public Class<?> resolveClass(ObjectStreamClass classDesc) throws ClassNotFoundException, IOException

Overrides java.io.ObjectInputStream.resolveClass.

Load the local class equivalent of the specified stream class description, by using the class loader assigned to this Context.

Parameters
classDesc:ObjectStreamClass

Class description from the input stream

Returns:Class<?>

Doc from java.io.ObjectInputStream.resolveClass.

a Class object corresponding to desc

Annotations
@Override
Exceptions
ClassNotFoundException:
if this class cannot be found
IOException:
if an input/output error occurs
resolveProxyClassback to summary
protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException

Overrides java.io.ObjectInputStream.resolveProxyClass.

Return a proxy class that implements the interfaces named in a proxy class descriptor. Do this using the class loader assigned to this Context.

Parameters
interfaces:String[]

Doc from java.io.ObjectInputStream.resolveProxyClass.

the list of interface names that were deserialized in the proxy class descriptor

Returns:Class<?>

Doc from java.io.ObjectInputStream.resolveProxyClass.

a proxy class for the specified interfaces

Annotations
@Override
Exceptions
IOException:

Doc from java.io.ObjectInputStream.resolveProxyClass.

any exception thrown by the underlying InputStream

ClassNotFoundException:

Doc from java.io.ObjectInputStream.resolveProxyClass.

if the proxy class or any of the named interfaces could not be found