├── .gitignore ├── README.md ├── pom.xml └── src ├── main └── java │ └── com │ └── ovea │ └── jetty │ └── session │ ├── Serializer.java │ ├── SerializerException.java │ ├── SessionIdManagerSkeleton.java │ ├── SessionManagerSkeleton.java │ ├── redis │ ├── JedisCallback.java │ ├── JedisExecutor.java │ ├── PooledJedisExecutor.java │ ├── RedisSessionIdManager.java │ └── RedisSessionManager.java │ └── serializer │ ├── BinarySerializer.java │ ├── JBossSerializer.java │ ├── JdkSerializer.java │ ├── JsonSerializer.java │ ├── SerializerSkeleton.java │ ├── XStreamSerializer.java │ └── jboss │ └── serial │ ├── Version.java │ ├── classmetamodel │ ├── ClassDescriptorStrategy.java │ ├── ClassMetaData.java │ ├── ClassMetaDataSlot.java │ ├── ClassMetadataField.java │ ├── ClassMetamodelFactory.java │ ├── ClassResolver.java │ ├── ConstructorManager.java │ ├── DefaultClassDescriptorStrategy.java │ ├── DefaultConstructorManager.java │ ├── FieldsManager.java │ ├── ReflectionFieldsManager.java │ ├── StreamingClass.java │ ├── SunConstructorManager.java │ └── UnsafeFieldsManager.java │ ├── exception │ └── SerializationException.java │ ├── finalcontainers │ ├── BooleanContainer.java │ ├── ByteContainer.java │ ├── CharacterContainer.java │ ├── DoubleContainer.java │ ├── FinalContainer.java │ ├── FloatContainer.java │ ├── IntegerContainer.java │ ├── LongContainer.java │ └── ShortContainer.java │ ├── io │ ├── Immutable.java │ ├── JBossObjectInputStream.java │ ├── JBossObjectInputStreamSharedTree.java │ ├── JBossObjectOutputStream.java │ ├── JBossObjectOutputStreamSharedTree.java │ ├── MarshalledObject.java │ └── MarshalledObjectForLocalCalls.java │ ├── objectmetamodel │ ├── DataContainer.java │ ├── DataContainerConstants.java │ ├── DataExport.java │ ├── DefaultObjectDescriptorStrategy.java │ ├── FieldsContainer.java │ ├── ObjectDescriptorFactory.java │ ├── ObjectDescriptorStrategy.java │ ├── ObjectSubstitutionInterface.java │ ├── ObjectsCache.java │ └── safecloning │ │ ├── SafeClone.java │ │ └── SafeCloningRepository.java │ ├── persister │ ├── ArrayPersister.java │ ├── ClassReferencePersister.java │ ├── EnumerationPersister.java │ ├── ExternalizePersister.java │ ├── ObjectInputStreamProxy.java │ ├── ObjectOutputStreamProxy.java │ ├── PersistResolver.java │ ├── Persister.java │ ├── ProxyPersister.java │ └── RegularObjectPersister.java │ ├── references │ ├── ArgumentPersistentReference.java │ ├── ConstructorPersistentReference.java │ ├── EmptyReference.java │ ├── FieldPersistentReference.java │ ├── MethodPersistentReference.java │ └── PersistentReference.java │ └── util │ ├── ClassMetaConsts.java │ ├── FastHashMap.java │ ├── HashStringUtil.java │ ├── PartitionedWeakHashMap.java │ ├── StringUtil.java │ └── StringUtilBuffer.java └── test ├── java ├── StartServers.java └── com │ └── ovea │ └── jetty │ └── session │ ├── ClusteringTest.java │ ├── JettyServer.java │ ├── RedisProcess.java │ └── serializer │ ├── JBossSerializerTest.java │ ├── JdkSerializerTest.java │ ├── JsonSerializerTest.java │ └── XStreamSerializerTest.java ├── resources ├── jndi.properties └── log4j.xml ├── webapp1 ├── WEB-INF │ ├── jetty-server.xml │ ├── jetty-web.xml │ └── web.xml └── index.jsp └── webapp2 ├── WEB-INF ├── jetty-server.xml ├── jetty-web.xml └── web.xml └── index.jsp /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *~ 3 | .*.swp 4 | .*.swo 5 | .loadpath 6 | .buildpath 7 | .project 8 | .settings 9 | .classpath 10 | .idea 11 | *.iml 12 | *.ipr 13 | *.iws 14 | nbproject 15 | .DS_Store 16 | target 17 | test-output 18 | tmp 19 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/Serializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session; 17 | 18 | public interface Serializer { 19 | 20 | void start(); 21 | 22 | void stop(); 23 | 24 | String serialize(Object o) throws SerializerException; 25 | 26 | T deserialize(String o, Class targetType) throws SerializerException; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/SerializerException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session; 17 | 18 | /** 19 | * @author Mathieu Carbou 20 | */ 21 | public final class SerializerException extends RuntimeException { 22 | private static final long serialVersionUID = 1669218829475607626L; 23 | 24 | public SerializerException(Throwable cause) { 25 | super(cause.getMessage(), cause); 26 | } 27 | 28 | public SerializerException(String message) { 29 | super(message); 30 | } 31 | 32 | public SerializerException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/redis/JedisCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.redis; 17 | 18 | import redis.clients.jedis.Jedis; 19 | 20 | /** 21 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 22 | */ 23 | interface JedisCallback { 24 | V execute(Jedis jedis); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/redis/JedisExecutor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.redis; 17 | 18 | /** 19 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 20 | */ 21 | interface JedisExecutor { 22 | V execute(JedisCallback cb); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/redis/PooledJedisExecutor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.redis; 17 | 18 | import redis.clients.jedis.Jedis; 19 | import redis.clients.jedis.JedisPool; 20 | import redis.clients.jedis.exceptions.JedisException; 21 | 22 | /** 23 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 24 | */ 25 | class PooledJedisExecutor implements JedisExecutor { 26 | private final JedisPool jedisPool; 27 | 28 | PooledJedisExecutor(JedisPool jedisPool) { 29 | this.jedisPool = jedisPool; 30 | } 31 | 32 | @Override 33 | public V execute(JedisCallback cb) { 34 | Jedis jedis = jedisPool.getResource(); 35 | try { 36 | return cb.execute(jedis); 37 | } catch (JedisException e) { 38 | jedisPool.returnBrokenResource(jedis); 39 | throw e; 40 | } finally { 41 | jedisPool.returnResource(jedis); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/redis/RedisSessionIdManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.redis; 17 | 18 | import com.ovea.jetty.session.SessionIdManagerSkeleton; 19 | import org.eclipse.jetty.server.Server; 20 | import org.eclipse.jetty.util.log.Log; 21 | import org.eclipse.jetty.util.log.Logger; 22 | import redis.clients.jedis.Jedis; 23 | import redis.clients.jedis.JedisPool; 24 | import redis.clients.jedis.TransactionBlock; 25 | import redis.clients.jedis.exceptions.JedisException; 26 | 27 | import javax.naming.InitialContext; 28 | import java.util.LinkedList; 29 | import java.util.List; 30 | 31 | /** 32 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 33 | */ 34 | public final class RedisSessionIdManager extends SessionIdManagerSkeleton { 35 | 36 | final static Logger LOG = Log.getLogger("com.ovea.jetty.session"); 37 | 38 | private static final Long ZERO = 0L; 39 | private static final String REDIS_SESSIONS_KEY = "jetty-sessions"; 40 | static final String REDIS_SESSION_KEY = "jetty-session-"; 41 | 42 | private final JedisExecutor jedisExecutor; 43 | 44 | public RedisSessionIdManager(Server server, JedisPool jedisPool) { 45 | super(server); 46 | this.jedisExecutor = new PooledJedisExecutor(jedisPool); 47 | } 48 | 49 | public RedisSessionIdManager(Server server, final String jndiName) { 50 | super(server); 51 | this.jedisExecutor = new JedisExecutor() { 52 | JedisExecutor delegate; 53 | 54 | @Override 55 | public V execute(JedisCallback cb) { 56 | if (delegate == null) { 57 | try { 58 | InitialContext ic = new InitialContext(); 59 | JedisPool jedisPool = (JedisPool) ic.lookup(jndiName); 60 | delegate = new PooledJedisExecutor(jedisPool); 61 | } catch (Exception e) { 62 | throw new IllegalStateException("Unable to find instance of " + JedisExecutor.class.getName() + " in JNDI location " + jndiName + " : " + e.getMessage(), e); 63 | } 64 | } 65 | return delegate.execute(cb); 66 | } 67 | }; 68 | } 69 | 70 | @Override 71 | protected void deleteClusterId(final String clusterId) { 72 | jedisExecutor.execute(new JedisCallback() { 73 | @Override 74 | public Object execute(Jedis jedis) { 75 | return jedis.srem(REDIS_SESSIONS_KEY, clusterId); 76 | } 77 | }); 78 | } 79 | 80 | @Override 81 | protected void storeClusterId(final String clusterId) { 82 | jedisExecutor.execute(new JedisCallback() { 83 | @Override 84 | public Object execute(Jedis jedis) { 85 | return jedis.sadd(REDIS_SESSIONS_KEY, clusterId); 86 | } 87 | }); 88 | } 89 | 90 | @Override 91 | protected boolean hasClusterId(final String clusterId) { 92 | return jedisExecutor.execute(new JedisCallback() { 93 | @Override 94 | public Boolean execute(Jedis jedis) { 95 | return jedis.sismember(REDIS_SESSIONS_KEY, clusterId); 96 | } 97 | }); 98 | } 99 | 100 | @Override 101 | protected List scavenge(final List clusterIds) { 102 | List expired = new LinkedList(); 103 | List status = jedisExecutor.execute(new JedisCallback>() { 104 | @Override 105 | public List execute(Jedis jedis) { 106 | return jedis.multi(new TransactionBlock() { 107 | @Override 108 | public void execute() throws JedisException { 109 | for (String clusterId : clusterIds) { 110 | exists(REDIS_SESSION_KEY + clusterId); 111 | } 112 | } 113 | }); 114 | } 115 | }); 116 | for (int i = 0; i < status.size(); i++) 117 | if (ZERO.equals(status.get(i))) 118 | expired.add(clusterIds.get(i)); 119 | if (LOG.isDebugEnabled() && !expired.isEmpty()) 120 | LOG.debug("[RedisSessionIdManager] Scavenger found {} sessions to expire: {}", expired.size(), expired); 121 | return expired; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/BinarySerializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import com.ovea.jetty.session.SerializerException; 19 | import org.eclipse.jetty.util.B64Code; 20 | 21 | import java.io.ByteArrayInputStream; 22 | import java.io.ByteArrayOutputStream; 23 | import java.io.InputStream; 24 | import java.io.OutputStream; 25 | import java.util.zip.GZIPInputStream; 26 | import java.util.zip.GZIPOutputStream; 27 | 28 | /** 29 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 30 | */ 31 | public abstract class BinarySerializer extends SerializerSkeleton { 32 | 33 | private boolean gzip = true; 34 | 35 | public void setGzip(boolean gzip) { 36 | this.gzip = gzip; 37 | } 38 | 39 | public boolean isGzip() { 40 | return gzip; 41 | } 42 | 43 | @Override 44 | public final String serialize(Object o) { 45 | try { 46 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 47 | if (gzip) { 48 | GZIPOutputStream gout = new GZIPOutputStream(baos); 49 | write(gout, o); 50 | gout.finish(); 51 | gout.close(); 52 | } else { 53 | write(baos, o); 54 | } 55 | return String.valueOf(B64Code.encode(baos.toByteArray(), false)); 56 | } catch (Exception e) { 57 | throw new SerializerException("Error serializing " + o + " : " + e.getMessage(), e); 58 | } 59 | } 60 | 61 | @Override 62 | public final T deserialize(String o, Class targetType) throws SerializerException { 63 | try { 64 | ByteArrayInputStream bais = new ByteArrayInputStream(B64Code.decode(o)); 65 | return targetType.cast(read(gzip ? new GZIPInputStream(bais) : bais)); 66 | } catch (Exception e) { 67 | throw new SerializerException("Error deserializing " + o + " : " + e.getMessage(), e); 68 | } 69 | } 70 | 71 | protected abstract void write(OutputStream out, Object o) throws Exception; 72 | 73 | protected abstract Object read(InputStream is) throws Exception; 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/JBossSerializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import com.ovea.jetty.session.serializer.jboss.serial.io.JBossObjectInputStream; 19 | import com.ovea.jetty.session.serializer.jboss.serial.io.JBossObjectOutputStream; 20 | 21 | import java.io.InputStream; 22 | import java.io.OutputStream; 23 | 24 | /** 25 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 26 | */ 27 | public final class JBossSerializer extends BinarySerializer { 28 | @Override 29 | protected void write(OutputStream out, Object o) throws Exception { 30 | JBossObjectOutputStream oos = new JBossObjectOutputStream(out); 31 | oos.writeObject(o); 32 | } 33 | 34 | @Override 35 | protected Object read(InputStream is) throws Exception { 36 | JBossObjectInputStream ois = new JBossObjectInputStream(is); 37 | return ois.readObject(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/JdkSerializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import java.io.InputStream; 19 | import java.io.ObjectInputStream; 20 | import java.io.ObjectOutputStream; 21 | import java.io.OutputStream; 22 | 23 | /** 24 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 25 | */ 26 | public final class JdkSerializer extends BinarySerializer { 27 | @Override 28 | protected void write(OutputStream out, Object o) throws Exception { 29 | ObjectOutputStream oos = new ObjectOutputStream(out); 30 | oos.writeObject(o); 31 | } 32 | 33 | @Override 34 | protected Object read(InputStream is) throws Exception { 35 | ObjectInputStream ois = new ObjectInputStream(is); 36 | return ois.readObject(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/JsonSerializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import com.ovea.jetty.session.SerializerException; 19 | import org.codehaus.jackson.map.DeserializationConfig; 20 | import org.codehaus.jackson.map.ObjectMapper; 21 | import org.codehaus.jackson.map.SerializationConfig; 22 | import org.codehaus.jackson.map.introspect.AnnotatedField; 23 | import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector; 24 | import org.codehaus.jackson.map.introspect.VisibilityChecker; 25 | 26 | import java.io.IOException; 27 | 28 | import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.ANY; 29 | 30 | /** 31 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 32 | */ 33 | public final class JsonSerializer extends SerializerSkeleton { 34 | 35 | private ObjectMapper mapper; 36 | 37 | @Override 38 | public void start() { 39 | mapper = new ObjectMapper(); 40 | 41 | mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, false); 42 | mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, false); 43 | mapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, false); 44 | mapper.configure(SerializationConfig.Feature.AUTO_DETECT_IS_GETTERS, false); 45 | mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true); 46 | mapper.configure(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true); 47 | mapper.configure(SerializationConfig.Feature.USE_STATIC_TYPING, false); 48 | mapper.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, false); 49 | mapper.configure(SerializationConfig.Feature.SORT_PROPERTIES_ALPHABETICALLY, true); 50 | mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, true); 51 | 52 | mapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, true); 53 | mapper.configure(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, false); 54 | mapper.configure(DeserializationConfig.Feature.AUTO_DETECT_CREATORS, true); 55 | mapper.configure(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, true); 56 | mapper.configure(DeserializationConfig.Feature.USE_GETTERS_AS_SETTERS, false); 57 | mapper.configure(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true); 58 | mapper.configure(DeserializationConfig.Feature.READ_ENUMS_USING_TO_STRING, true); 59 | 60 | mapper.setVisibilityChecker(new VisibilityChecker.Std(ANY, ANY, ANY, ANY, ANY)); 61 | 62 | super.start(); 63 | } 64 | 65 | @Override 66 | public void stop() { 67 | super.stop(); 68 | mapper = null; 69 | } 70 | 71 | @Override 72 | public String serialize(Object o) throws SerializerException { 73 | try { 74 | return mapper.writeValueAsString(o); 75 | } catch (IOException e) { 76 | throw new SerializerException(e); 77 | } 78 | } 79 | 80 | @Override 81 | public T deserialize(String o, Class targetType) throws SerializerException { 82 | try { 83 | return mapper.readValue(o, targetType); 84 | } catch (IOException e) { 85 | throw new SerializerException(e); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/SerializerSkeleton.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import com.ovea.jetty.session.Serializer; 19 | 20 | /** 21 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 22 | */ 23 | public abstract class SerializerSkeleton implements Serializer { 24 | @Override 25 | public void start() { 26 | } 27 | 28 | @Override 29 | public void stop() { 30 | } 31 | 32 | @Override 33 | public String serialize(Object o) { 34 | return o == null ? null : String.valueOf(o); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/XStreamSerializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import com.ovea.jetty.session.SerializerException; 19 | import com.thoughtworks.xstream.XStream; 20 | import com.thoughtworks.xstream.core.util.XmlHeaderAwareReader; 21 | import com.thoughtworks.xstream.io.HierarchicalStreamReader; 22 | import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 23 | import com.thoughtworks.xstream.io.StreamException; 24 | import com.thoughtworks.xstream.io.xml.AbstractXmlDriver; 25 | import com.thoughtworks.xstream.io.xml.CompactWriter; 26 | import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer; 27 | import com.thoughtworks.xstream.io.xml.XppReader; 28 | 29 | import java.io.*; 30 | 31 | /** 32 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 33 | */ 34 | public final class XStreamSerializer extends SerializerSkeleton { 35 | 36 | private XStream xStream; 37 | 38 | @Override 39 | public void start() { 40 | xStream = new XStream(new AbstractXmlDriver(new XmlFriendlyReplacer()) { 41 | @Override 42 | public HierarchicalStreamReader createReader(Reader in) { 43 | return new XppReader(in, xmlFriendlyReplacer()); 44 | } 45 | 46 | @Override 47 | public HierarchicalStreamReader createReader(InputStream in) { 48 | try { 49 | return createReader(new XmlHeaderAwareReader(in)); 50 | } catch (UnsupportedEncodingException e) { 51 | throw new StreamException(e); 52 | } catch (IOException e) { 53 | throw new StreamException(e); 54 | } 55 | } 56 | 57 | @Override 58 | public HierarchicalStreamWriter createWriter(Writer out) { 59 | return new CompactWriter(out, xmlFriendlyReplacer()); 60 | } 61 | 62 | @Override 63 | public HierarchicalStreamWriter createWriter(OutputStream out) { 64 | return createWriter(new OutputStreamWriter(out)); 65 | } 66 | }); 67 | super.start(); 68 | } 69 | 70 | @Override 71 | public void stop() { 72 | super.stop(); 73 | xStream = null; 74 | } 75 | 76 | @Override 77 | public String serialize(Object o) throws SerializerException { 78 | return xStream.toXML(o); 79 | } 80 | 81 | @Override 82 | public T deserialize(String o, Class targetType) throws SerializerException { 83 | return targetType.cast(xStream.fromXML(o)); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/Version.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial; 24 | 25 | /** 26 | * $Id: Version.java 336 2006-09-19 17:33:22Z csuconic $ 27 | * 28 | * @author Clebert Suconic 29 | */ 30 | public class Version { 31 | private static final String VERSION = "1.0.3.GA"; 32 | 33 | public static void main(String arg[]) { 34 | System.out.println(VERSION); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/ClassDescriptorStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors 4 | * as indicated by the @author tags. See the copyright.txt file in the 5 | * distribution for a full listing of individual contributors. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 23 | 24 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache; 25 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache.JBossSeralizationInputInterface; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * @author Clebert Suconic 31 | * @author Ron Sigal 32 | * @version

33 | * Copyright Jan 28, 2009 34 | *

35 | */ 36 | public interface ClassDescriptorStrategy { 37 | void writeClassDescription(Object obj, ClassMetaData metaData, ObjectsCache cache, int description) throws IOException; 38 | 39 | StreamingClass readClassDescription(ObjectsCache cache, JBossSeralizationInputInterface input, ClassResolver classResolver, String className) throws IOException; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/ClassMetadataField.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.references.FieldPersistentReference; 26 | import com.ovea.jetty.session.serializer.jboss.serial.util.HashStringUtil; 27 | 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * @author clebert suconic 32 | */ 33 | public class ClassMetadataField { 34 | public ClassMetadataField(Field field) { 35 | this.setField(field); 36 | this.setFieldName(field.getName()); 37 | this.shaHash = HashStringUtil.hashName(field.getType().getName() + "$" + field.getName()); 38 | this.setObject(!ClassMetamodelFactory.isImmutable(field.getType())); 39 | } 40 | 41 | String fieldName; 42 | 43 | FieldPersistentReference field; 44 | 45 | /** 46 | * Used only by {@link UnsafeFieldsManager} 47 | */ 48 | long unsafeKey; 49 | 50 | boolean isObject; 51 | 52 | long shaHash; 53 | 54 | /** 55 | * Order the field appears on the slot 56 | */ 57 | short order; 58 | 59 | 60 | /** 61 | * @return Returns the field. 62 | */ 63 | public Field getField() { 64 | return (Field) field.get(); 65 | } 66 | 67 | /** 68 | * @param field The field to set. 69 | */ 70 | public void setField(Field afield) { 71 | this.field = new FieldPersistentReference(afield, ClassMetaData.REFERENCE_TYPE_IN_USE); 72 | } 73 | 74 | /** 75 | * @return Returns the fieldName. 76 | */ 77 | public String getFieldName() { 78 | return fieldName; 79 | } 80 | 81 | /** 82 | * @param fieldName The fieldName to set. 83 | */ 84 | public void setFieldName(String fieldName) { 85 | this.fieldName = fieldName; 86 | } 87 | 88 | /** 89 | * @return Returns the isObject. 90 | */ 91 | public boolean isObject() { 92 | return isObject; 93 | } 94 | 95 | /** 96 | * @param isObject The isObject to set. 97 | */ 98 | public void setObject(boolean isObject) { 99 | this.isObject = isObject; 100 | } 101 | 102 | public long getUnsafeKey() { 103 | return unsafeKey; 104 | } 105 | 106 | public void setUnsafeKey(long unsafeKey) { 107 | this.unsafeKey = unsafeKey; 108 | } 109 | 110 | public long getShaHash() { 111 | return shaHash; 112 | } 113 | 114 | public void setShaHash(long shaHash) { 115 | this.shaHash = shaHash; 116 | } 117 | 118 | public short getOrder() { 119 | return order; 120 | } 121 | 122 | public void setOrder(short order) { 123 | this.order = order; 124 | } 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/ClassResolver.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 24 | 25 | /** 26 | * This interface is implemented by JbossobjectinputStream, and its used to validate if a class has readResolve implemented 27 | */ 28 | public interface ClassResolver { 29 | 30 | public Class resolveClass(String name) throws ClassNotFoundException; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/ConstructorManager.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.util.ClassMetaConsts; 26 | 27 | import java.lang.reflect.Constructor; 28 | 29 | /** 30 | * Find the constructor that respect the serialization behavior 31 | * $Id: ConstructorManager.java 175 2006-03-16 16:25:02Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public abstract class ConstructorManager implements ClassMetaConsts { 36 | public abstract Constructor getConstructor(Class clazz) throws SecurityException, NoSuchMethodException; 37 | 38 | public abstract boolean isSupported(); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/DefaultClassDescriptorStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors 4 | * as indicated by the @author tags. See the copyright.txt file in the 5 | * distribution for a full listing of individual contributors. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 23 | 24 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.DataContainerConstants; 25 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache; 26 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache.JBossSeralizationInputInterface; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * @author Clebert Suconic 32 | * @author Ron Sigal 33 | * @version

34 | * Copyright Jan 28, 2009 35 | *

36 | */ 37 | public class DefaultClassDescriptorStrategy implements ClassDescriptorStrategy { 38 | public void writeClassDescription(Object obj, ClassMetaData metaData, ObjectsCache cache, int description) throws IOException { 39 | writeClassDescription(obj, metaData, cache, description, true); 40 | } 41 | 42 | public void writeClassDescription(Object obj, ClassMetaData metaData, ObjectsCache cache, int description, boolean writeClassDescription) throws IOException { 43 | ObjectsCache.JBossSeralizationOutputInterface outputParent = cache.getOutput(); 44 | int cacheId = cache.findIdInCacheWrite(metaData, false); 45 | if (cacheId == 0) { 46 | cacheId = cache.putObjectInCacheWrite(metaData, false); 47 | outputParent.writeByte(DataContainerConstants.NEWDEF); 48 | outputParent.addObjectReference(cacheId); 49 | if (writeClassDescription) { 50 | outputParent.writeUTF(metaData.getClassName()); 51 | } 52 | StreamingClass.saveStream(metaData, outputParent); 53 | } else { 54 | outputParent.writeByte(DataContainerConstants.OBJECTREF); 55 | outputParent.addObjectReference(cacheId); 56 | } 57 | } 58 | 59 | public StreamingClass readClassDescription(ObjectsCache cache, JBossSeralizationInputInterface input, ClassResolver classResolver, String className) throws IOException { 60 | return readClassDescription(cache, input, classResolver, className, null); 61 | } 62 | 63 | public StreamingClass readClassDescription(ObjectsCache cache, JBossSeralizationInputInterface input, ClassResolver classResolver, String className, Class clazz) throws IOException { 64 | byte defClass = input.readByte(); 65 | StreamingClass streamingClass = null; 66 | if (defClass == DataContainerConstants.NEWDEF) { 67 | int referenceId = input.readObjectReference(); 68 | if (className == null) { 69 | className = input.readUTF(); 70 | } 71 | 72 | streamingClass = StreamingClass.readStream(input, classResolver, cache.getLoader(), className); 73 | cache.putObjectInCacheRead(referenceId, streamingClass); 74 | } else { 75 | int referenceId = input.readObjectReference(); 76 | streamingClass = (StreamingClass) cache.findObjectInCacheRead(referenceId); 77 | if (streamingClass == null) { 78 | throw new IOException("Didn't find StreamingClass circular refernce id=" + referenceId); 79 | } 80 | } 81 | 82 | return streamingClass; 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/DefaultConstructorManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Distributable under LGPL license. 5 | * See terms of license at gnu.org. 6 | */ 7 | 8 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 9 | 10 | import java.lang.reflect.Constructor; 11 | 12 | /** 13 | * If SunConstructorManager is not available in this current JVM, we will use the default one which only looks for the default constructor 14 | * at the current class 15 | * $Id: DefaultConstructorManager.java 175 2006-03-16 16:25:02Z csuconic $ 16 | * 17 | * @author Clebert Suconic 18 | */ 19 | public class DefaultConstructorManager extends ConstructorManager { 20 | 21 | /* (non-Javadoc) 22 | * @see org.jboss.serial.classmetamodel.ConstructorManager#getConstructor(java.lang.Class) 23 | */ 24 | public Constructor getConstructor(Class clazz) throws SecurityException, NoSuchMethodException { 25 | Constructor constr = clazz.getDeclaredConstructor(EMPTY_CLASS_ARRY); 26 | constr.setAccessible(true); 27 | return constr; 28 | } 29 | 30 | /* (non-Javadoc) 31 | * @see org.jboss.serial.classmetamodel.ConstructorManager#isSupported() 32 | */ 33 | public boolean isSupported() { 34 | return true; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/FieldsManager.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 24 | 25 | import java.lang.reflect.Field; 26 | 27 | /** 28 | * $Id: FieldsManager.java 217 2006-04-18 18:42:42Z csuconic $ 29 | *

30 | * FieldsManager is the class responsible to manage changing the fields. 31 | * It will be up to implementations of this class to decide wether we should use Unsafe operations or 32 | * pure reflection 33 | * 34 | * @author Clebert Suconic 35 | */ 36 | public abstract class FieldsManager { 37 | 38 | /** 39 | * We need to test if Reflection could be used to change final fields or not. 40 | * In case negative we will use UnsafeFieldsManager and this class will be used to execute this test 41 | */ 42 | private static class InternalFinalFieldTestClass { 43 | final int x = 0; 44 | } 45 | 46 | private static FieldsManager fieldsManager; 47 | 48 | static { 49 | if (UnsafeFieldsManager.isSupported()) { 50 | fieldsManager = new UnsafeFieldsManager(); 51 | } else { 52 | try { 53 | Field fieldX = InternalFinalFieldTestClass.class.getDeclaredField("x"); 54 | fieldX.setAccessible(true); 55 | 56 | InternalFinalFieldTestClass fieldTest = new InternalFinalFieldTestClass(); 57 | fieldX.setInt(fieldTest, 33); 58 | 59 | 60 | fieldsManager = new ReflectionFieldsManager(); 61 | 62 | } catch (Throwable e) { 63 | } 64 | } 65 | if (fieldsManager == null) { 66 | System.err.println("Couldn't set FieldsManager, JBoss Serialization can't work properly on this VM"); 67 | } 68 | 69 | } 70 | 71 | public static FieldsManager getFieldsManager() { 72 | return fieldsManager; 73 | } 74 | 75 | 76 | public abstract void fillMetadata(ClassMetadataField field); 77 | 78 | public abstract void setInt(Object obj, ClassMetadataField field, int value); 79 | 80 | public abstract int getInt(Object obj, ClassMetadataField field); 81 | 82 | public abstract void setByte(Object obj, ClassMetadataField field, byte value); 83 | 84 | public abstract byte getByte(Object obj, ClassMetadataField field); 85 | 86 | public abstract void setLong(Object obj, ClassMetadataField field, long value); 87 | 88 | public abstract long getLong(Object obj, ClassMetadataField field); 89 | 90 | public abstract void setFloat(Object obj, ClassMetadataField field, float value); 91 | 92 | public abstract float getFloat(Object obj, ClassMetadataField field); 93 | 94 | public abstract void setDouble(Object obj, ClassMetadataField field, double value); 95 | 96 | public abstract double getDouble(Object obj, ClassMetadataField field); 97 | 98 | public abstract void setShort(Object obj, ClassMetadataField field, short value); 99 | 100 | public abstract short getShort(Object obj, ClassMetadataField field); 101 | 102 | public abstract void setCharacter(Object obj, ClassMetadataField field, char value); 103 | 104 | public abstract char getCharacter(Object obj, ClassMetadataField field); 105 | 106 | public abstract void setBoolean(Object obj, ClassMetadataField field, boolean value); 107 | 108 | public abstract boolean getBoolean(Object obj, ClassMetadataField field); 109 | 110 | public abstract void setObject(Object obj, ClassMetadataField field, Object value); 111 | 112 | public abstract Object getObject(Object obj, ClassMetadataField field); 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/ReflectionFieldsManager.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 24 | 25 | /** 26 | * $Id: ReflectionFieldsManager.java 217 2006-04-18 18:42:42Z csuconic $ 27 | * 28 | * @author Clebert Suconic 29 | */ 30 | public class ReflectionFieldsManager extends FieldsManager { 31 | public void fillMetadata(ClassMetadataField field) { 32 | if (field.getField() != null) { 33 | field.getField().setAccessible(true); 34 | } 35 | } 36 | 37 | public void setInt(Object obj, ClassMetadataField field, int value) { 38 | try { 39 | field.getField().setInt(obj, value); 40 | } catch (Exception e) { 41 | throw new RuntimeException(e); 42 | } 43 | } 44 | 45 | public int getInt(Object obj, ClassMetadataField field) { 46 | try { 47 | return field.getField().getInt(obj); 48 | } catch (Exception e) { 49 | throw new RuntimeException(e); 50 | } 51 | } 52 | 53 | public void setByte(Object obj, ClassMetadataField field, byte value) { 54 | try { 55 | field.getField().setByte(obj, value); 56 | } catch (Exception e) { 57 | throw new RuntimeException(e); 58 | } 59 | } 60 | 61 | public byte getByte(Object obj, ClassMetadataField field) { 62 | try { 63 | return field.getField().getByte(obj); 64 | } catch (Exception e) { 65 | throw new RuntimeException(e); 66 | } 67 | } 68 | 69 | public void setLong(Object obj, ClassMetadataField field, long value) { 70 | try { 71 | field.getField().setLong(obj, value); 72 | } catch (Exception e) { 73 | throw new RuntimeException(e); 74 | } 75 | } 76 | 77 | public long getLong(Object obj, ClassMetadataField field) { 78 | try { 79 | return field.getField().getLong(obj); 80 | } catch (Exception e) { 81 | throw new RuntimeException(e); 82 | } 83 | } 84 | 85 | public void setFloat(Object obj, ClassMetadataField field, float value) { 86 | try { 87 | field.getField().setFloat(obj, value); 88 | } catch (Exception e) { 89 | throw new RuntimeException(e); 90 | } 91 | } 92 | 93 | public float getFloat(Object obj, ClassMetadataField field) { 94 | try { 95 | return field.getField().getFloat(obj); 96 | } catch (Exception e) { 97 | throw new RuntimeException(e); 98 | } 99 | } 100 | 101 | public void setDouble(Object obj, ClassMetadataField field, double value) { 102 | try { 103 | field.getField().setDouble(obj, value); 104 | } catch (Exception e) { 105 | throw new RuntimeException(e); 106 | } 107 | } 108 | 109 | public double getDouble(Object obj, ClassMetadataField field) { 110 | try { 111 | return field.getField().getDouble(obj); 112 | } catch (Exception e) { 113 | throw new RuntimeException(e); 114 | } 115 | } 116 | 117 | public void setShort(Object obj, ClassMetadataField field, short value) { 118 | try { 119 | field.getField().setShort(obj, value); 120 | } catch (Exception e) { 121 | throw new RuntimeException(e); 122 | } 123 | } 124 | 125 | public short getShort(Object obj, ClassMetadataField field) { 126 | try { 127 | return field.getField().getShort(obj); 128 | } catch (Exception e) { 129 | throw new RuntimeException(e); 130 | } 131 | } 132 | 133 | public void setCharacter(Object obj, ClassMetadataField field, char value) { 134 | try { 135 | field.getField().setChar(obj, value); 136 | } catch (Exception e) { 137 | throw new RuntimeException(e); 138 | } 139 | } 140 | 141 | public char getCharacter(Object obj, ClassMetadataField field) { 142 | try { 143 | return field.getField().getChar(obj); 144 | } catch (Exception e) { 145 | throw new RuntimeException(e); 146 | } 147 | } 148 | 149 | public void setBoolean(Object obj, ClassMetadataField field, boolean value) { 150 | try { 151 | field.getField().setBoolean(obj, value); 152 | } catch (Exception e) { 153 | throw new RuntimeException(e); 154 | } 155 | } 156 | 157 | public boolean getBoolean(Object obj, ClassMetadataField field) { 158 | try { 159 | return field.getField().getBoolean(obj); 160 | } catch (Exception e) { 161 | throw new RuntimeException(e); 162 | } 163 | } 164 | 165 | public void setObject(Object obj, ClassMetadataField field, Object value) { 166 | try { 167 | field.getField().set(obj, value); 168 | } catch (Exception e) { 169 | throw new RuntimeException(e); 170 | } 171 | } 172 | 173 | public Object getObject(Object obj, ClassMetadataField field) { 174 | try { 175 | return field.getField().get(obj); 176 | } catch (Exception e) { 177 | throw new RuntimeException(e); 178 | } 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/StreamingClass.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 24 | 25 | import java.io.IOException; 26 | import java.io.ObjectInput; 27 | import java.io.ObjectOutput; 28 | 29 | /** 30 | * A Streaming Class is created every time an object is created on the treaming. 31 | * It contains the current version and fields dependencies 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class StreamingClass { 36 | public StreamingClass(Class clazz) throws IOException { 37 | metadata = ClassMetamodelFactory.getClassMetaData(clazz, false); 38 | } 39 | 40 | public StreamingClass(ClassMetaData clazz) throws IOException { 41 | metadata = clazz; 42 | } 43 | 44 | ClassMetaData metadata; 45 | 46 | /** 47 | * Position the fields used by this StreamingClass on Read. 48 | * When a StreamingClass is read from a Streaming, an older version could have a different order on fields. This array is used to manage that 49 | */ 50 | private short[][] keyFields; 51 | 52 | 53 | public static void saveStream(ClassMetaData metadata, ObjectOutput out) throws IOException { 54 | ClassMetaDataSlot slots[] = metadata.getSlots(); 55 | out.writeShort(slots.length); 56 | for (int slotNR = 0; slotNR < slots.length; slotNR++) { 57 | out.writeLong(slots[slotNR].getShaHash()); 58 | ClassMetadataField[] fields = slots[slotNR].getFields(); 59 | out.writeShort(fields.length); 60 | for (int fieldNR = 0; fieldNR < fields.length; fieldNR++) { 61 | out.writeLong(fields[fieldNR].getShaHash()); 62 | } 63 | } 64 | } 65 | 66 | public static StreamingClass readStream(ObjectInput inp, ClassResolver resolver, ClassLoader loader, String className) throws IOException { 67 | ClassMetaData metadata = ClassMetamodelFactory.getClassMetaData(className, resolver, loader, false); 68 | StreamingClass streamClass = new StreamingClass(metadata); 69 | 70 | // number of slots on streaming 71 | short slotsNrOnStreaming = inp.readShort(); 72 | ClassMetaDataSlot slots[] = metadata.getSlots(); 73 | if (slotsNrOnStreaming != slots.length) { 74 | throw new IOException("The hierarchy of " + className + " is different in your current classPath"); 75 | } 76 | 77 | short[][] keyfields = new short[slots.length][]; 78 | 79 | for (int slotIndex = 0; slotIndex < slots.length; slotIndex++) { 80 | long shaSlotHash = inp.readLong(); 81 | if (slots[slotIndex].getShaHash() != shaSlotHash) { 82 | throw new IOException("The hierarchy of " + className + " is different in your current classPath"); 83 | } 84 | short numberofFields = inp.readShort(); 85 | keyfields[slotIndex] = new short[numberofFields]; 86 | 87 | ClassMetadataField fields[] = slots[slotIndex].getFields(); 88 | if (numberofFields > fields.length) { 89 | throw new IOException("Current classpath has lesser fields on " + className + " than its original version"); 90 | } 91 | for (short fieldIndex = 0; fieldIndex < fields.length; fieldIndex++) { 92 | long hashfield = inp.readLong(); 93 | ClassMetadataField fieldOnHash = slots[slotIndex].getField(hashfield); 94 | if (fieldOnHash == null) { 95 | throw new IOException("Field hash " + fieldOnHash + " is not available on current classPath for class " + className); 96 | } 97 | keyfields[slotIndex][fieldIndex] = fieldOnHash.getOrder(); 98 | } 99 | } 100 | 101 | streamClass.keyFields = keyfields; 102 | 103 | return streamClass; 104 | } 105 | 106 | 107 | public short[][] getKeyFields() { 108 | return keyFields; 109 | } 110 | 111 | 112 | public void setKeyFields(short[][] keyFields) { 113 | this.keyFields = keyFields; 114 | } 115 | 116 | public ClassMetaData getMetadata() { 117 | return metadata; 118 | } 119 | 120 | public void setMetadata(ClassMetaData metadata) { 121 | this.metadata = metadata; 122 | } 123 | 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/SunConstructorManager.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 24 | 25 | import sun.reflect.ReflectionFactory; 26 | 27 | import java.io.Externalizable; 28 | import java.io.Serializable; 29 | import java.lang.reflect.Constructor; 30 | 31 | 32 | /** 33 | * This constructor manager requires sun package present. 34 | * If the class is not present, we will not be able to use this constructor manager 35 | * $Id: SunConstructorManager.java 315 2006-06-15 16:29:07Z csuconic $ 36 | * 37 | * @author Clebert Suconic 38 | */ 39 | public class SunConstructorManager extends ConstructorManager { 40 | static boolean supported = true; 41 | 42 | static { 43 | try { 44 | reflectionFactory = ReflectionFactory.getReflectionFactory(); 45 | } catch (Throwable e) { 46 | e.printStackTrace(); 47 | supported = false; 48 | } 49 | } 50 | 51 | static ReflectionFactory reflectionFactory; 52 | 53 | 54 | /* (non-Javadoc) 55 | * @see org.jboss.serial.classmetamodel.ConstructorManager#getConstructor(java.lang.Class) 56 | */ 57 | public Constructor getConstructor(Class clazz) throws SecurityException, NoSuchMethodException { 58 | if (clazz.isInterface()) { 59 | throw new NoSuchMethodException("Can't create a constructor for a pure interface"); 60 | } else if (!Serializable.class.isAssignableFrom(clazz)) { 61 | Constructor constr = clazz.getDeclaredConstructor(EMPTY_CLASS_ARRY); 62 | constr.setAccessible(true); 63 | return constr; 64 | } else if (Externalizable.class.isAssignableFrom(clazz)) { 65 | Constructor constr = clazz.getConstructor(EMPTY_CLASS_ARRY); 66 | constr.setAccessible(true); 67 | return constr; 68 | } else { 69 | Class currentClass = clazz; 70 | while (Serializable.class.isAssignableFrom(currentClass)) { 71 | currentClass = currentClass.getSuperclass(); 72 | } 73 | Constructor constr = currentClass.getDeclaredConstructor(EMPTY_CLASS_ARRY); 74 | constr.setAccessible(true); 75 | 76 | // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6220682 77 | Constructor newConstructor = reflectionFactory.newConstructorForSerialization(clazz, constr); 78 | newConstructor.setAccessible(true); 79 | 80 | return newConstructor; 81 | } 82 | } 83 | 84 | /* (non-Javadoc) 85 | * @see org.jboss.serial.classmetamodel.ConstructorManager#isSupported() 86 | */ 87 | public boolean isSupported() { 88 | return supported; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/classmetamodel/UnsafeFieldsManager.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.classmetamodel; 24 | 25 | import sun.misc.Unsafe; 26 | 27 | import java.io.ObjectStreamClass; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: UnsafeFieldsManager.java 217 2006-04-18 18:42:42Z csuconic $ 32 | *

33 | * This FieldsManager uses the only hook available to change final fields into JVM 1.4 (operations with sun.misc.Unsafe). 34 | * As this is a reflection functionality, we've gotten the Unsafe instance used by java.io.ObjectStreamClass 35 | * 36 | * @author Clebert Suconic 37 | */ 38 | public class UnsafeFieldsManager extends FieldsManager { 39 | UnsafeFieldsManager() { 40 | } 41 | 42 | static Unsafe unsafe; 43 | 44 | public static boolean isSupported() { 45 | return unsafe != null; 46 | } 47 | 48 | static { 49 | try { 50 | Class[] classes = ObjectStreamClass.class.getDeclaredClasses(); 51 | for (int i = 0; i < classes.length; i++) { 52 | if (classes[i].getName().equals("java.io.ObjectStreamClass$FieldReflector")) { 53 | Field unsafeField = classes[i].getDeclaredField("unsafe"); 54 | unsafeField.setAccessible(true); 55 | 56 | unsafe = (Unsafe) unsafeField.get(null); 57 | break; 58 | } 59 | } 60 | } catch (Throwable e) { 61 | //e.printStackTrace() 62 | } 63 | } 64 | 65 | public void fillMetadata(ClassMetadataField field) { 66 | if (field.getField() != null) { 67 | field.setUnsafeKey(unsafe.objectFieldOffset(field.getField())); 68 | } 69 | } 70 | 71 | public void setInt(Object obj, ClassMetadataField field, int value) { 72 | unsafe.putInt(obj, field.getUnsafeKey(), value); 73 | } 74 | 75 | public int getInt(Object obj, ClassMetadataField field) { 76 | return unsafe.getInt(obj, field.getUnsafeKey()); 77 | } 78 | 79 | public void setByte(Object obj, ClassMetadataField field, byte value) { 80 | unsafe.putByte(obj, field.getUnsafeKey(), value); 81 | } 82 | 83 | public byte getByte(Object obj, ClassMetadataField field) { 84 | return unsafe.getByte(obj, field.getUnsafeKey()); 85 | } 86 | 87 | public void setLong(Object obj, ClassMetadataField field, long value) { 88 | unsafe.putLong(obj, field.getUnsafeKey(), value); 89 | } 90 | 91 | public long getLong(Object obj, ClassMetadataField field) { 92 | return unsafe.getLong(obj, field.getUnsafeKey()); 93 | } 94 | 95 | public void setFloat(Object obj, ClassMetadataField field, float value) { 96 | unsafe.putFloat(obj, field.getUnsafeKey(), value); 97 | } 98 | 99 | public float getFloat(Object obj, ClassMetadataField field) { 100 | return unsafe.getFloat(obj, field.getUnsafeKey()); 101 | } 102 | 103 | public void setDouble(Object obj, ClassMetadataField field, double value) { 104 | unsafe.putDouble(obj, field.getUnsafeKey(), value); 105 | } 106 | 107 | public double getDouble(Object obj, ClassMetadataField field) { 108 | return unsafe.getDouble(obj, field.getUnsafeKey()); 109 | } 110 | 111 | public void setShort(Object obj, ClassMetadataField field, short value) { 112 | unsafe.putShort(obj, field.getUnsafeKey(), value); 113 | } 114 | 115 | public short getShort(Object obj, ClassMetadataField field) { 116 | return unsafe.getShort(obj, field.getUnsafeKey()); 117 | } 118 | 119 | public void setCharacter(Object obj, ClassMetadataField field, char value) { 120 | unsafe.putChar(obj, field.getUnsafeKey(), value); 121 | } 122 | 123 | public char getCharacter(Object obj, ClassMetadataField field) { 124 | return unsafe.getChar(obj, field.getUnsafeKey()); 125 | } 126 | 127 | public void setBoolean(Object obj, ClassMetadataField field, boolean value) { 128 | unsafe.putBoolean(obj, field.getUnsafeKey(), value); 129 | } 130 | 131 | public boolean getBoolean(Object obj, ClassMetadataField field) { 132 | return unsafe.getBoolean(obj, field.getUnsafeKey()); 133 | } 134 | 135 | public void setObject(Object obj, ClassMetadataField field, Object value) { 136 | unsafe.putObject(obj, field.getUnsafeKey(), value); 137 | } 138 | 139 | public Object getObject(Object obj, ClassMetadataField field) { 140 | return unsafe.getObject(obj, field.getUnsafeKey()); 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/exception/SerializationException.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.exception; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * $Id: SerializationException.java 217 2006-04-18 18:42:42Z csuconic $ 29 | * 30 | * @author Clebert Suconic 31 | */ 32 | public class SerializationException extends IOException { 33 | public SerializationException(String message, Exception source) { 34 | this(message); 35 | this.initCause(source); 36 | } 37 | 38 | public SerializationException(String message) { 39 | super(message); 40 | } 41 | 42 | public SerializationException(Exception ex) { 43 | this(ex.getMessage(), ex); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/BooleanContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import java.io.DataInput; 26 | import java.io.DataOutput; 27 | import java.io.IOException; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: BooleanContainer.java 217 2006-04-18 18:42:42Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | * @author Bob Morris - Added singletons TRUE and FALSE 35 | */ 36 | public class BooleanContainer extends FinalContainer { 37 | static private BooleanContainer TRUE = new BooleanContainer(true); 38 | static private BooleanContainer FALSE = new BooleanContainer(false); 39 | 40 | boolean value; 41 | 42 | static public BooleanContainer valueOf(boolean value) { 43 | return value ? TRUE : FALSE; 44 | } 45 | 46 | private BooleanContainer(boolean value) { 47 | this.value = value; 48 | } 49 | 50 | public boolean getValue() { 51 | return value; 52 | } 53 | 54 | public boolean equals(Object o) { 55 | if (this == o) return true; 56 | if (o == null || getClass() != o.getClass()) return false; 57 | 58 | final BooleanContainer that = (BooleanContainer) o; 59 | 60 | if (value != that.value) return false; 61 | 62 | return true; 63 | } 64 | 65 | public int hashCode() { 66 | return (value ? 1 : 0); 67 | } 68 | 69 | public void writeMyself(DataOutput output) throws IOException { 70 | output.writeBoolean(value); 71 | } 72 | 73 | public void readMyself(DataInput input) throws IOException { 74 | value = input.readBoolean(); 75 | } 76 | 77 | public void setPrimitive(Object obj, Field field) throws IllegalAccessException { 78 | field.setBoolean(obj, value); 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/ByteContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import java.io.DataInput; 26 | import java.io.DataOutput; 27 | import java.io.IOException; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: ByteContainer.java 217 2006-04-18 18:42:42Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class ByteContainer extends FinalContainer { 36 | byte value; 37 | 38 | public ByteContainer(byte value) { 39 | this.value = value; 40 | } 41 | 42 | public ByteContainer() { 43 | } 44 | 45 | public byte getValue() { 46 | return value; 47 | } 48 | 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | 53 | final ByteContainer that = (ByteContainer) o; 54 | 55 | if (value != that.value) return false; 56 | 57 | return true; 58 | } 59 | 60 | public int hashCode() { 61 | return (int) value; 62 | } 63 | 64 | public void writeMyself(DataOutput output) throws IOException { 65 | output.write(value); 66 | } 67 | 68 | public void readMyself(DataInput input) throws IOException { 69 | value = input.readByte(); 70 | } 71 | 72 | public void setPrimitive(Object obj, Field field) throws IllegalAccessException { 73 | field.setByte(obj, value); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/CharacterContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import java.io.DataInput; 26 | import java.io.DataOutput; 27 | import java.io.IOException; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: CharacterContainer.java 217 2006-04-18 18:42:42Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class CharacterContainer extends FinalContainer { 36 | char value; 37 | 38 | public CharacterContainer(char value) { 39 | this.value = value; 40 | } 41 | 42 | public CharacterContainer() { 43 | } 44 | 45 | public char getValue() { 46 | return value; 47 | } 48 | 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | 53 | final CharacterContainer that = (CharacterContainer) o; 54 | 55 | if (value != that.value) return false; 56 | 57 | return true; 58 | } 59 | 60 | public int hashCode() { 61 | return (int) value; 62 | } 63 | 64 | public void writeMyself(DataOutput output) throws IOException { 65 | output.writeChar(value); 66 | } 67 | 68 | public void readMyself(DataInput input) throws IOException { 69 | value = input.readChar(); 70 | } 71 | 72 | public void setPrimitive(Object obj, Field field) throws IllegalAccessException { 73 | field.setChar(obj, value); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/DoubleContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import java.io.DataInput; 26 | import java.io.DataOutput; 27 | import java.io.IOException; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: DoubleContainer.java 217 2006-04-18 18:42:42Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class DoubleContainer extends FinalContainer { 36 | double value; 37 | 38 | public DoubleContainer(double value) { 39 | this.value = value; 40 | } 41 | 42 | public DoubleContainer() { 43 | } 44 | 45 | public double getValue() { 46 | return value; 47 | } 48 | 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | 53 | final DoubleContainer that = (DoubleContainer) o; 54 | 55 | if (Double.compare(that.value, value) != 0) return false; 56 | 57 | return true; 58 | } 59 | 60 | public int hashCode() { 61 | final long temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L; 62 | return (int) (temp ^ (temp >>> 32)); 63 | } 64 | 65 | public void writeMyself(DataOutput output) throws IOException { 66 | output.writeDouble(value); 67 | } 68 | 69 | public void readMyself(DataInput input) throws IOException { 70 | value = input.readDouble(); 71 | } 72 | 73 | public void setPrimitive(Object obj, Field field) throws IllegalAccessException { 74 | field.setDouble(obj, value); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/FinalContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.DataExport; 26 | 27 | import java.lang.reflect.Field; 28 | 29 | /** 30 | * $Id: FinalContainer.java 217 2006-04-18 18:42:42Z csuconic $ 31 | * 32 | * @author Clebert Suconic 33 | */ 34 | public abstract class FinalContainer extends DataExport { 35 | public abstract void setPrimitive(Object obj, Field field) throws IllegalAccessException; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/FloatContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import java.io.DataInput; 26 | import java.io.DataOutput; 27 | import java.io.IOException; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: FloatContainer.java 217 2006-04-18 18:42:42Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class FloatContainer extends FinalContainer { 36 | float value; 37 | 38 | public FloatContainer(float value) { 39 | this.value = value; 40 | } 41 | 42 | public FloatContainer() { 43 | } 44 | 45 | public float getValue() { 46 | return value; 47 | } 48 | 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | 53 | final FloatContainer that = (FloatContainer) o; 54 | 55 | if (Float.compare(that.value, value) != 0) return false; 56 | 57 | return true; 58 | } 59 | 60 | public int hashCode() { 61 | return value != +0.0f ? Float.floatToIntBits(value) : 0; 62 | } 63 | 64 | public void writeMyself(DataOutput output) throws IOException { 65 | output.writeFloat(value); 66 | } 67 | 68 | public void readMyself(DataInput input) throws IOException { 69 | value = input.readFloat(); 70 | } 71 | 72 | public void setPrimitive(Object obj, Field field) throws IllegalAccessException { 73 | field.setFloat(obj, value); 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/IntegerContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import java.io.DataInput; 26 | import java.io.DataOutput; 27 | import java.io.IOException; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: IntegerContainer.java 217 2006-04-18 18:42:42Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class IntegerContainer extends FinalContainer { 36 | int value; 37 | 38 | public IntegerContainer(int value) { 39 | this.value = value; 40 | } 41 | 42 | public IntegerContainer() { 43 | } 44 | 45 | public int getValue() { 46 | return value; 47 | } 48 | 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | 53 | final IntegerContainer that = (IntegerContainer) o; 54 | 55 | if (value != that.value) return false; 56 | 57 | return true; 58 | } 59 | 60 | public int hashCode() { 61 | return value; 62 | } 63 | 64 | public void writeMyself(DataOutput output) throws IOException { 65 | output.writeInt(value); 66 | } 67 | 68 | public void readMyself(DataInput input) throws IOException { 69 | value = input.readInt(); 70 | } 71 | 72 | public void setPrimitive(Object obj, Field field) throws IllegalAccessException { 73 | field.setInt(obj, value); 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/LongContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import java.io.DataInput; 26 | import java.io.DataOutput; 27 | import java.io.IOException; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: LongContainer.java 217 2006-04-18 18:42:42Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class LongContainer extends FinalContainer { 36 | long value; 37 | 38 | public LongContainer(long value) { 39 | this.value = value; 40 | } 41 | 42 | public LongContainer() { 43 | } 44 | 45 | public long getValue() { 46 | return value; 47 | } 48 | 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | 53 | final LongContainer that = (LongContainer) o; 54 | 55 | if (value != that.value) return false; 56 | 57 | return true; 58 | } 59 | 60 | public int hashCode() { 61 | return (int) (value ^ (value >>> 32)); 62 | } 63 | 64 | public void writeMyself(DataOutput output) throws IOException { 65 | output.writeLong(value); 66 | } 67 | 68 | public void readMyself(DataInput input) throws IOException { 69 | value = input.readLong(); 70 | } 71 | 72 | public void setPrimitive(Object obj, Field field) throws IllegalAccessException { 73 | field.setLong(obj, value); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/finalcontainers/ShortContainer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.finalcontainers; 24 | 25 | import java.io.DataInput; 26 | import java.io.DataOutput; 27 | import java.io.IOException; 28 | import java.lang.reflect.Field; 29 | 30 | /** 31 | * $Id: ShortContainer.java 217 2006-04-18 18:42:42Z csuconic $ 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class ShortContainer extends FinalContainer { 36 | short value; 37 | 38 | public ShortContainer(short value) { 39 | this.value = value; 40 | } 41 | 42 | public ShortContainer() { 43 | } 44 | 45 | public short getValue() { 46 | return value; 47 | } 48 | 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | 53 | final ShortContainer that = (ShortContainer) o; 54 | 55 | if (value != that.value) return false; 56 | 57 | return true; 58 | } 59 | 60 | public int hashCode() { 61 | return (int) value; 62 | } 63 | 64 | public void writeMyself(DataOutput output) throws IOException { 65 | output.writeShort(value); 66 | } 67 | 68 | public void readMyself(DataInput input) throws IOException { 69 | value = input.readShort(); 70 | } 71 | 72 | public void setPrimitive(Object obj, Field field) throws IllegalAccessException { 73 | field.setShort(obj, value); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/io/Immutable.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.io; 24 | 25 | import java.io.Serializable; 26 | 27 | /** 28 | * This class is intended to TAG immutable serializable classes. 29 | * When you have too identical user immutable classes in a serialization graph tree, they will be considered as a single entity 30 | * and reading the object tree would cause a single object reference also. 31 | *

32 | * This is useful if for example you are serializing an object read from the database, and you have several identical instances 33 | * on the tree. They will be all considered a single instance and JBossSerialziation will place then as references. 34 | *

35 | * Classes implementing Immutable are required to provide a proper equals and a proper hashCode implementations. 36 | * 37 | * @author clebert suconic 38 | */ 39 | public interface Immutable extends Serializable { 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/io/JBossObjectInputStreamSharedTree.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.io; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.DataContainer; 26 | import com.ovea.jetty.session.serializer.jboss.serial.util.StringUtilBuffer; 27 | 28 | import java.io.IOException; 29 | import java.io.InputStream; 30 | import java.io.ObjectInput; 31 | 32 | /** 33 | * This implementation will respect reset commands. 34 | */ 35 | public class JBossObjectInputStreamSharedTree extends JBossObjectInputStream { 36 | 37 | ObjectInput input = null; 38 | DataContainer container = null; 39 | 40 | public JBossObjectInputStreamSharedTree(InputStream is, ClassLoader loader, StringUtilBuffer buffer) throws IOException { 41 | super(is, loader, buffer); 42 | } 43 | 44 | public JBossObjectInputStreamSharedTree(InputStream is, ClassLoader loader) throws IOException { 45 | super(is, loader); 46 | } 47 | 48 | public JBossObjectInputStreamSharedTree(InputStream is, StringUtilBuffer buffer) throws IOException { 49 | super(is, buffer); 50 | } 51 | 52 | public JBossObjectInputStreamSharedTree(InputStream is) throws IOException { 53 | super(is); 54 | } 55 | 56 | public Object readObjectOverride() throws IOException, ClassNotFoundException { 57 | if (input == null) { 58 | container = new DataContainer(classLoader, getSubstitutionInterface(), false, buffer, classDescriptorStrategy, objectDescriptorStrategy); 59 | container.setClassResolver(resolver); 60 | input = container.getDirectInput(dis); 61 | } 62 | return input.readObject(); 63 | } 64 | 65 | public ClassLoader getClassLoader() { 66 | return super.getClassLoader(); 67 | } 68 | 69 | public void setClassLoader(ClassLoader classLoader) { 70 | if (container != null) { 71 | container.getCache().setLoader(classLoader); 72 | } 73 | super.setClassLoader(classLoader); 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/io/JBossObjectOutputStreamSharedTree.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.io; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.DataContainer; 26 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.DataContainerConstants; 27 | import com.ovea.jetty.session.serializer.jboss.serial.util.StringUtilBuffer; 28 | 29 | import java.io.DataOutputStream; 30 | import java.io.IOException; 31 | import java.io.ObjectOutput; 32 | import java.io.OutputStream; 33 | 34 | /** 35 | * This implementation will respect reset commands. 36 | */ 37 | public class JBossObjectOutputStreamSharedTree extends JBossObjectOutputStream { 38 | protected ObjectOutput objectOutput; 39 | DataContainer dataContainer; 40 | 41 | public JBossObjectOutputStreamSharedTree(OutputStream output, boolean checkSerializableClass, StringUtilBuffer buffer) throws IOException { 42 | super(output, checkSerializableClass, buffer); 43 | } 44 | 45 | public JBossObjectOutputStreamSharedTree(OutputStream output, boolean checkSerializableClass) throws IOException { 46 | super(output, checkSerializableClass); 47 | } 48 | 49 | public JBossObjectOutputStreamSharedTree(OutputStream output, StringUtilBuffer buffer) throws IOException { 50 | super(output, buffer); 51 | } 52 | 53 | public JBossObjectOutputStreamSharedTree(OutputStream output) throws IOException { 54 | super(output); 55 | } 56 | 57 | protected void writeObjectOverride(Object obj) throws IOException { 58 | checkOutput(); 59 | objectOutput.writeObject(obj); 60 | } 61 | 62 | public void reset() throws IOException { 63 | checkOutput(); 64 | objectOutput.writeByte(DataContainerConstants.RESET); 65 | dataContainer.getCache().reset(); 66 | } 67 | 68 | private void checkOutput() throws IOException { 69 | if (objectOutput == null) { 70 | dataContainer = new DataContainer(null, this.getSubstitutionInterface(), checkSerializableClass, buffer, classDescriptorStrategy, objectDescriptorStrategy); 71 | if (output instanceof DataOutputStream) { 72 | dataOutput = (DataOutputStream) output; 73 | } else { 74 | dataOutput = new DataOutputStream(output); 75 | } 76 | 77 | objectOutput = dataContainer.getDirectOutput(this.dataOutput); 78 | } 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/io/MarshalledObject.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | package com.ovea.jetty.session.serializer.jboss.serial.io; 23 | 24 | import java.io.ByteArrayInputStream; 25 | import java.io.ByteArrayOutputStream; 26 | import java.io.IOException; 27 | import java.io.Serializable; 28 | import java.util.Arrays; 29 | 30 | /** 31 | * Turns content into a byte array that is delayed in unmarshalling. JBoss Serialization 32 | * equivalent to java.rmi.MarshalledObject 33 | * 34 | * @author Bill Burke 35 | * @version $Revision: 123 $ 36 | */ 37 | public class MarshalledObject implements Serializable { 38 | private byte[] bytes; 39 | private int hash; 40 | 41 | static final long serialVersionUID = -1433248532959364465L; 42 | 43 | 44 | public MarshalledObject() { 45 | } 46 | 47 | public MarshalledObject(Object obj) throws IOException { 48 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 49 | JBossObjectOutputStream mvos = new JBossObjectOutputStream(baos); 50 | mvos.writeObject(obj); 51 | mvos.flush(); 52 | bytes = baos.toByteArray(); 53 | mvos.close(); 54 | hash = 0; 55 | for (int i = 0; i < bytes.length; i++) { 56 | hash += bytes[i]; 57 | } 58 | } 59 | 60 | public Object get() throws IOException, ClassNotFoundException { 61 | ByteArrayInputStream bais = new ByteArrayInputStream(bytes); 62 | JBossObjectInputStream ois = new JBossObjectInputStream(bais); 63 | try { 64 | return ois.readObject(); 65 | } finally { 66 | ois.close(); 67 | bais.close(); 68 | } 69 | } 70 | 71 | public boolean equals(Object o) { 72 | if (this == o) return true; 73 | if (o == null || getClass() != o.getClass()) return false; 74 | 75 | final MarshalledObject that = (MarshalledObject) o; 76 | 77 | if (!Arrays.equals(bytes, that.bytes)) return false; 78 | 79 | return true; 80 | } 81 | 82 | public int hashCode() { 83 | return hash; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/io/MarshalledObjectForLocalCalls.java: -------------------------------------------------------------------------------- 1 | package com.ovea.jetty.session.serializer.jboss.serial.io; 2 | 3 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.DataContainer; 4 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.safecloning.SafeCloningRepository; 5 | 6 | import java.io.Externalizable; 7 | import java.io.IOException; 8 | import java.io.ObjectInput; 9 | import java.io.ObjectOutput; 10 | 11 | 12 | /** 13 | * This is the equivalent for MarshalledObject on RMI, but this is optimized for local calls. 14 | * Instead of converting every single field into Bytes, this will use a DataContainer. 15 | * 16 | * @author Clebert Suconic 17 | */ 18 | public class MarshalledObjectForLocalCalls implements Externalizable { 19 | private static final long serialVersionUID = 785809358605094514L; 20 | 21 | DataContainer container; 22 | 23 | public MarshalledObjectForLocalCalls() { 24 | } 25 | 26 | public MarshalledObjectForLocalCalls(Object obj) throws IOException { 27 | container = new DataContainer(false); 28 | ObjectOutput output = container.getOutput(); 29 | output.writeObject(obj); 30 | output.flush(); 31 | container.flush(); 32 | } 33 | 34 | public MarshalledObjectForLocalCalls(Object obj, SafeCloningRepository safeToReuse) throws IOException { 35 | container = new DataContainer(null, null, safeToReuse, false, null); 36 | ObjectOutput output = container.getOutput(); 37 | output.writeObject(obj); 38 | output.flush(); 39 | container.flush(); 40 | } 41 | 42 | /** 43 | * The object has to be unserialized only when the first get is executed. 44 | */ 45 | public Object get() throws IOException, ClassNotFoundException { 46 | try { 47 | container.getCache().setLoader(Thread.currentThread().getContextClassLoader()); 48 | return container.getInput().readObject(); 49 | } catch (RuntimeException e) { 50 | throw e; 51 | } 52 | } 53 | 54 | public void writeExternal(ObjectOutput out) throws IOException { 55 | container.saveData(out); 56 | } 57 | 58 | public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 59 | container = new DataContainer(false); 60 | container.loadData(in); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/objectmetamodel/DataContainerConstants.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel; 24 | 25 | /** 26 | * $Id: DataContainerConstants.java 263 2006-05-02 04:45:03Z csuconic $ 27 | * 28 | * @author Clebert Suconic 29 | */ 30 | public interface DataContainerConstants { 31 | public static final byte CLASSDEF = 1; 32 | public static final byte OBJECTDEF = 2; 33 | public static final byte OBJECTREF = 3; 34 | public static final byte STRING = 4; 35 | public static final byte DOUBLE = 5; 36 | public static final byte INTEGER = 6; 37 | public static final byte LONG = 7; 38 | public static final byte SHORT = 8; 39 | public static final byte BYTE = 9; 40 | public static final byte FLOAT = 10; 41 | public static final byte CHARACTER = 11; 42 | public static final byte BOOLEAN = 12; 43 | public static final byte BYTEARRAY = 13; 44 | 45 | public static final byte DOUBLEOBJ = 25; 46 | public static final byte INTEGEROBJ = 26; 47 | public static final byte LONGOBJ = 27; 48 | public static final byte SHORTOBJ = 28; 49 | public static final byte BYTEOBJ = 29; 50 | public static final byte FLOATOBJ = 30; 51 | public static final byte CHARACTEROBJ = 31; 52 | public static final byte BOOLEANOBJ = 32; 53 | 54 | public static final byte IMMUTABLE_OBJREF = 40; 55 | 56 | 57 | public static final byte SMARTCLONE_DEF = 50; 58 | public static final byte NEWDEF = 51; 59 | 60 | public static final byte RESET = 60; 61 | 62 | public static final byte NULLREF = 99; 63 | 64 | public static byte[] openSign = new byte[]{(byte) 'j', (byte) 'b', (byte) 's', (byte) '1', (byte) '{'}; 65 | public static byte[] closeSign = new byte[]{(byte) 'j', (byte) 'b', (byte) 's', (byte) '1', (byte) '}'}; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/objectmetamodel/DataExport.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | 24 | package com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel; 25 | 26 | /** 27 | * DataExport is class which is not part of the public API used only during 28 | * the persistence of the meta-model into bytes which happens at {@link org.jboss.serial.objectmetamodel.DataContainer#saveData(java.io.DataOutput)} and {@link org.jboss.serial.objectmetamodel.DataContainer#loadData(DataInput))} 29 | *

30 | * So... Don't use this class 31 | *

32 | * $Id: DataExport.java 137 2006-02-24 20:33:13Z csuconic $ 33 | * 34 | * @author Clebert Suconic 35 | */ 36 | public abstract class DataExport { 37 | //public abstract void writeMyself(DataOutput output) throws IOException; 38 | //public abstract void readMyself(DataInput input) throws IOException; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/objectmetamodel/ObjectDescriptorStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2008, Red Hat Middleware LLC, and individual contributors 4 | * as indicated by the @author tags. See the copyright.txt file in the 5 | * distribution for a full listing of individual contributors. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | package com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel; 23 | 24 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaData; 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.StreamingClass; 26 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache.JBossSeralizationInputInterface; 27 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache.JBossSeralizationOutputInterface; 28 | 29 | import java.io.IOException; 30 | 31 | /** 32 | * @author Clebert Suconic 33 | * @author Ron Sigal 34 | * @version

35 | * Copyright Feb 1, 2009 36 | *

37 | */ 38 | public interface ObjectDescriptorStrategy { 39 | public boolean writeObjectSpecialCase(JBossSeralizationOutputInterface output, ObjectsCache cache, Object obj) throws IOException; 40 | 41 | public boolean writeDuplicateObject(JBossSeralizationOutputInterface output, ObjectsCache cache, Object obj, ClassMetaData metaData) throws IOException; 42 | 43 | public Object replaceObjectByClass(ObjectsCache cache, Object obj, ClassMetaData metaData) throws IOException; 44 | 45 | public Object replaceObjectByStream(ObjectsCache cache, Object obj, ClassMetaData metaData) throws IOException; 46 | 47 | public boolean doneReplacing(ObjectsCache cache, Object newObject, Object oldObject, ClassMetaData oldMetaData) throws IOException; 48 | 49 | public void writeObject(JBossSeralizationOutputInterface output, ObjectsCache cache, ClassMetaData metadata, Object obj) throws IOException; 50 | 51 | public Object readObjectSpecialCase(JBossSeralizationInputInterface input, ObjectsCache cache, byte byteIdentify) throws IOException; 52 | 53 | public Object readObject(JBossSeralizationInputInterface input, ObjectsCache cache, StreamingClass streamingClass, int reference) throws IOException; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/objectmetamodel/ObjectSubstitutionInterface.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * If ObjectSubstitution needs to be handled, send an implementation of this class to DataContainer 29 | * $Id: ObjectSubstitutionInterface.java 217 2006-04-18 18:42:42Z csuconic $ 30 | * 31 | * @author Clebert Suconic 32 | */ 33 | public interface ObjectSubstitutionInterface { 34 | public Object replaceObject(Object obj) throws IOException; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/objectmetamodel/safecloning/SafeClone.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.safecloning; 24 | 25 | /** 26 | * @author Tom Elrod 27 | */ 28 | public interface SafeClone { 29 | public boolean isSafeToReuse(Object obj); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/objectmetamodel/safecloning/SafeCloningRepository.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.safecloning; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.util.ClassMetaConsts; 26 | import gnu.trove.TObjectIntHashMap; 27 | 28 | import java.util.ArrayList; 29 | 30 | /** 31 | * $Id: SafeCloningRepository.java 263 2006-05-02 04:45:03Z csuconic $ 32 | *

33 | * Some objects may be completely reused during cloning operations. (For instance InvocationContext) 34 | * 35 | * @author Clebert Suconic 36 | */ 37 | public class SafeCloningRepository implements ClassMetaConsts { 38 | 39 | 40 | public SafeCloningRepository(SafeClone safeClone) { 41 | this.safeClone = safeClone; 42 | } 43 | 44 | private SafeClone safeClone; 45 | 46 | TObjectIntHashMap safeToReuse = new TObjectIntHashMap(identityHashStrategy); 47 | ArrayList reuse = new ArrayList(); 48 | 49 | public void clear() { 50 | reuse.clear(); 51 | safeToReuse.clear(); 52 | } 53 | 54 | public int storeSafe(Object obj) { 55 | if (safeClone.isSafeToReuse(obj)) { 56 | int description = safeToReuse.get(obj); 57 | 58 | if (description == 0) { 59 | safeToReuse.put(obj, safeToReuse.size() + 1); 60 | description = safeToReuse.size(); 61 | reuse.add(obj); 62 | } 63 | return description; 64 | } else { 65 | return 0; 66 | } 67 | } 68 | 69 | public Object findReference(int reference) { 70 | Object retobject = reuse.get(reference - 1); 71 | return retobject; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/persister/ClassReferencePersister.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.persister; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaData; 26 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetamodelFactory; 27 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassResolver; 28 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.StreamingClass; 29 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectSubstitutionInterface; 30 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache; 31 | 32 | import java.io.IOException; 33 | import java.io.ObjectInput; 34 | import java.io.ObjectOutput; 35 | import java.lang.reflect.Proxy; 36 | 37 | /** 38 | * $Id: ClassReferencePersister.java 314 2006-06-08 16:39:44Z csuconic $ 39 | * 40 | * @author Clebert Suconic 41 | */ 42 | public class ClassReferencePersister implements Persister { 43 | byte id; 44 | 45 | public byte getId() { 46 | return id; 47 | } 48 | 49 | public void setId(byte id) { 50 | this.id = id; 51 | } 52 | 53 | public void writeData(ClassMetaData clazzMetaData, ObjectOutput output, Object obj, ObjectSubstitutionInterface substitution) throws IOException { 54 | Class clazz = (Class) obj; 55 | 56 | boolean isProxy = clazzMetaData.isProxy(); 57 | output.writeBoolean(isProxy); 58 | 59 | if (isProxy) { 60 | Class interfaces[] = clazz.getInterfaces(); 61 | output.writeInt(interfaces.length); 62 | for (int i = 0; i < interfaces.length; i++) { 63 | output.writeUTF(interfaces[i].getName()); 64 | } 65 | } else { 66 | output.writeUTF(clazz.getName()); 67 | } 68 | 69 | } 70 | 71 | public Object readData(ClassLoader loader, StreamingClass streaming, ClassMetaData metaData, int referenceId, ObjectsCache cache, ObjectInput input, ObjectSubstitutionInterface substitution) throws IOException { 72 | boolean isProxy = input.readBoolean(); 73 | 74 | if (isProxy) { 75 | int size = input.readInt(); 76 | Class interfaces[] = new Class[size]; 77 | for (int i = 0; i < interfaces.length; i++) { 78 | interfaces[i] = lookupClass(cache.getClassResolver(), loader, input.readUTF()); 79 | } 80 | 81 | Object proxyReturn = Proxy.getProxyClass(loader, interfaces); 82 | cache.putObjectInCacheRead(referenceId, proxyReturn); 83 | return proxyReturn; 84 | 85 | } else { 86 | String name = input.readUTF(); 87 | Class classReturn = lookupClass(cache.getClassResolver(), loader, name); 88 | cache.putObjectInCacheRead(referenceId, classReturn); 89 | return classReturn; 90 | } 91 | } 92 | 93 | private Class lookupClass(ClassResolver resolver, ClassLoader loader, String name) throws IOException { 94 | if (name.equals("int")) { 95 | return Integer.TYPE; 96 | } else if (name.equals("long")) { 97 | return Long.TYPE; 98 | } else if (name.equals("double")) { 99 | return Double.TYPE; 100 | } else if (name.equals("float")) { 101 | return Float.TYPE; 102 | } else if (name.equals("char")) { 103 | return Character.TYPE; 104 | } else if (name.equals("boolean")) { 105 | return Boolean.TYPE; 106 | } else if (name.equals("byte")) { 107 | return Byte.TYPE; 108 | } else if (name.equals("short")) { 109 | return Short.TYPE; 110 | } else { 111 | ClassMetaData metaData = ClassMetamodelFactory.getClassMetaData(name, resolver, loader, false); 112 | if (metaData.isArray()) { 113 | return metaData.getArrayRepresentation(); 114 | } else { 115 | return metaData.getClazz(); 116 | } 117 | } 118 | } 119 | 120 | public boolean canPersist(Object obj) { 121 | // not implemented 122 | return false; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/persister/EnumerationPersister.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.persister; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaData; 26 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetamodelFactory; 27 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.StreamingClass; 28 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectSubstitutionInterface; 29 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache; 30 | 31 | import java.io.IOException; 32 | import java.io.ObjectInput; 33 | import java.io.ObjectOutput; 34 | 35 | public class EnumerationPersister implements Persister { 36 | 37 | byte id; 38 | 39 | static Class enumClass; 40 | 41 | static { 42 | try { 43 | enumClass = Class.forName("java.lang.Enum"); 44 | } catch (Throwable e) { 45 | } 46 | } 47 | 48 | public byte getId() { 49 | return id; 50 | } 51 | 52 | public void setId(byte id) { 53 | this.id = id; 54 | } 55 | 56 | /** 57 | * @todo is it needed to get another metadata here. 58 | * need to verify 59 | */ 60 | public void writeData(ClassMetaData metaData, ObjectOutput out, Object obj, ObjectSubstitutionInterface substitution) throws IOException { 61 | Enum aEnum = (Enum) obj; 62 | out.writeUTF(aEnum.getDeclaringClass().getName()); 63 | out.writeUTF(aEnum.name()); 64 | } 65 | 66 | /** 67 | * @todo is it needed to get another metadata here. 68 | * need to verify 69 | */ 70 | public Object readData(ClassLoader loader, StreamingClass streaming, ClassMetaData nonUsedmetaData, int referenceId, ObjectsCache cache, ObjectInput input, ObjectSubstitutionInterface substitution) throws IOException { 71 | String instanceName = null; 72 | Class enumClass = null; 73 | String classEnum = input.readUTF(); 74 | try { 75 | ClassMetaData enummetaData = ClassMetamodelFactory.getClassMetaData(classEnum, cache.getClassResolver(), loader, true); 76 | enumClass = enummetaData.getClazz(); 77 | instanceName = input.readUTF(); 78 | Object enumInstance = Enum.valueOf(enumClass, instanceName); 79 | if (enumInstance != null) { 80 | cache.putObjectInCacheRead(referenceId, enumInstance); 81 | return enumInstance; 82 | } else { 83 | throw new IOException("Enumeration " + instanceName + " not found at Enum Class " + enumClass); 84 | } 85 | } catch (Exception e) { 86 | IOException ioException = new IOException(e.getMessage()); 87 | ioException.initCause(e); 88 | throw ioException; 89 | } 90 | } 91 | 92 | public boolean canPersist(Object obj) { 93 | if (enumClass != null) { 94 | return (enumClass.isAssignableFrom(obj.getClass())); 95 | } else { 96 | return false; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/persister/ExternalizePersister.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.persister; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaData; 26 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.StreamingClass; 27 | import com.ovea.jetty.session.serializer.jboss.serial.exception.SerializationException; 28 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectSubstitutionInterface; 29 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache; 30 | 31 | import java.io.Externalizable; 32 | import java.io.IOException; 33 | import java.io.ObjectInput; 34 | import java.io.ObjectOutput; 35 | 36 | /** 37 | * $Id: ExternalizePersister.java 231 2006-04-24 23:49:41Z csuconic $ 38 | * 39 | * @author Clebert Suconic 40 | */ 41 | public class ExternalizePersister implements Persister { 42 | byte id; 43 | 44 | public byte getId() { 45 | return id; 46 | } 47 | 48 | public void setId(byte id) { 49 | this.id = id; 50 | } 51 | 52 | 53 | /* (non-Javadoc) 54 | * @see org.jboss.serial.persister.Persister#writeData(org.jboss.serial.objectmetamodel.DataContainer, java.lang.Object) 55 | */ 56 | public void writeData(ClassMetaData metaData, ObjectOutput out, Object obj, ObjectSubstitutionInterface substitution) throws IOException { 57 | ((Externalizable) obj).writeExternal(out); 58 | } 59 | 60 | /* (non-Javadoc) 61 | * @see org.jboss.serial.persister.Persister 62 | */ 63 | public Object readData(ClassLoader loader, StreamingClass streaming, ClassMetaData metaData, int referenceId, ObjectsCache cache, ObjectInput input, ObjectSubstitutionInterface substitution) throws IOException { 64 | 65 | Object obj = metaData.newInstance(); 66 | cache.putObjectInCacheRead(referenceId, obj); 67 | 68 | try { 69 | ((Externalizable) obj).readExternal(input); 70 | } catch (ClassNotFoundException e) { 71 | throw new SerializationException(e); 72 | } 73 | 74 | return obj; 75 | } 76 | 77 | public boolean canPersist(Object obj) { 78 | return false; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/persister/ObjectInputStreamProxy.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.persister; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaDataSlot; 26 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.FieldsContainer; 27 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectSubstitutionInterface; 28 | 29 | import java.io.*; 30 | 31 | /** 32 | * $Id: ObjectInputStreamProxy.java 231 2006-04-24 23:49:41Z csuconic $ 33 | * 34 | * @author Clebert Suconic 35 | */ 36 | public class ObjectInputStreamProxy extends ObjectInputStream { 37 | 38 | Object currentObj; 39 | ClassMetaDataSlot currentMetaClass; 40 | ObjectSubstitutionInterface currentSubstitution; 41 | 42 | short[] fieldsKey; 43 | 44 | ObjectInput input; 45 | 46 | public ObjectInputStreamProxy(ObjectInput input, short[] fieldsKey, Object currentObj, ClassMetaDataSlot currentMetaClass, ObjectSubstitutionInterface currentSubstitution) throws IOException { 47 | super(); 48 | this.input = input; 49 | this.fieldsKey = fieldsKey; 50 | this.currentObj = currentObj; 51 | this.currentMetaClass = currentMetaClass; 52 | this.currentSubstitution = currentSubstitution; 53 | } 54 | 55 | protected Object readObjectOverride() throws IOException, 56 | ClassNotFoundException { 57 | return input.readObject(); 58 | } 59 | 60 | public Object readUnshared() throws IOException, ClassNotFoundException { 61 | return readObjectOverride(); 62 | } 63 | 64 | public void defaultReadObject() throws IOException, ClassNotFoundException { 65 | RegularObjectPersister.readSlotWithFields(fieldsKey, currentMetaClass, input, currentObj); // @todo - finish this 66 | } 67 | 68 | public void registerValidation(ObjectInputValidation obj, int prio) 69 | throws NotActiveException, InvalidObjectException { 70 | } 71 | 72 | protected void readStreamHeader() throws IOException, 73 | StreamCorruptedException { 74 | } 75 | 76 | protected ObjectStreamClass readClassDescriptor() throws IOException, 77 | ClassNotFoundException { 78 | return null; 79 | } 80 | 81 | public int read() throws IOException { 82 | return input.read(); 83 | } 84 | 85 | public int read(byte[] buf, int off, int len) throws IOException { 86 | return input.read(buf, off, len); 87 | } 88 | 89 | /** 90 | * Returns the number of bytes that can be read without blocking. 91 | * 92 | * @return the number of available bytes. 93 | * @throws java.io.IOException if there are I/O errors while reading from the underlying 94 | * InputStream 95 | */ 96 | public int available() throws IOException { 97 | return 1; 98 | } 99 | 100 | public void close() throws IOException { 101 | } 102 | 103 | public boolean readBoolean() throws IOException { 104 | return input.readBoolean(); 105 | } 106 | 107 | public byte readByte() throws IOException { 108 | return input.readByte(); 109 | } 110 | 111 | public int readUnsignedByte() throws IOException { 112 | return input.readUnsignedByte(); 113 | } 114 | 115 | public char readChar() throws IOException { 116 | return input.readChar(); 117 | } 118 | 119 | public short readShort() throws IOException { 120 | return input.readShort(); 121 | } 122 | 123 | public int readUnsignedShort() throws IOException { 124 | return input.readUnsignedShort(); 125 | } 126 | 127 | public int readInt() throws IOException { 128 | return input.readInt(); 129 | } 130 | 131 | public long readLong() throws IOException { 132 | return input.readLong(); 133 | } 134 | 135 | public float readFloat() throws IOException { 136 | return input.readFloat(); 137 | } 138 | 139 | public double readDouble() throws IOException { 140 | return input.readDouble(); 141 | } 142 | 143 | public void readFully(byte[] buf) throws IOException { 144 | input.readFully(buf); 145 | } 146 | 147 | public void readFully(byte[] buf, int off, int len) throws IOException { 148 | input.readFully(buf, off, len); 149 | } 150 | 151 | public int skipBytes(int len) throws IOException { 152 | return input.skipBytes(len); 153 | } 154 | 155 | @SuppressWarnings({"deprecation"}) 156 | public String readLine() throws IOException { 157 | return input.readLine(); 158 | } 159 | 160 | public String readUTF() throws IOException { 161 | return input.readUTF(); 162 | } 163 | 164 | /* 165 | * (non-Javadoc) 166 | * 167 | * @see java.io.ObjectInput#read(byte[]) 168 | */ 169 | public int read(byte[] b) throws IOException { 170 | return input.read(b); 171 | } 172 | 173 | /* 174 | * (non-Javadoc) 175 | * 176 | * @see java.io.ObjectInput#skip(long) 177 | */ 178 | public long skip(long n) throws IOException { 179 | return input.skip(n); 180 | } 181 | 182 | 183 | public GetField readFields() 184 | throws IOException, ClassNotFoundException { 185 | FieldsContainer container = new FieldsContainer(currentMetaClass); 186 | container.readMyself(this); 187 | return container.createGet(); 188 | } 189 | 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/persister/ObjectOutputStreamProxy.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.persister; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaDataSlot; 26 | import com.ovea.jetty.session.serializer.jboss.serial.exception.SerializationException; 27 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.FieldsContainer; 28 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectSubstitutionInterface; 29 | 30 | import java.io.IOException; 31 | import java.io.ObjectOutput; 32 | import java.io.ObjectOutputStream; 33 | import java.io.ObjectStreamClass; 34 | 35 | /** 36 | * $Id: ObjectOutputStreamProxy.java 202 2006-04-11 23:13:09Z csuconic $ 37 | * 38 | * @author Clebert Suconic 39 | */ 40 | public class ObjectOutputStreamProxy extends ObjectOutputStream { 41 | 42 | Object currentObj; 43 | ClassMetaDataSlot currentMetaClass; 44 | ObjectSubstitutionInterface currentSubstitution; 45 | FieldsContainer currentContainer = null; 46 | 47 | 48 | ObjectOutput bout; 49 | 50 | public ObjectOutputStreamProxy(ObjectOutput output, Object currentObj, ClassMetaDataSlot currentMetaClass, ObjectSubstitutionInterface currentSubstitution) throws IOException { 51 | super(); 52 | this.bout = output; 53 | this.currentObj = currentObj; 54 | this.currentMetaClass = currentMetaClass; 55 | this.currentSubstitution = currentSubstitution; 56 | } 57 | 58 | protected void writeObjectOverride(Object obj) throws IOException { 59 | bout.writeObject(obj); 60 | } 61 | 62 | public void writeUnshared(Object obj) throws IOException { 63 | writeObjectOverride(obj); 64 | } 65 | 66 | public void defaultWriteObject() throws IOException { 67 | writeFields(); 68 | } 69 | 70 | public void writeFields() throws IOException { 71 | if (currentContainer != null) { 72 | currentContainer.writeMyself(this); 73 | currentContainer = null; 74 | } else { 75 | RegularObjectPersister.writeSlotWithFields(currentMetaClass, bout, currentObj, currentSubstitution); 76 | } 77 | } 78 | 79 | public void reset() throws IOException { 80 | } 81 | 82 | protected void writeStreamHeader() throws IOException { 83 | } 84 | 85 | protected void writeClassDescriptor(ObjectStreamClass desc) 86 | throws IOException { 87 | } 88 | 89 | /** 90 | * Writes a byte. This method will block until the byte is actually 91 | * written. 92 | * 93 | * @param val the byte to be written to the stream 94 | * @throws java.io.IOException If an I/O error has occurred. 95 | */ 96 | public void write(int val) throws IOException { 97 | bout.write(val); 98 | } 99 | 100 | /** 101 | * Writes an array of bytes. This method will block until the bytes are 102 | * actually written. 103 | * 104 | * @param buf the data to be written 105 | * @throws java.io.IOException If an I/O error has occurred. 106 | */ 107 | public void write(byte[] buf) throws IOException { 108 | bout.write(buf); 109 | } 110 | 111 | public void write(byte[] buf, int off, int len) throws IOException { 112 | if (buf == null) { 113 | throw new SerializationException("buf can't be null"); 114 | } 115 | bout.write(buf, off, len); 116 | } 117 | 118 | /** 119 | * Flushes the stream. This will write any buffered output bytes and flush 120 | * through to the underlying stream. 121 | * 122 | * @throws java.io.IOException If an I/O error has occurred. 123 | */ 124 | public void flush() throws IOException { 125 | bout.flush(); 126 | } 127 | 128 | protected void drain() throws IOException { 129 | //bout.drain(); 130 | } 131 | 132 | public void close() throws IOException { 133 | flush(); 134 | bout.close(); 135 | } 136 | 137 | public void writeBoolean(boolean val) throws IOException { 138 | bout.writeBoolean(val); 139 | } 140 | 141 | public void writeByte(int val) throws IOException { 142 | bout.writeByte(val); 143 | } 144 | 145 | public void writeShort(int val) throws IOException { 146 | bout.writeShort(val); 147 | } 148 | 149 | public void writeChar(int val) throws IOException { 150 | bout.writeChar(val); 151 | } 152 | 153 | public void writeInt(int val) throws IOException { 154 | bout.writeInt(val); 155 | } 156 | 157 | public void writeLong(long val) throws IOException { 158 | bout.writeLong(val); 159 | } 160 | 161 | public void writeFloat(float val) throws IOException { 162 | bout.writeFloat(val); 163 | } 164 | 165 | public void writeDouble(double val) throws IOException { 166 | bout.writeDouble(val); 167 | } 168 | 169 | public void writeBytes(String str) throws IOException { 170 | bout.writeBytes(str); 171 | } 172 | 173 | public void writeChars(String str) throws IOException { 174 | bout.writeChars(str); 175 | } 176 | 177 | public void writeUTF(String str) throws IOException { 178 | bout.writeUTF(str); 179 | } 180 | 181 | public PutField putFields() throws IOException { 182 | currentContainer = new FieldsContainer(currentMetaClass); 183 | return currentContainer.createPut(); 184 | } 185 | 186 | } 187 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/persister/PersistResolver.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.persister; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaData; 26 | 27 | /** 28 | * @author clebert suconic 29 | */ 30 | public class PersistResolver { 31 | static Persister arrayPersister = new ArrayPersister(); 32 | static ExternalizePersister externalizePersister = new ExternalizePersister(); 33 | static RegularObjectPersister defaultPersister = new RegularObjectPersister(); 34 | static ClassReferencePersister classReferencePersister = new ClassReferencePersister(); 35 | static ProxyPersister proxyPersister = new ProxyPersister(); 36 | static Persister enumPersister = null; 37 | 38 | static { 39 | try { 40 | Class enumClass = Class.forName("java.lang.Enum"); 41 | if (enumClass != null) { 42 | try { 43 | enumPersister = (Persister) PersistResolver.class.getClassLoader().loadClass("com.ovea.jetty.session.serializer.jboss.serial.persister.EnumerationPersister").newInstance(); 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | } catch (Throwable e) { 49 | 50 | } 51 | } 52 | 53 | 54 | static { 55 | defaultPersister.setId((byte) 1); 56 | arrayPersister.setId((byte) 2); 57 | externalizePersister.setId((byte) 3); 58 | classReferencePersister.setId((byte) 5); 59 | proxyPersister.setId((byte) 6); 60 | if (enumPersister != null) { 61 | enumPersister.setId((byte) 7); 62 | } 63 | } 64 | 65 | public static Persister resolvePersister(byte id) { 66 | switch (id) { 67 | case 1: 68 | return defaultPersister; 69 | case 2: 70 | return arrayPersister; 71 | case 3: 72 | return externalizePersister; 73 | case 4: 74 | throw new RuntimeException("This persister is not valid any more"); 75 | case 5: 76 | return classReferencePersister; 77 | case 6: 78 | return proxyPersister; 79 | case 7: 80 | if (enumPersister == null) { 81 | throw new RuntimeException("This current VM doesn't support Enumerations"); 82 | } 83 | return enumPersister; 84 | default: 85 | return defaultPersister; 86 | } 87 | } 88 | 89 | public static Persister resolvePersister(Object objToBeSerialized, ClassMetaData metaData) { 90 | if (metaData.isArray() && (!(objToBeSerialized instanceof Class))) { 91 | return arrayPersister; 92 | } else if (objToBeSerialized instanceof Class || metaData.getClazz() == Class.class) { 93 | return classReferencePersister; 94 | } else if (metaData.isExternalizable()) { 95 | return externalizePersister; 96 | } 97 | if (metaData.isProxy()) { 98 | return proxyPersister; 99 | } else if (enumPersister != null) { 100 | if (enumPersister.canPersist(objToBeSerialized)) { 101 | return enumPersister; 102 | } else { 103 | return defaultPersister; 104 | } 105 | } else { 106 | return defaultPersister; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/persister/Persister.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.persister; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaData; 26 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.StreamingClass; 27 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectSubstitutionInterface; 28 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache; 29 | 30 | import java.io.IOException; 31 | import java.io.ObjectInput; 32 | import java.io.ObjectOutput; 33 | 34 | /** 35 | * Interface used to define how to load complex objects from the repository or streaming 36 | * $Id: Persister.java 231 2006-04-24 23:49:41Z csuconic $ 37 | * 38 | * @author clebert suconic 39 | */ 40 | public interface Persister { 41 | /** 42 | * You need to always return what was sent by setId. This is to enable Streaming to discover what Persister to use 43 | */ 44 | public byte getId(); 45 | 46 | public void setId(byte id); 47 | 48 | public void writeData(ClassMetaData metaData, ObjectOutput out, Object obj, ObjectSubstitutionInterface substitution) throws IOException; 49 | 50 | /** 51 | * @param loader 52 | * @param metaData 53 | * @param referenceId 54 | * @param cache It's the persister job to assign the cache with a created object, right after its creation, as if in case of circular references those references are respected. 55 | * @param input 56 | * @param substitution 57 | * @return 58 | * @throws java.io.IOException 59 | */ 60 | public Object readData(ClassLoader loader, StreamingClass streaming, ClassMetaData metaData, int referenceId, ObjectsCache cache, ObjectInput input, ObjectSubstitutionInterface substitution) throws IOException; 61 | 62 | /** 63 | * Ask the persister if the persister can handle this object 64 | */ 65 | public boolean canPersist(Object obj); 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/persister/ProxyPersister.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.persister; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.ClassMetaData; 26 | import com.ovea.jetty.session.serializer.jboss.serial.classmetamodel.StreamingClass; 27 | import com.ovea.jetty.session.serializer.jboss.serial.exception.SerializationException; 28 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectSubstitutionInterface; 29 | import com.ovea.jetty.session.serializer.jboss.serial.objectmetamodel.ObjectsCache; 30 | 31 | import java.io.IOException; 32 | import java.io.ObjectInput; 33 | import java.io.ObjectOutput; 34 | import java.lang.reflect.Constructor; 35 | import java.lang.reflect.InvocationHandler; 36 | import java.lang.reflect.InvocationTargetException; 37 | import java.lang.reflect.Proxy; 38 | 39 | /** 40 | * $Id: ProxyPersister.java 231 2006-04-24 23:49:41Z csuconic $ 41 | * 42 | * @author Clebert Suconic 43 | */ 44 | public class ProxyPersister implements Persister { 45 | private byte id; 46 | 47 | public byte getId() { 48 | return id; 49 | } 50 | 51 | public void setId(byte id) { 52 | this.id = id; 53 | } 54 | 55 | public void writeData(ClassMetaData metaData, ObjectOutput output, Object obj, ObjectSubstitutionInterface substitution) throws IOException { 56 | Object handler = Proxy.getInvocationHandler(obj); 57 | 58 | output.writeObject(handler); 59 | output.writeObject(obj.getClass()); 60 | } 61 | 62 | public Object readData(ClassLoader loader, StreamingClass streaming, ClassMetaData metaData, int referenceId, ObjectsCache cache, ObjectInput input, ObjectSubstitutionInterface substitution) throws IOException { 63 | 64 | try { 65 | Object handler = input.readObject(); 66 | Class proxy = (Class) input.readObject(); 67 | Constructor constructor = proxy.getConstructor(new Class[]{InvocationHandler.class}); 68 | Object obj = constructor.newInstance(new Object[]{handler}); 69 | cache.putObjectInCacheRead(referenceId, obj); 70 | return obj; 71 | } catch (ClassNotFoundException e) { 72 | throw new SerializationException(e); 73 | } catch (NoSuchMethodException e) { 74 | throw new SerializationException(e); 75 | } catch (IllegalAccessException e) { 76 | throw new SerializationException(e); 77 | } catch (InstantiationException e) { 78 | throw new SerializationException(e); 79 | } catch (InvocationTargetException e) { 80 | throw new SerializationException(e); 81 | } 82 | } 83 | 84 | public boolean canPersist(Object obj) { 85 | // not implemented 86 | return false; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/references/ArgumentPersistentReference.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.references; 24 | 25 | import java.lang.ref.WeakReference; 26 | 27 | /** 28 | * Abstract class used where reflection operations with arguments are used (like Methods and Constructors) 29 | * 30 | * @author csuconic 31 | */ 32 | public abstract class ArgumentPersistentReference extends PersistentReference { 33 | public ArgumentPersistentReference(Class clazz, Object referencedObject, int referenceType) { 34 | super(clazz, referencedObject, referenceType); 35 | } 36 | 37 | WeakReference[] arguments; 38 | 39 | public void setArguments(Class[] parguments) { 40 | this.arguments = new WeakReference[parguments.length]; 41 | for (int i = 0; i < arguments.length; i++) { 42 | this.arguments[i] = new WeakReference(parguments[i]); 43 | } 44 | } 45 | 46 | public Class[] getArguments() { 47 | if (arguments == null) { 48 | return null; 49 | } else { 50 | Class argumentsReturn[] = new Class[arguments.length]; 51 | for (int i = 0; i < arguments.length; i++) { 52 | argumentsReturn[i] = (Class) arguments[i].get(); 53 | } 54 | return argumentsReturn; 55 | } 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/references/ConstructorPersistentReference.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.references; 24 | 25 | import java.lang.reflect.Constructor; 26 | 27 | /** 28 | * This class is not used by JBossSerialization itself, as the constructor used is slightly different (GhostConstructor), but I kept the implementation here as a reference for others. 29 | * 30 | * @author Clebert Suconic 31 | */ 32 | public class ConstructorPersistentReference extends ArgumentPersistentReference { 33 | 34 | public ConstructorPersistentReference(Class clazz, Object referencedObject, int referenceType) { 35 | super(clazz, referencedObject, referenceType); 36 | this.setArguments(((Constructor) referencedObject).getParameterTypes()); 37 | } 38 | 39 | public synchronized Object rebuildReference() throws Exception { 40 | // A reference to guarantee the value is not being GCed during while the value is being rebuilt 41 | Object returnValue = null; 42 | if ((returnValue = internalGet()) != null) return returnValue; 43 | 44 | Constructor constructor = getMappedClass().getConstructor(getArguments()); 45 | constructor.setAccessible(true); 46 | buildReference(constructor); 47 | return constructor; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/references/EmptyReference.java: -------------------------------------------------------------------------------- 1 | package com.ovea.jetty.session.serializer.jboss.serial.references; 2 | 3 | public class EmptyReference extends PersistentReference { 4 | 5 | public EmptyReference() { 6 | super(null, null, REFERENCE_WEAK); 7 | } 8 | 9 | public Object rebuildReference() throws Exception { 10 | return null; 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/references/FieldPersistentReference.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.references; 24 | 25 | import java.lang.reflect.Field; 26 | 27 | /** 28 | * Creates a persistentReference for Fields 29 | * 30 | * @author csuconic 31 | */ 32 | public class FieldPersistentReference extends PersistentReference { 33 | public FieldPersistentReference(Field field, int referenceType) { 34 | super(field != null ? field.getDeclaringClass() : null, field, referenceType); 35 | this.name = field.getName(); 36 | } 37 | 38 | String name; 39 | 40 | public synchronized Object rebuildReference() throws Exception { 41 | // A reference to guarantee the value is not being GCed during while the value is being rebuilt 42 | Object returnValue = null; 43 | if ((returnValue = internalGet()) != null) return returnValue; 44 | 45 | Field field = getMappedClass().getDeclaredField(name); 46 | field.setAccessible(true); 47 | buildReference(field); 48 | return field; 49 | } 50 | 51 | public Field getField() { 52 | return (Field) get(); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/references/MethodPersistentReference.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.references; 24 | 25 | import java.lang.reflect.Method; 26 | 27 | /** 28 | * A reference to a field. 29 | * In case the reference is released, the reference will be reconstructed 30 | */ 31 | public class MethodPersistentReference extends ArgumentPersistentReference { 32 | public MethodPersistentReference(Method method, int referenceType) { 33 | super(method != null ? method.getDeclaringClass() : null, method, referenceType); 34 | if (method != null) { 35 | this.name = method.getName(); 36 | setArguments(method.getParameterTypes()); 37 | } 38 | } 39 | 40 | String name; 41 | 42 | 43 | public synchronized Object rebuildReference() throws Exception { 44 | // A reference to guarantee the value is not being GCed during while the value is being rebuilt 45 | Object returnValue = null; 46 | if ((returnValue = internalGet()) != null) return returnValue; 47 | 48 | Method aMethod = getMappedClass().getDeclaredMethod(name, getArguments()); 49 | aMethod.setAccessible(true); 50 | buildReference(aMethod); 51 | return aMethod; 52 | } 53 | 54 | public Method getMethod() { 55 | return (Method) get(); 56 | } 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/references/PersistentReference.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.references; 24 | 25 | import java.lang.ref.Reference; 26 | import java.lang.ref.SoftReference; 27 | import java.lang.ref.WeakReference; 28 | 29 | /** 30 | * Base class for persistent references. 31 | * Persistent reference is a Weak/Soft reference to a reflection object. 32 | * If the reflection object is garbage collected, the reference is then rebuilt using reflection operations. 33 | * 34 | * @author csuconic 35 | */ 36 | public abstract class PersistentReference { 37 | public static final int REFERENCE_WEAK = 1; 38 | public static final int REFERENCE_SOFT = 2; 39 | 40 | private WeakReference classReference; 41 | private Reference referencedObject; 42 | private int referenceType = 0; 43 | 44 | /** 45 | * @param clazz The clazz being used on this object (where we will do reflection operations) 46 | * @param referencedObject The reflection object being used 47 | * @param referenceType if REFERENCE_WEAK will use a WeakReference, and if REFERENCE_SOFT will use a SoftReference for referencedObject 48 | */ 49 | public PersistentReference(Class clazz, Object referencedObject, int referenceType) { 50 | this.referenceType = referenceType; 51 | if (clazz != null) { 52 | classReference = new WeakReference(clazz); 53 | } 54 | buildReference(referencedObject); 55 | } 56 | 57 | /** 58 | * Checks the reference but doesn't perform rebuild if empty 59 | */ 60 | protected Object internalGet() { 61 | if (referencedObject == null) 62 | return null; 63 | 64 | return referencedObject.get(); 65 | 66 | 67 | } 68 | 69 | public Object get() { 70 | if (referencedObject == null) 71 | return null; 72 | 73 | Object returnValue = referencedObject.get(); 74 | if (returnValue == null) { 75 | try { 76 | // Return ths value straight from the rebuild, to guarantee the value is not destroyed if a GC happens during the rebuild reference 77 | return rebuildReference(); 78 | } catch (Exception e) { 79 | throw new RuntimeException(e.getMessage(), e); 80 | } 81 | } 82 | 83 | return returnValue; 84 | } 85 | 86 | public abstract Object rebuildReference() throws Exception; 87 | 88 | /** 89 | * This method should be called from a synchronized block 90 | */ 91 | protected void buildReference(Object obj) { 92 | if (obj == null) { 93 | referencedObject = null; 94 | } else { 95 | if (referenceType == REFERENCE_WEAK) { 96 | referencedObject = new WeakReference(obj); 97 | } else { 98 | referencedObject = new SoftReference(obj); 99 | } 100 | } 101 | } 102 | 103 | public Class getMappedClass() { 104 | if (classReference == null) return null; 105 | Class returnClass = (Class) classReference.get(); 106 | if (returnClass == null) { 107 | throw new RuntimeException("Class was already unloaded"); 108 | } 109 | return (Class) returnClass; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/util/ClassMetaConsts.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.util; 24 | 25 | import com.ovea.jetty.session.serializer.jboss.serial.references.EmptyReference; 26 | import com.ovea.jetty.session.serializer.jboss.serial.references.PersistentReference; 27 | import gnu.trove.TObjectHashingStrategy; 28 | 29 | 30 | /** 31 | * Contribution made by Bob Morris. 32 | * To improve performance we should use EMPTY_CLASS_ARRAY and EMPTY_OBJECT_ARRAY instead of creating an instance every time we need. 33 | * 34 | * @author Bob Morris 35 | */ 36 | public interface ClassMetaConsts { 37 | static final int REFERENCE_TYPE_IN_USE = PersistentReference.REFERENCE_SOFT; 38 | static public final Class[] EMPTY_CLASS_ARRY = new Class[0]; 39 | static public final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; 40 | static final PersistentReference emptyReference = new EmptyReference(); 41 | static public final TObjectHashingStrategy identityHashStrategy = 42 | new TObjectHashingStrategy() { 43 | public int computeHashCode(Object o) { 44 | return System.identityHashCode(o); 45 | } 46 | 47 | public boolean equals(Object o1, Object o2) { 48 | return o1 == o2; 49 | } 50 | }; 51 | 52 | static public final TObjectHashingStrategy regularHashStrategy = 53 | new TObjectHashingStrategy() { 54 | public int computeHashCode(Object o) { 55 | return o.hashCode(); 56 | } 57 | 58 | public boolean equals(Object o1, Object o2) { 59 | return o1.getClass() == o2.getClass() && o1.equals(o2); 60 | } 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/util/HashStringUtil.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | package com.ovea.jetty.session.serializer.jboss.serial.util; 24 | 25 | import java.io.ByteArrayOutputStream; 26 | import java.io.DataOutputStream; 27 | import java.security.DigestOutputStream; 28 | import java.security.MessageDigest; 29 | 30 | /** 31 | * This code was extracted from MarshalledInvocation. It converts any string to a unique HashCode 32 | * 33 | * @author Clebert Suconic 34 | */ 35 | public class HashStringUtil { 36 | public static long hashName(String name) { 37 | try { 38 | long hash = 0; 39 | ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(512); 40 | MessageDigest messagedigest = MessageDigest.getInstance("SHA"); 41 | DataOutputStream dataoutputstream = new DataOutputStream(new DigestOutputStream(bytearrayoutputstream, messagedigest)); 42 | dataoutputstream.writeUTF(name); 43 | dataoutputstream.flush(); 44 | byte abyte0[] = messagedigest.digest(); 45 | for (int j = 0; j < Math.min(8, abyte0.length); j++) 46 | hash += (long) (abyte0[j] & 0xff) << j * 8; 47 | return hash; 48 | } catch (Exception e) { 49 | RuntimeException rte = new RuntimeException(e); 50 | throw rte; 51 | } 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/util/PartitionedWeakHashMap.java: -------------------------------------------------------------------------------- 1 | package com.ovea.jetty.session.serializer.jboss.serial.util; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * This is a WeakHashMap divided into partitions, using a simple algorithm of using the hashCode of a Key % numberOfPartitions to determine what partition to use. 7 | * This is intended to minimize synchroniozation affects 8 | * 9 | * @author Clebert Suconic 10 | */ 11 | public class PartitionedWeakHashMap extends AbstractMap { 12 | 13 | boolean issynchronized; 14 | Map[] partitionMaps; 15 | 16 | public PartitionedWeakHashMap() { 17 | this(false); 18 | } 19 | 20 | public PartitionedWeakHashMap(boolean issynchronized) { 21 | super(); 22 | this.issynchronized = issynchronized; 23 | partitionMaps = new Map[PARTITION_SIZE]; 24 | for (int i = 0; i < PARTITION_SIZE; i++) { 25 | if (issynchronized) { 26 | partitionMaps[i] = Collections.synchronizedMap(new WeakHashMap()); 27 | } else { 28 | partitionMaps[i] = new WeakHashMap(); 29 | } 30 | } 31 | } 32 | 33 | 34 | public Map getMap(Object obj) { 35 | int hash = obj.hashCode(); 36 | if (hash < 0) hash *= -1; 37 | hash = hash % PARTITION_SIZE; 38 | return partitionMaps[hash]; 39 | } 40 | 41 | 42 | private static final int PARTITION_SIZE = 10; 43 | 44 | 45 | public Set entrySet() { 46 | throw new RuntimeException("method not supported"); 47 | } 48 | 49 | public void clear() { 50 | for (int i = 0; i < partitionMaps.length; i++) { 51 | partitionMaps[i].clear(); 52 | } 53 | } 54 | 55 | protected Object clone() throws CloneNotSupportedException { 56 | throw new RuntimeException("Clone not supported"); 57 | } 58 | 59 | public boolean containsKey(Object key) { 60 | return getMap(key).containsKey(key); 61 | } 62 | 63 | public boolean containsValue(Object value) { 64 | throw new RuntimeException("method not supported"); 65 | } 66 | 67 | public boolean equals(Object o) { 68 | throw new RuntimeException("method not supported"); 69 | } 70 | 71 | public Object get(Object key) { 72 | return getMap(key).get(key); 73 | } 74 | 75 | public boolean isEmpty() { 76 | throw new RuntimeException("method not supported"); 77 | } 78 | 79 | public Set keySet() { 80 | HashSet hashSet = new HashSet(); 81 | 82 | for (int i = 0; i < PARTITION_SIZE; i++) { 83 | hashSet.addAll(partitionMaps[i].keySet()); 84 | } 85 | 86 | return hashSet; 87 | } 88 | 89 | public Object put(Object key, Object value) { 90 | 91 | // if the maps are not synchronized, the put at leas needs to be 92 | if (!issynchronized) { 93 | Map map = getMap(key); 94 | synchronized (map) { 95 | return map.put(key, value); 96 | } 97 | 98 | } else { 99 | return getMap(key).put(key, value); 100 | } 101 | } 102 | 103 | public void putAll(Map elementsToAdd) { 104 | Iterator iter = elementsToAdd.entrySet().iterator(); 105 | while (iter.hasNext()) { 106 | Entry entry = (Entry) iter.next(); 107 | put(entry.getKey(), entry.getValue()); 108 | } 109 | } 110 | 111 | public Object remove(Object key) { 112 | return getMap(key).remove(key); 113 | } 114 | 115 | public int size() { 116 | int size = 0; 117 | for (int i = 0; i < PARTITION_SIZE; i++) { 118 | size += partitionMaps[i].size(); 119 | } 120 | return size; 121 | } 122 | 123 | public Collection values() { 124 | ArrayList values = new ArrayList(); 125 | for (int i = 0; i < PARTITION_SIZE; i++) { 126 | values.addAll(partitionMaps[i].values()); 127 | } 128 | return values; 129 | 130 | } 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/com/ovea/jetty/session/serializer/jboss/serial/util/StringUtilBuffer.java: -------------------------------------------------------------------------------- 1 | /* 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. 6 | * 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. 11 | * 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. 16 | * 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. 21 | */ 22 | 23 | 24 | package com.ovea.jetty.session.serializer.jboss.serial.util; 25 | 26 | /** 27 | * $Id: StringUtilBuffer.java 297 2006-05-20 03:02:32Z csuconic $ 28 | * 29 | * @author Clebert Suconic 30 | */ 31 | public class StringUtilBuffer { 32 | 33 | /* A way to pass an integer as a parameter to a method */ 34 | public static class Position { 35 | int pos; 36 | long size; 37 | 38 | public Position reset() { 39 | pos = 0; 40 | size = 0; 41 | return this; 42 | } 43 | } 44 | 45 | Position position = new Position(); 46 | 47 | 48 | public char charBuffer[]; 49 | public byte byteBuffer[]; 50 | 51 | public void resizeCharBuffer(int newSize) { 52 | if (newSize <= charBuffer.length) { 53 | throw new RuntimeException("New buffer can't be smaller"); 54 | } 55 | char[] newCharBuffer = new char[newSize]; 56 | for (int i = 0; i < charBuffer.length; i++) { 57 | newCharBuffer[i] = charBuffer[i]; 58 | } 59 | charBuffer = newCharBuffer; 60 | } 61 | 62 | public void resizeByteBuffer(int newSize) { 63 | if (newSize <= byteBuffer.length) { 64 | throw new RuntimeException("New buffer can't be smaller"); 65 | } 66 | byte[] newByteBuffer = new byte[newSize]; 67 | for (int i = 0; i < byteBuffer.length; i++) { 68 | newByteBuffer[i] = byteBuffer[i]; 69 | } 70 | byteBuffer = newByteBuffer; 71 | } 72 | 73 | public StringUtilBuffer() { 74 | this(1024, 1024); 75 | } 76 | 77 | public StringUtilBuffer(int sizeChar, int sizeByte) { 78 | charBuffer = new char[sizeChar]; 79 | byteBuffer = new byte[sizeByte]; 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/StartServers.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import com.ovea.jetty.session.JettyServer; 17 | 18 | /** 19 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 20 | */ 21 | final class StartServers { 22 | public static void main(String... args) throws Exception { 23 | JettyServer container1 = new JettyServer("src/test/webapp1"); 24 | JettyServer container2 = new JettyServer("src/test/webapp2"); 25 | container1.start(); 26 | container2.start(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/ovea/jetty/session/ClusteringTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session; 17 | 18 | import org.junit.*; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.JUnit4; 21 | 22 | /** 23 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 24 | */ 25 | @Ignore 26 | @RunWith(JUnit4.class) 27 | public final class ClusteringTest { 28 | 29 | @Test 30 | public void test() throws Exception { 31 | //TODO 32 | } 33 | 34 | @BeforeClass 35 | public static void startRedis() throws Exception { 36 | redis.start(); 37 | } 38 | 39 | @AfterClass 40 | public static void stopRedis() throws Exception { 41 | redis.stop(); 42 | } 43 | 44 | @Before 45 | public void startJetty() throws Exception { 46 | container1.start(); 47 | container2.start(); 48 | } 49 | 50 | @After 51 | public void stopJetty() throws Exception { 52 | container1.stop(); 53 | container2.stop(); 54 | } 55 | 56 | static final RedisProcess redis = new RedisProcess(); 57 | final JettyServer container1 = new JettyServer("src/test/webapp1"); 58 | final JettyServer container2 = new JettyServer("src/test/webapp2"); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/ovea/jetty/session/JettyServer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session; 17 | 18 | import org.testatoo.container.Container; 19 | import org.testatoo.container.ContainerConfiguration; 20 | import org.testatoo.container.TestatooContainer; 21 | 22 | /** 23 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 24 | */ 25 | public final class JettyServer { 26 | 27 | final Container container; 28 | 29 | public JettyServer(String webappRoot) { 30 | container = ContainerConfiguration.create() 31 | .webappRoot(webappRoot) 32 | .set("jetty.conf", webappRoot + "/WEB-INF/jetty-server.xml") 33 | .set("jetty.env", webappRoot + "/WEB-INF/jetty-web.xml") 34 | .buildContainer(TestatooContainer.JETTY); 35 | } 36 | 37 | public void start() throws Exception { 38 | if (container != null) 39 | container.start(); 40 | } 41 | 42 | public void stop() throws Exception { 43 | if (container != null) 44 | container.stop(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/ovea/jetty/session/RedisProcess.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session; 17 | 18 | import java.io.BufferedReader; 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.InputStreamReader; 22 | 23 | /** 24 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 25 | */ 26 | public final class RedisProcess { 27 | 28 | ProcessReader reader; 29 | 30 | public void start() throws Exception { 31 | Process process = new ProcessBuilder("/bin/bash", "-c", "redis/redis-start.sh") 32 | .redirectErrorStream(true) 33 | .directory(new File(".")) 34 | .start(); 35 | reader = new ProcessReader(process); 36 | process.waitFor(); 37 | reader.stop(); 38 | 39 | process = new ProcessBuilder("/bin/bash", "-c", "redis/redis-monitor.sh") 40 | .redirectErrorStream(true) 41 | .directory(new File(".")) 42 | .start(); 43 | reader = new ProcessReader(process); 44 | } 45 | 46 | public void stop() throws Exception { 47 | if (reader != null) 48 | reader.stop(); 49 | new ProcessBuilder("/bin/bash", "-c", "redis/redis-stop.sh") 50 | .redirectErrorStream(true) 51 | .directory(new File(".")) 52 | .start(); 53 | } 54 | 55 | static class ProcessReader { 56 | final Thread reader; 57 | 58 | ProcessReader(final Process process) { 59 | reader = new Thread() { 60 | @Override 61 | public void run() { 62 | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); 63 | String line; 64 | try { 65 | while ((line = reader.readLine()) != null) 66 | System.out.println("[RedisProcess] " + line); 67 | 68 | } catch (IOException ignored) { 69 | } finally { 70 | try { 71 | reader.close(); 72 | } catch (IOException ignored) { 73 | } 74 | } 75 | } 76 | }; 77 | reader.start(); 78 | } 79 | 80 | void stop() { 81 | reader.interrupt(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/com/ovea/jetty/session/serializer/JBossSerializerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.JUnit4; 21 | 22 | import java.io.Serializable; 23 | import java.net.InetAddress; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | import static org.junit.Assert.assertArrayEquals; 28 | import static org.junit.Assert.assertEquals; 29 | 30 | /** 31 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 32 | */ 33 | @RunWith(JUnit4.class) 34 | public final class JBossSerializerTest implements Serializable { 35 | 36 | private static final long serialVersionUID = -4758353525859226249L; 37 | 38 | private transient JBossSerializer serializer = new JBossSerializer(); 39 | 40 | private int a = 1; 41 | private transient int b = 1; 42 | private Map attributes = new HashMap(); 43 | 44 | @Test 45 | public void test() throws Exception { 46 | a = 2; 47 | b = 2; 48 | attributes.put("a", 1); 49 | attributes.put("b", new String[]{"q", "w", "e", "r", "t", "y"}); 50 | attributes.put("c", InetAddress.getLocalHost()); 51 | 52 | serializer.setGzip(true); 53 | 54 | JBossSerializerTest c = round(this); 55 | 56 | assertEquals(2, c.a); 57 | assertEquals(0, c.b); 58 | assertEquals(1, c.attributes.get("a")); 59 | assertArrayEquals(new String[]{"q", "w", "e", "r", "t", "y"}, (String[]) c.attributes.get("b")); 60 | assertEquals(InetAddress.getLocalHost(), c.attributes.get("c")); 61 | } 62 | 63 | @Test 64 | public void test_non_gzip() throws Exception { 65 | a = 2; 66 | b = 2; 67 | attributes.put("a", 1); 68 | attributes.put("b", new String[]{"q", "w", "e", "r", "t", "y"}); 69 | attributes.put("c", InetAddress.getLocalHost()); 70 | 71 | serializer.setGzip(false); 72 | 73 | JBossSerializerTest c = round(this); 74 | 75 | assertEquals(2, c.a); 76 | assertEquals(0, c.b); 77 | assertEquals(1, c.attributes.get("a")); 78 | assertArrayEquals(new String[]{"q", "w", "e", "r", "t", "y"}, (String[]) c.attributes.get("b")); 79 | assertEquals(InetAddress.getLocalHost(), c.attributes.get("c")); 80 | } 81 | 82 | private T round(T obj) { 83 | String data = serializer.serialize(obj); 84 | System.out.println("gzip=" + serializer.isGzip() + " : " + data); 85 | return (T) serializer.deserialize(data, obj.getClass()); 86 | } 87 | } -------------------------------------------------------------------------------- /src/test/java/com/ovea/jetty/session/serializer/JdkSerializerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.JUnit4; 21 | 22 | import java.io.Serializable; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | 26 | /** 27 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 28 | */ 29 | @RunWith(JUnit4.class) 30 | public final class JdkSerializerTest implements Serializable { 31 | 32 | private static final long serialVersionUID = -4758353525859226249L; 33 | 34 | private transient JdkSerializer serializer = new JdkSerializer(); 35 | 36 | private int a = 1; 37 | private transient int b = 1; 38 | 39 | @Test 40 | public void test() throws Exception { 41 | a = 2; 42 | b = 2; 43 | serializer.setGzip(true); 44 | JdkSerializerTest c = round(this); 45 | assertEquals(2, c.a); 46 | assertEquals(0, c.b); 47 | //round(new JFrame()); 48 | } 49 | 50 | @Test 51 | public void test_non_gzip() throws Exception { 52 | a = 2; 53 | b = 2; 54 | serializer.setGzip(false); 55 | JdkSerializerTest c = round(this); 56 | assertEquals(2, c.a); 57 | assertEquals(0, c.b); 58 | //round(new JFrame()); 59 | } 60 | 61 | private T round(T obj) { 62 | String data = serializer.serialize(obj); 63 | System.out.println("gzip=" + serializer.isGzip() + " : " + data); 64 | return (T) serializer.deserialize(data, obj.getClass()); 65 | } 66 | } -------------------------------------------------------------------------------- /src/test/java/com/ovea/jetty/session/serializer/JsonSerializerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.JUnit4; 21 | 22 | import java.net.InetAddress; 23 | import java.util.Arrays; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | import static org.junit.Assert.assertTrue; 29 | 30 | /** 31 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 32 | */ 33 | @RunWith(JUnit4.class) 34 | public final class JsonSerializerTest { 35 | 36 | private transient JsonSerializer serializer = new JsonSerializer(); 37 | 38 | private int a = 1; 39 | private transient int b = 1; 40 | private Map attributes = new HashMap(); 41 | private InetAddress addr; 42 | 43 | @Test 44 | public void test() throws Exception { 45 | addr = InetAddress.getLocalHost(); 46 | serializer.start(); 47 | 48 | a = 2; 49 | b = 2; 50 | attributes.put("a", 1); 51 | attributes.put("b", new String[]{"q", "w", "e", "r", "t", "y"}); 52 | System.out.println(InetAddress.getLocalHost()); 53 | 54 | System.out.println(this); 55 | 56 | JsonSerializerTest c = round(this); 57 | System.out.println(c); 58 | 59 | assertEquals(2, c.a); 60 | assertEquals(1, c.b); 61 | assertEquals(1, c.attributes.get("a")); 62 | assertEquals(Arrays.asList("q", "w", "e", "r", "t", "y"), c.attributes.get("b")); 63 | assertEquals(c.addr, addr); 64 | } 65 | 66 | private T round(T obj) { 67 | String data = serializer.serialize(obj); 68 | System.out.println(data); 69 | return (T) serializer.deserialize(data, obj.getClass()); 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "JsonSerializerTest{" + 75 | "addr=" + addr + 76 | ", a=" + a + 77 | ", b=" + b + 78 | ", attributes=" + attributes + 79 | '}'; 80 | } 81 | } -------------------------------------------------------------------------------- /src/test/java/com/ovea/jetty/session/serializer/XStreamSerializerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011 Ovea 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.ovea.jetty.session.serializer; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.JUnit4; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | 24 | /** 25 | * @author Mathieu Carbou (mathieu.carbou@gmail.com) 26 | */ 27 | @RunWith(JUnit4.class) 28 | public final class XStreamSerializerTest { 29 | 30 | private transient XStreamSerializer serializer = new XStreamSerializer(); 31 | 32 | private int a = 1; 33 | private transient int b = 1; 34 | 35 | @Test 36 | public void test() throws Exception { 37 | serializer.start(); 38 | 39 | a = 2; 40 | b = 2; 41 | XStreamSerializerTest c = round(this); 42 | assertEquals(2, c.a); 43 | assertEquals(1, c.b); 44 | //round(new JFrame()); 45 | } 46 | 47 | private T round(T obj) { 48 | String data = serializer.serialize(obj); 49 | System.out.println(data); 50 | return (T) serializer.deserialize(data, obj.getClass()); 51 | } 52 | } -------------------------------------------------------------------------------- /src/test/resources/jndi.properties: -------------------------------------------------------------------------------- 1 | java.naming.factory.url.pkgs=org.eclipse.jetty.jndi 2 | java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory 3 | -------------------------------------------------------------------------------- /src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/test/webapp1/WEB-INF/jetty-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | true 23 | true 24 | true 25 | 1000 26 | 27 | 28 | 29 | 10 30 | 200 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 65 | 66 | 67 | 68 | 69 | 70 | session/redis 71 | 20000 72 | 73 | 74 | 75 | 76 | 77 | 78 | 81 | 82 | session/redis 83 | 84 | 85 | 86 | 87 | 3 88 | 5 89 | true 90 | 91 | 92 | 127.0.0.1 93 | 6379 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/test/webapp1/WEB-INF/jetty-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | /webapp1 25 | 26 | 29 | 30 | 31 | 32 | 33 | session/redis 34 | 35 | 36 | 37 | 38 | 20 39 | 40 | localhost 41 | 42 | / 43 | 44 | 80 45 | 46 | 20 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/test/webapp1/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | web-1 24 | 25 | 26 | index.jsp 27 | 28 | 29 | 30 | 43200 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/test/webapp1/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright (C) 2011 Ovea 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ page import="java.util.Enumeration" %> 19 | <%@ page import="java.util.Random" %> 20 | <% 21 | int r = new Random().nextInt(100); 22 | if(request.getParameter("key") != null) 23 | request.getSession().setAttribute(String.valueOf(request.getParameter("key")), request.getParameter("val")); 24 | if(request.getParameter("invalidate") != null) 25 | request.getSession().invalidate(); 26 | %> 27 | 29 | 30 | 31 | web-1 32 | 33 | 34 | 35 |

Context path: <%=request.getContextPath()%>

36 | Refresh 37 |

38 | &val=<%="val"+r%>">Set in session: <%="key"+r%>=<%="val"+r%> 39 |

40 | Invalidate session 41 |
    42 | <% 43 | HttpSession sess = request.getSession(false); 44 | if(sess != null) { 45 | Enumeration e = sess.getAttributeNames(); 46 | while(e.hasMoreElements()) { 47 | String key = e.nextElement(); 48 | String val = String.valueOf(request.getSession().getAttribute(key)); 49 | %> 50 |
  • <%=key%> = <%=val%>
  • 51 | <% } 52 | } 53 | %> 54 |
55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/test/webapp2/WEB-INF/jetty-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | true 23 | true 24 | true 25 | 1000 26 | 27 | 28 | 29 | 10 30 | 200 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 65 | 66 | 67 | 68 | 69 | 70 | session/redis 71 | 20000 72 | 73 | 74 | 75 | 76 | 77 | 78 | 81 | 82 | session/redis 83 | 84 | 85 | 86 | 87 | 3 88 | 5 89 | true 90 | 91 | 92 | 127.0.0.1 93 | 6379 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/test/webapp2/WEB-INF/jetty-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | /webapp2 25 | 26 | 29 | 30 | 31 | 32 | 33 | session/redis 34 | 35 | 36 | 37 | 38 | 20 39 | 40 | localhost 41 | 42 | / 43 | 44 | 80 45 | 46 | 20 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/test/webapp2/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | web-2 24 | 25 | 26 | index.jsp 27 | 28 | 29 | 30 | 43200 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/test/webapp2/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright (C) 2011 Ovea 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ page import="java.util.Enumeration" %> 19 | <%@ page import="java.util.Random" %> 20 | <% 21 | int r = new Random().nextInt(100); 22 | if(request.getParameter("key") != null) 23 | request.getSession().setAttribute(String.valueOf(request.getParameter("key")), request.getParameter("val")); 24 | if(request.getParameter("invalidate") != null) 25 | request.getSession().invalidate(); 26 | %> 27 | 29 | 30 | 31 | web-2 32 | 33 | 34 | 35 |

Context path: <%=request.getContextPath()%>

36 | Refresh 37 |

38 | &val=<%="val"+r%>">Set in session: <%="key"+r%>=<%="val"+r%> 39 |

40 | Invalidate session 41 |
    42 | <% 43 | HttpSession sess = request.getSession(false); 44 | if(sess != null) { 45 | Enumeration e = sess.getAttributeNames(); 46 | while(e.hasMoreElements()) { 47 | String key = e.nextElement(); 48 | String val = String.valueOf(request.getSession().getAttribute(key)); 49 | %> 50 |
  • <%=key%> = <%=val%>
  • 51 | <% } 52 | } 53 | %> 54 |
55 | 56 | 57 | 58 | --------------------------------------------------------------------------------