Java源码示例:org.kie.server.client.KieServicesFactory

示例1
private void runRemoteActiveMQ(PrintWriter out) throws Exception {
    String baseurl = appcfg.getBaseUrl("tcp", "localhost", "61616");
    String username = appcfg.getUsername();
    String password = appcfg.getPassword();
    String qusername = appcfg.getQUsername();
    String qpassword = appcfg.getQPassword();
    out.println("runRemoteActiveMQ, using properties: url=" + baseurl);
    out.println("runRemoteActiveMQ, using properties: username=" + username);
    out.println("runRemoteActiveMQ, using properties: password=" + password);
    Properties props = new Properties();
    props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    props.setProperty(Context.PROVIDER_URL, baseurl);
    props.setProperty(Context.SECURITY_PRINCIPAL, username);
    props.setProperty(Context.SECURITY_CREDENTIALS, password);
    InitialContext context = new InitialContext(props);
    ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("ConnectionFactory");
    Queue requestQueue = (Queue) context.lookup("dynamicQueues/queue/KIE.SERVER.REQUEST");
    Queue responseQueue = (Queue) context.lookup("dynamicQueues/queue/KIE.SERVER.RESPONSE");
    KieServicesConfiguration kiecfg = KieServicesFactory.newJMSConfiguration(connectionFactory, requestQueue, responseQueue, qusername, qpassword);
    runRemote(out, kiecfg);
}
 
示例2
private void runRemote(PrintWriter out, KieServicesConfiguration kiecfg) throws Exception {
    appcfg.setKieSession(null);
    MarshallingFormat marshallingFormat = appcfg.getMarshallingFormat();
    out.println(String.format("Using %s MarshallingFormat.%s", marshallingFormat.getType(), marshallingFormat.name()));
    kiecfg.setMarshallingFormat(marshallingFormat);
    if (MarshallingFormat.JAXB.equals(marshallingFormat)) {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(Book.class);
        classes.add(Loan.class);
        classes.add(LoanRequest.class);
        classes.add(LoanResponse.class);
        classes.add(ReturnRequest.class);
        classes.add(ReturnResponse.class);
        classes.add(Suggestion.class);
        classes.add(SuggestionRequest.class);
        classes.add(SuggestionResponse.class);
        kiecfg.addExtraClasses(classes);
    }
    KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kiecfg);
    RuleServicesClient ruleServicesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
    ProcessServicesClient processServicesClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
    appcfg.setRuleServicesClient(ruleServicesClient);
    appcfg.setProcessServicesClient(processServicesClient);
    runApp(out);
}
 
示例3
private void runRemoteRest(PrintWriter out) throws Exception {
    String baseurl = appcfg.getBaseUrl("http", "localhost", "8080");
    String resturl = baseurl + "/services/rest/server";
    logger.debug("---------> resturl: " + resturl);
    String username = appcfg.getUsername();
    String password = appcfg.getPassword();
    KieServicesConfiguration kiecfg = KieServicesFactory.newRestConfiguration(resturl, username, password);
    if (resturl.toLowerCase().startsWith("https")) {
        kiecfg.setUseSsl(true);
        forgiveUnknownCert();
    }
    runRemote(out, kiecfg);
}
 
示例4
private void runRemoteHornetQ(PrintWriter out) throws Exception {
    String baseurl = appcfg.getBaseUrl("remote", "localhost", "4447");
    String username = appcfg.getUsername();
    String password = appcfg.getPassword();
    String qusername = appcfg.getQUsername();
    String qpassword = appcfg.getQPassword();
    Properties props = new Properties();
    props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    props.setProperty(Context.PROVIDER_URL, baseurl);
    props.setProperty(Context.SECURITY_PRINCIPAL, username);
    props.setProperty(Context.SECURITY_CREDENTIALS, password);
    InitialContext context = new InitialContext(props);
    KieServicesConfiguration kiecfg = KieServicesFactory.newJMSConfiguration(context, qusername, qpassword);
    runRemote(out, kiecfg);
}
 
示例5
public Measure processRules(@Body Measure measure) {
	
	KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(
			kieHost, kieUser,
			kiePassword);
	
	Set<Class<?>> jaxBClasses = new HashSet<Class<?>>();
	jaxBClasses.add(Measure.class);
	
	config.addJaxbClasses(jaxBClasses);
	config.setMarshallingFormat(MarshallingFormat.JAXB);
	RuleServicesClient client = KieServicesFactory.newKieServicesClient(config)
			.getServicesClient(RuleServicesClient.class);

       List<Command<?>> cmds = new ArrayList<Command<?>>();
	KieCommands commands = KieServices.Factory.get().getCommands();
	cmds.add(commands.newInsert(measure));
	
    GetObjectsCommand getObjectsCommand = new GetObjectsCommand();
    getObjectsCommand.setOutIdentifier("objects");

	
	cmds.add(commands.newFireAllRules());
	cmds.add(getObjectsCommand);
	BatchExecutionCommand myCommands = CommandFactory.newBatchExecution(cmds,
			"DecisionTableKS");
	ServiceResponse<ExecutionResults> response = client.executeCommandsWithResults("iot-ocp-businessrules-service", myCommands);
			
	List responseList = (List) response.getResult().getValue("objects");
	
	Measure responseMeasure = (Measure) responseList.get(0);
	
	return responseMeasure;

}
 
示例6
@Test
    public void run() {
        KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(SERVER_URL, USERNAME, PASSWORD);

        Set<Class<?>> jaxbClasses = new HashSet<Class<?>>();
        jaxbClasses.add(Application.class);

        config.addJaxbClasses(jaxbClasses);
//        config.setMarshallingFormat(MarshallingFormat.JSON);
        KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
        UserTaskServicesClient taskServicesClient = client.getServicesClient(UserTaskServicesClient.class);

        List<TaskSummary> tasks = taskServicesClient.findTasksAssignedAsPotentialOwner(USERNAME, 0, 10);

        for (TaskSummary taskSummary : tasks) {
            logger.info("task: " + String.valueOf(taskSummary));
        }

//        taskServicesClient.claimTask(CONTAINER_ID, tasks.get(0).getId(), USERNAME);
//        taskServicesClient.activateTask(CONTAINER_ID, tasks.get(0).getId(), USERNAME);
//        taskServicesClient.startTask(CONTAINER_ID, tasks.get(0).getId(), USERNAME);
        //taskServicesClient.completeTask(CONTAINER_ID, tasks.get(0).getId(), USERNAME, null);
        //taskServicesClient.completeAutoProgress(containerId, taskId, userId, params);
//        void completeTask(String containerId, Long taskId, String userId, Map<String, Object> params);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("taskOutputApplication", generateDummyApp());

        try {
            ObjectMapper mapper = new ObjectMapper();
            String val = mapper.writeValueAsString(params);
            logger.info("json \n\n" + val);
        } catch (Exception e) {
            e.printStackTrace();
        }

        taskServicesClient.completeAutoProgress(CONTAINER_ID, tasks.get(0).getId(), USERNAME, params);
    }