@Override
  protected void setUp() throws Exception {
    super.setUp();
    env = EnvironmentFactory.newEnvironment();
    Environment domainEnv = EnvironmentFactory.newEnvironment();
    domainEmf = Persistence.createEntityManagerFactory("org.jbpm.persistence.example");

    domainEnv.set(EnvironmentName.ENTITY_MANAGER_FACTORY, domainEmf);
    env.set(
        EnvironmentName.OBJECT_MARSHALLING_STRATEGIES,
        new ObjectMarshallingStrategy[] {
          new JPAPlaceholderResolverStrategy(domainEnv),
          new SerializablePlaceholderResolverStrategy(
              ClassObjectMarshallingStrategyAcceptor.DEFAULT)
        });
    ksession.setEnvironment(env);

    server = new MinaTaskServer(taskService);
    System.out.println("Waiting for the MinaTask Server to come up");
    try {
      startTaskServerThread(server, false);
    } catch (Exception e) {
      startTaskServerThread(server, true);
    }

    AsyncMinaHTWorkItemHandler asyncWSHumanTaskHandler =
        new AsyncMinaHTWorkItemHandler("my-mina-connector", client, ksession, null);
    setClient(asyncWSHumanTaskHandler.getClient());
    setHandler(asyncWSHumanTaskHandler);
  }
  private Environment getEnvironment() {
    Environment environment = KnowledgeBaseFactory.newEnvironment();
    environment.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
    environment.set(EnvironmentName.TRANSACTION_MANAGER, txm);
    environment.set(EnvironmentName.GLOBALS, new MapGlobalResolver());

    return environment;
  }
  private Environment initializeEnvironment() {
    Environment env = EnvironmentFactory.newEnvironment();
    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
    env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
    env.set(
        EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());

    return env;
  }
 public static Environment newEnvironment() {
   Environment env = new EnvironmentImpl();
   env.set(
       EnvironmentName.OBJECT_MARSHALLING_STRATEGIES,
       new ObjectMarshallingStrategy[] {
         new SerializablePlaceholderResolverStrategy(
             ClassObjectMarshallingStrategyAcceptor.DEFAULT)
       });
   return env;
   //        Environment environment = EnvironmentFactory.environment.get();
   //        if (environment == null) {
   //            environment = new EnvironmentImpl();
   //            EnvironmentFactory.environment.set(environment);
   //        }
   //        return environment;
 }
  public static Object unmarshall(byte[] content, Environment env, ClassLoader classloader) {
    MarshallerReaderContext context = null;
    try {
      ByteArrayInputStream stream = new ByteArrayInputStream(content);
      MarshallingConfigurationImpl marshallingConfigurationImpl = null;
      if (env != null) {
        marshallingConfigurationImpl =
            new MarshallingConfigurationImpl(
                (ObjectMarshallingStrategy[])
                    env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES),
                false,
                false);
      } else {
        marshallingConfigurationImpl =
            new MarshallingConfigurationImpl(
                new ObjectMarshallingStrategy[] {
                  new SerializablePlaceholderResolverStrategy(
                      ClassObjectMarshallingStrategyAcceptor.DEFAULT)
                },
                false,
                false);
      }
      ObjectMarshallingStrategyStore objectMarshallingStrategyStore =
          marshallingConfigurationImpl.getObjectMarshallingStrategyStore();
      context =
          new MarshallerReaderContext(
              stream, null, null, objectMarshallingStrategyStore, null, env);
      if (classloader != null) {
        context.classLoader = classloader;
      } else {
        context.classLoader = ContentMarshallerHelper.class.getClassLoader();
      }
      ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null);
      Header _header = PersisterHelper.readFromStreamWithHeader(context, registry);
      Variable parseFrom = JBPMMessages.Variable.parseFrom(_header.getPayload(), registry);
      Object value = ProtobufProcessMarshaller.unmarshallVariableValue(context, parseFrom);

      if (value instanceof Map) {
        Map result = new HashMap();
        Map<String, Variable> variablesMap = (Map<String, Variable>) value;
        for (String key : variablesMap.keySet()) {
          result.put(
              key,
              ProtobufProcessMarshaller.unmarshallVariableValue(context, variablesMap.get(key)));
        }
        return result;
      }
      return value;
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return null;
  }
  public static ContentData marshal(Object o, Environment env) {
    MarshallerWriteContext context = null;
    ContentData content = null;
    try {
      MarshallingConfigurationImpl marshallingConfigurationImpl = null;
      if (env != null) {
        marshallingConfigurationImpl =
            new MarshallingConfigurationImpl(
                (ObjectMarshallingStrategy[])
                    env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES),
                false,
                false);
      } else {
        marshallingConfigurationImpl =
            new MarshallingConfigurationImpl(
                new ObjectMarshallingStrategy[] {
                  new SerializablePlaceholderResolverStrategy(
                      ClassObjectMarshallingStrategyAcceptor.DEFAULT)
                },
                false,
                false);
      }
      ObjectMarshallingStrategyStore objectMarshallingStrategyStore =
          marshallingConfigurationImpl.getObjectMarshallingStrategyStore();
      ByteArrayOutputStream stream = new ByteArrayOutputStream();

      context =
          new MarshallerWriteContext(stream, null, null, null, objectMarshallingStrategyStore, env);
      Variable marshallVariable = null;
      if (o instanceof Map) {
        marshallVariable =
            ProtobufProcessMarshaller.marshallVariablesMap(context, (Map<String, Object>) o);
      } else {
        marshallVariable = ProtobufProcessMarshaller.marshallVariable(context, "results", o);
      }
      PersisterHelper.writeToStreamWithHeader(context, marshallVariable);

      context.close();

      byte[] toByteArray = stream.toByteArray();

      content = new ContentData();
      content.setContent(toByteArray);
      content.setType(o.getClass().getCanonicalName());
      content.setAccessType(AccessType.Inline);

    } catch (IOException ex) {
      ex.printStackTrace();
    }
    return content;
  }