StatefulKnowledgeSessionImpl ksession = new StatefulKnowledgeSessionImpl( (ReteooStatefulSession ) session );
Marshaller marshaller = MarshallerFactory.newMarshaller( ksession.getKnowledgeBase() );
marshaller.marshall( baos, ksession );
baos.close();
GlobalResolver resolver = session.getGlobalResolver();
byte[] serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
session.dispose();
// now deserialize the rulebase, deserialize the session and test it
ruleBase = (RuleBase) DroolsStreamUtils.streamIn( serializedRulebase );