Пример #1
0
  public static TaskClient newAsyncInstance(Properties properties, String connectorId) {
    TaskClient client = null;
    String defaultPort = null;
    String strategy =
        properties.getProperty("jbpm.console.task.service.strategy", DEFAULT_TASK_SERVICE_STRATEGY);
    if ("Mina".equalsIgnoreCase(strategy)) {
      if (client == null) {
        client =
            new TaskClient(
                new MinaTaskClientConnector(
                    connectorId,
                    new MinaTaskClientHandler(
                        SystemEventListenerFactory.getSystemEventListener())));
        defaultPort = "9123";
      }
    } else {
      throw new IllegalArgumentException("Unknown TaskClient type was specified: " + strategy);
    }

    String host = properties.getProperty("jbpm.console.task.service.host", DEFAULT_IP_ADDRESS);
    String port = properties.getProperty("jbpm.console.task.service.port", defaultPort);
    boolean connected = client.connect(host, Integer.parseInt(port));
    if (!connected) {
      throw new IllegalArgumentException(
          "Could not connect task client " + strategy + "(" + host + ":" + port + ")");
    }

    return client;
  }
 @Override
 public void connect() {
   try {
     final Field field = WSHumanTaskHandler.class.getDeclaredField("client");
     TaskClient client = (TaskClient) field.get(this);
     if (client == null) {
       client =
           new TaskClient(
               new JMSTaskClientConnector(
                   "org.jbpm.process.workitem.wsht.WSThroughJMSHumanTaskHandler",
                   new JMSTaskClientHandler(SystemEventListenerFactory.getSystemEventListener()),
                   WSHumanTaskJMSProperties.getInstance().getProperties(),
                   new InitialContext(WSHumanTaskJMSProperties.getInstance().getProperties())));
       field.set(this, client);
       boolean connected = client.connect();
       if (!connected) {
         throw new IllegalArgumentException("Could not connect to the task client");
       }
     }
     super.connect();
   } catch (NoSuchFieldException e) {
     throw new RuntimeException("Problem configuring the human task connector", e);
   } catch (IllegalAccessException e) {
     throw new RuntimeException("Problem accessing the human task connector", e);
   } catch (NamingException e) {
     throw new RuntimeException("Problem accesing the JNDI directory", e);
   }
 }
  public static final void main(String[] args) throws Exception {
    // load up the knowledge base
    KnowledgeBase kbase = readKnowledgeBase();
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

    // setup task client to use running BRMS server task client.
    TaskClient client =
        new TaskClient(
            new HornetQTaskClientConnector(
                "taskClient" + UUID.randomUUID(),
                new HornetQTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
    client.connect("127.0.0.1", 5153);

    // setup task client to use running BRMS server task client.
    CommandBasedHornetQWSHumanTaskHandler handler =
        new CommandBasedHornetQWSHumanTaskHandler(ksession);
    handler.setClient(client);

    // register work items.
    ksession.getWorkItemManager().registerWorkItemHandler("Log", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);

    // setup our input request for processing.
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "erics");
    params.put("reason", "Amazing demos for JBoss World");

    // start a new process instance
    // start a new process instance
    System.out.println("Starting Rewards process testing...");
    ksession.startProcess("org.jbpm.approval.rewards", params);
    System.out.println("Rewards process testing started and at first Human Task...");
  }
Пример #4
0
  public static final void main(String[] args) {
    try {
      setupTaskServer();
      // load up the knowledge base
      KnowledgeBase kbase = readKnowledgeBase();
      StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
      KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
      ksession
          .getWorkItemManager()
          .registerWorkItemHandler("Human Task", new CommandBasedWSHumanTaskHandler(ksession));
      // start a new process instance
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("userId", "krisv");
      params.put("s", "Need a new laptop computer");
      ksession.startProcess("UserTask", params);

      SystemEventListenerFactory.setSystemEventListener(new SystemEventListener());
      TaskClient taskClient =
          new TaskClient(
              new MinaTaskClientConnector(
                  "MinaConnector",
                  new MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
      taskClient.connect("127.0.0.1", 9123);
      Thread.sleep(1000);

      // sleep to allow notification to be sent for deadline start
      Thread.sleep(6000);
      //            Assert.assertEquals(4, wiser.getMessages().size());
      //            Assert.assertEquals("*****@*****.**",
      // wiser.getMessages().get(0).getEnvelopeReceiver());
      //            Assert.assertEquals("*****@*****.**",
      // wiser.getMessages().get(1).getEnvelopeReceiver());
      //            Assert.assertEquals("Task is ready for mike",
      // wiser.getMessages().get(0).getMimeMessage().getSubject());

      // wait another few seconds to trigger complete deadline
      Thread.sleep(4000);
      //            Assert.assertEquals(6, wiser.getMessages().size());
      //            Assert.assertEquals("*****@*****.**",
      // wiser.getMessages().get(2).getEnvelopeReceiver());
      //            Assert.assertEquals("*****@*****.**",
      // wiser.getMessages().get(3).getEnvelopeReceiver());
      //            Assert.assertEquals("Not completedTask is ready for mike",
      // wiser.getMessages().get(4).getMimeMessage().getSubject());

      BlockingTaskSummaryResponseHandler taskSummaryHandler =
          new BlockingTaskSummaryResponseHandler();
      taskClient.getTasksAssignedAsPotentialOwner("mike", "en-UK", taskSummaryHandler);
      TaskSummary task1 = taskSummaryHandler.getResults().get(0);

      BlockingTaskOperationResponseHandler taskOperationHandler =
          new BlockingTaskOperationResponseHandler();
      taskClient.start(task1.getId(), "mike", taskOperationHandler);
      taskOperationHandler.waitTillDone(1000);
      taskOperationHandler = new BlockingTaskOperationResponseHandler();
      Map<String, Object> results = new HashMap<String, Object>();
      results.put("comment", "Agreed, existing laptop needs replacing");
      results.put("outcome", "Accept");
      ContentData contentData = new ContentData();
      contentData.setAccessType(AccessType.Inline);
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      ObjectOutputStream out;
      try {
        out = new ObjectOutputStream(bos);
        out.writeObject(results);
        out.close();
        contentData = new ContentData();
        contentData.setContent(bos.toByteArray());
        contentData.setAccessType(AccessType.Inline);
      } catch (IOException e) {
        e.printStackTrace();
      }
      taskClient.complete(task1.getId(), "mike", contentData, taskOperationHandler);
      taskOperationHandler.waitTillDone(1000);
      Thread.sleep(1000);

      logger.close();
    } catch (Throwable t) {
      t.printStackTrace();
    }
    wiser.stop();
    System.exit(0);
  }