2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
24
package org.jboss.remoting.serialization.impl.java;
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.io.ObjectInputStream;
29
import java.io.ObjectOutputStream;
30
import java.io.OptionalDataException;
31
import java.io.OutputStream;
32
import org.jboss.logging.Logger;
33
import org.jboss.remoting.Version;
34
import org.jboss.remoting.loading.ObjectInputStreamWithClassLoader;
35
import org.jboss.remoting.serialization.SerializationManager;
36
import org.jboss.remoting.serialization.SerializationStreamFactory;
37
import org.jboss.remoting.serialization.IMarshalledValue;
40
* $Id: JavaSerializationManager.java 4519 2008-08-30 06:20:07Z ron.sigal@jboss.com $
42
* @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
44
public class JavaSerializationManager extends SerializationManager
46
protected static final Logger log = Logger.getLogger(JavaSerializationManager.class);
48
public ObjectInputStream createInput(InputStream input, ClassLoader loader) throws IOException
50
if(log.isTraceEnabled())
52
log.trace("Creating ObjectInputStreamWithClassLoader");
54
return new ObjectInputStreamWithClassLoader(input, loader);
57
public ObjectOutputStream createOutput(OutputStream output) throws IOException
59
if(log.isTraceEnabled())
61
log.trace("Creating ObjectOutputStream");
63
return new ClearableObjectOutputStream(output);
67
* Creates a MarshalledValue that does lazy serialization.
69
public IMarshalledValue createdMarshalledValue(Object source) throws IOException
71
if(source instanceof IMarshalledValue)
73
return (IMarshalledValue) source;
77
return new JavaMarshalledValue(source);
81
public IMarshalledValue createMarshalledValueForClone(Object original) throws IOException {
82
return createdMarshalledValue(original);
85
public void sendObject(ObjectOutputStream oos, Object dataObject, int version) throws IOException
89
case Version.VERSION_1:
90
case Version.VERSION_2:
91
sendObjectVersion1_2(oos, dataObject);
94
case Version.VERSION_2_2:
95
sendObjectVersion2_2(oos, dataObject);
99
throw new IOException("Can not process version " + version + ". " +
100
"Supported versions: " + Version.VERSION_1 + ", " + Version.VERSION_2 + ", " + Version.VERSION_2_2);
105
protected void sendObjectVersion1_2(ObjectOutputStream oos, Object dataObject) throws IOException
107
oos.writeObject(dataObject);
109
// to make sure stream gets reset
110
// Stupid ObjectInputStream holds object graph
111
// can only be set by the client/server sending a TC_RESET
112
oos.writeObject(Boolean.TRUE);
117
protected void sendObjectVersion2_2(ObjectOutputStream oos, Object dataObject) throws IOException
120
oos.writeObject(dataObject);
123
if (oos instanceof ClearableObjectOutputStream)
125
((ClearableObjectOutputStream) oos).clear();
129
public Object receiveObject(InputStream inputStream, ClassLoader customClassLoader, int version) throws IOException, ClassNotFoundException
133
case Version.VERSION_1:
134
case Version.VERSION_2:
135
return receiveObjectVersion1_2(inputStream, customClassLoader);
137
case Version.VERSION_2_2:
138
return receiveObjectVersion2_2(inputStream, customClassLoader);
141
throw new IOException("Can not process version " + version + ". " +
142
"Supported versions: " + Version.VERSION_1 + ", " + Version.VERSION_2 + ", " + Version.VERSION_2_2);
147
protected Object receiveObjectVersion1_2(InputStream inputStream, ClassLoader customClassLoader) throws IOException, ClassNotFoundException
149
ObjectInputStream objInputStream = null;
151
if(inputStream instanceof ObjectInputStreamWithClassLoader)
153
((ObjectInputStreamWithClassLoader) inputStream).setClassLoader(customClassLoader);
154
objInputStream = (ObjectInputStream) inputStream;
156
/*else if(inputStream instanceof JBossObjectInputStream)
158
if(((JBossObjectInputStream) inputStream).getClassLoader() == null)
160
((JBossObjectInputStream) inputStream).setClassLoader(customClassLoader);
162
objInputStream = (ObjectInputStream) inputStream;
163
} -- for future reference */
164
else if(inputStream instanceof ObjectInputStream)
166
objInputStream = (ObjectInputStream) inputStream;
170
if(customClassLoader != null)
172
objInputStream = SerializationStreamFactory.getManagerInstance(SerializationStreamFactory.JAVA).createInput(inputStream, customClassLoader);
176
objInputStream = SerializationStreamFactory.getManagerInstance(SerializationStreamFactory.JAVA).createRegularInput(inputStream);
182
obj = objInputStream.readObject();
184
catch (IOException e)
192
objInputStream.readObject(); // for stupid ObjectInputStream reset
197
* Putting try catch around this because if using servlet sever invoker, the previous
198
* call is not needed, so will throw EOFException and can ignore.
204
protected Object receiveObjectVersion2_2(InputStream inputStream, ClassLoader customClassLoader) throws IOException, ClassNotFoundException
206
ObjectInputStream objInputStream = null;
208
if(inputStream instanceof ObjectInputStreamWithClassLoader)
210
((ObjectInputStreamWithClassLoader) inputStream).setClassLoader(customClassLoader);
211
objInputStream = (ObjectInputStream) inputStream;
213
/*else if(inputStream instanceof JBossObjectInputStream)
215
if(((JBossObjectInputStream) inputStream).getClassLoader() == null)
217
((JBossObjectInputStream) inputStream).setClassLoader(customClassLoader);
219
objInputStream = (ObjectInputStream) inputStream;
220
} -- for future reference */
221
else if(inputStream instanceof ObjectInputStream)
223
objInputStream = (ObjectInputStream) inputStream;
227
if(customClassLoader != null)
229
objInputStream = SerializationStreamFactory.getManagerInstance(SerializationStreamFactory.JAVA).createInput(inputStream, customClassLoader);
233
objInputStream = SerializationStreamFactory.getManagerInstance(SerializationStreamFactory.JAVA).createRegularInput(inputStream);
238
obj = objInputStream.readObject();
240
if(inputStream instanceof ObjectInputStreamWithClassLoader)
242
((ObjectInputStreamWithClassLoader) inputStream).clearCache();
b'\\ No newline at end of file'