1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. 4 // ------------------------------------------------------------------------ 5 // All rights reserved. This program and the accompanying materials 6 // are made available under the terms of the Eclipse Public License v1.0 7 // and Apache License v2.0 which accompanies this distribution. 8 // 9 // The Eclipse Public License is available at 10 // http://www.eclipse.org/legal/epl-v10.html 11 // 12 // The Apache License v2.0 is available at 13 // http://www.opensource.org/licenses/apache2.0.php 14 // 15 // You may elect to redistribute this code under either of these licenses. 16 // ======================================================================== 17 // 18 19 package org.eclipse.jetty.session.infinispan; 20 21 import org.infinispan.commons.marshall.jboss.AbstractJBossMarshaller; 22 import org.jboss.marshalling.ContextClassResolver; 23 24 25 /** 26 * WebAppMarshaller 27 * 28 * An implementation of the AbstractJBossMarshaller code that is just 29 * enough to provide a ContextClassResolver that will use the Thread Context Classloader 30 * in order to deserialize session attribute classes. 31 * 32 * This is necessary because the standard infinispan marshaller (GenericJBossMarshaller) uses the 33 * classloader of the loader that loaded itself. When using the infinispan module in Jetty, all of 34 * the infinispan classes will be on the container classpath. That means that the GenericJBossMarshaller 35 * returns the container classloader which is unable to load any webapp classes. This class ensures 36 * that it is always the webapp's classloader that will be used. 37 * 38 * In order to use this class, you should put a hotrod-client.properties file into the 39 * ${jetty.base}/resources directory that contains this line: 40 * 41 * infinispan.client.hotrod.marshaller=org.eclipse.jetty.session.infinispan.WebAppMarshaller 42 * 43 * You will also need to add the following lines to a context xml file for your webapp to 44 * permit the webapp's classloader to see the org.eclipse.jetty.session.infinispan classes for 45 * the deserialization to work correctly: 46 * 47 * <Call name="prependServerClass"> 48 * <Arg>-org.eclipse.jetty.session.infinispan.</Arg> 49 * </Call> 50 * 51 */ 52 public class WebAppMarshaller extends AbstractJBossMarshaller 53 { 54 55 /** 56 * WebAppContextClassResolver 57 * 58 * Provides the Thread Context Classloader to use for deserializing. 59 * 60 */ 61 public static class WebAppContextClassResolver extends ContextClassResolver 62 { 63 public WebAppContextClassResolver () 64 { 65 super(); 66 } 67 68 @Override 69 protected ClassLoader getClassLoader() 70 { 71 return Thread.currentThread().getContextClassLoader(); 72 } 73 } 74 75 76 77 public WebAppMarshaller () 78 { 79 super(); 80 baseCfg.setClassResolver(new WebAppContextClassResolver()); 81 } 82 83 84 }