Search in sources :

Example 6 with KieMarshallers

use of org.kie.api.marshalling.KieMarshallers in project drools by kiegroup.

the class MarshallingTest method marshallAndUnmarshall.

public static KieSession marshallAndUnmarshall(KieBase kbase1, KieBase kbase2, KieSession ksession, KieSessionConfiguration sessionConfig) {
    // Serialize and Deserialize
    try {
        KieMarshallers kieMarshallers = KieServices.Factory.get().getMarshallers();
        Marshaller marshaller = kieMarshallers.newMarshaller(kbase1);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        marshaller.marshall(baos, ksession);
        marshaller = kieMarshallers.newMarshaller(kbase2);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        baos.close();
        ksession = marshaller.unmarshall(bais, sessionConfig, null);
        bais.close();
    } catch (Exception e) {
        e.printStackTrace();
        fail("unexpected exception :" + e.getMessage());
    }
    return ksession;
}
Also used : Marshaller(org.kie.api.marshalling.Marshaller) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) KieMarshallers(org.kie.api.marshalling.KieMarshallers)

Aggregations

KieMarshallers (org.kie.api.marshalling.KieMarshallers)6 Marshaller (org.kie.api.marshalling.Marshaller)6 IOException (java.io.IOException)5 File (java.io.File)4 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.Test)1 KieServices (org.kie.api.KieServices)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1 KieModuleModel (org.kie.api.builder.model.KieModuleModel)1 KieSessionModel (org.kie.api.builder.model.KieSessionModel)1 KieContainer (org.kie.api.runtime.KieContainer)1 KieSession (org.kie.api.runtime.KieSession)1 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)1