Search in sources :

Example 1 with ProtobufMarshallerReaderContext

use of org.drools.serialization.protobuf.ProtobufMarshallerReaderContext in project drools by kiegroup.

the class WorkItemInfo method getWorkItem.

public WorkItem getWorkItem(Environment env, InternalKnowledgeBase kBase) {
    this.env = env;
    if (workItem == null) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(workItemByteArray);
            MarshallerReaderContext context = new ProtobufMarshallerReaderContext(bais, kBase, null, null, null, env);
            try {
                workItem = ProtobufInputMarshaller.readWorkItem(context);
            } catch (Exception e) {
                // for backward compatibility to be able to restore 5.x data
                try {
                    context.close();
                    bais = new ByteArrayInputStream(workItemByteArray);
                    context = new ProtobufMarshallerReaderContext(bais, kBase, null, null, null, env);
                    workItem = InputMarshaller.readWorkItem(context);
                } catch (IOException e1) {
                    logger.error("Unable to read work item with InputMarshaller", e1);
                    // throw the original exception produced by failed protobuf op
                    throw new RuntimeException("Unable to read work item ", e);
                }
            }
            context.close();
        } catch (IOException e) {
            e.printStackTrace();
            throw new IllegalArgumentException("IOException while loading work item: " + e.getMessage());
        }
    }
    return workItem;
}
Also used : ProtobufMarshallerReaderContext(org.drools.serialization.protobuf.ProtobufMarshallerReaderContext) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtobufMarshallerReaderContext(org.drools.serialization.protobuf.ProtobufMarshallerReaderContext) MarshallerReaderContext(org.drools.core.marshalling.MarshallerReaderContext) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 MarshallerReaderContext (org.drools.core.marshalling.MarshallerReaderContext)1 ProtobufMarshallerReaderContext (org.drools.serialization.protobuf.ProtobufMarshallerReaderContext)1